Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Sith
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
59
Issues
59
List
Boards
Labels
Service Desk
Milestones
Merge Requests
9
Merge Requests
9
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
AE
Sith
Commits
22ab21e4
Commit
22ab21e4
authored
Nov 19, 2016
by
Skia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add picture-people relation and ask for removal thing
parent
b619619b
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
221 additions
and
18 deletions
+221
-18
core/migrations/0008_sithfile_asked_for_removal.py
core/migrations/0008_sithfile_asked_for_removal.py
+19
-0
core/models.py
core/models.py
+1
-0
core/views/__init__.py
core/views/__init__.py
+6
-0
sas/migrations/0002_auto_20161119_1241.py
sas/migrations/0002_auto_20161119_1241.py
+28
-0
sas/models.py
sas/models.py
+17
-0
sas/templates/sas/album.jinja
sas/templates/sas/album.jinja
+8
-8
sas/templates/sas/moderation.jinja
sas/templates/sas/moderation.jinja
+3
-0
sas/templates/sas/picture.jinja
sas/templates/sas/picture.jinja
+85
-4
sas/views.py
sas/views.py
+54
-6
No files found.
core/migrations/0008_sithfile_asked_for_removal.py
0 → 100644
View file @
22ab21e4
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'core'
,
'0007_auto_20161108_1703'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'sithfile'
,
name
=
'asked_for_removal'
,
field
=
models
.
BooleanField
(
default
=
False
,
verbose_name
=
'asked for removal'
),
),
]
core/models.py
View file @
22ab21e4
...
...
@@ -503,6 +503,7 @@ class SithFile(models.Model):
size
=
models
.
IntegerField
(
_
(
"size"
),
default
=
0
)
date
=
models
.
DateTimeField
(
_
(
'date'
),
auto_now
=
True
)
is_moderated
=
models
.
BooleanField
(
_
(
"is moderated"
),
default
=
False
)
asked_for_removal
=
models
.
BooleanField
(
_
(
"asked for removal"
),
default
=
False
)
class
Meta
:
verbose_name
=
_
(
"file"
)
...
...
core/views/__init__.py
View file @
22ab21e4
...
...
@@ -58,6 +58,8 @@ class CanEditPropMixin(View):
"""
def
dispatch
(
self
,
request
,
*
arg
,
**
kwargs
):
res
=
super
(
CanEditPropMixin
,
self
).
dispatch
(
request
,
*
arg
,
**
kwargs
)
if
res
.
__class__
.
status_code
==
302
:
return
res
if
hasattr
(
self
,
'object'
):
obj
=
self
.
object
elif
hasattr
(
self
,
'object_list'
):
...
...
@@ -76,6 +78,8 @@ class CanEditMixin(View):
"""
def
dispatch
(
self
,
request
,
*
arg
,
**
kwargs
):
res
=
super
(
CanEditMixin
,
self
).
dispatch
(
request
,
*
arg
,
**
kwargs
)
if
res
.
__class__
.
status_code
==
302
:
return
res
if
hasattr
(
self
,
'object'
):
obj
=
self
.
object
elif
hasattr
(
self
,
'object_list'
):
...
...
@@ -94,6 +98,8 @@ class CanViewMixin(View):
"""
def
dispatch
(
self
,
request
,
*
arg
,
**
kwargs
):
res
=
super
(
CanViewMixin
,
self
).
dispatch
(
request
,
*
arg
,
**
kwargs
)
if
res
.
__class__
.
status_code
==
302
:
return
res
if
hasattr
(
self
,
'object'
):
obj
=
self
.
object
elif
hasattr
(
self
,
'object_list'
):
...
...
sas/migrations/0002_auto_20161119_1241.py
0 → 100644
View file @
22ab21e4
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
from
django.conf
import
settings
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
migrations
.
swappable_dependency
(
settings
.
AUTH_USER_MODEL
),
(
'sas'
,
'0001_initial'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'PeoplePictureRelation'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
primary_key
=
True
,
verbose_name
=
'ID'
,
auto_created
=
True
,
serialize
=
False
)),
(
'picture'
,
models
.
ForeignKey
(
related_name
=
'people'
,
to
=
'sas.Picture'
,
verbose_name
=
'picture'
)),
(
'user'
,
models
.
ForeignKey
(
related_name
=
'pictures'
,
to
=
settings
.
AUTH_USER_MODEL
,
verbose_name
=
'user'
)),
],
),
migrations
.
AlterUniqueTogether
(
name
=
'peoplepicturerelation'
,
unique_together
=
set
([(
'user'
,
'picture'
)]),
),
]
sas/models.py
View file @
22ab21e4
from
django.db
import
models
from
django.conf
import
settings
from
django.core.urlresolvers
import
reverse
from
django.utils.translation
import
ugettext_lazy
as
_
from
core.models
import
SithFile
,
User
...
...
@@ -23,6 +24,12 @@ class Picture(SithFile):
def
get_download_url
(
self
):
return
reverse
(
'sas:download'
,
kwargs
=
{
'picture_id'
:
self
.
id
})
def
get_next
(
self
):
return
self
.
parent
.
children
.
exclude
(
is_moderated
=
False
,
asked_for_removal
=
True
).
filter
(
id__gt
=
self
.
id
).
order_by
(
'id'
).
first
()
def
get_previous
(
self
):
return
self
.
parent
.
children
.
exclude
(
is_moderated
=
False
,
asked_for_removal
=
True
).
filter
(
id__lt
=
self
.
id
).
order_by
(
'id'
).
last
()
class
Album
(
SithFile
):
class
Meta
:
proxy
=
True
...
...
@@ -42,3 +49,13 @@ class Album(SithFile):
def
get_absolute_url
(
self
):
return
reverse
(
'sas:album'
,
kwargs
=
{
'album_id'
:
self
.
id
})
class
PeoplePictureRelation
(
models
.
Model
):
"""
The PeoplePictureRelation class makes the connection between User and Picture
"""
user
=
models
.
ForeignKey
(
User
,
verbose_name
=
_
(
'user'
),
related_name
=
"pictures"
,
null
=
False
,
blank
=
False
)
picture
=
models
.
ForeignKey
(
Picture
,
verbose_name
=
_
(
'picture'
),
related_name
=
"people"
,
null
=
False
,
blank
=
False
)
class
Meta
:
unique_together
=
[
'user'
,
'picture'
]
sas/templates/sas/album.jinja
View file @
22ab21e4
...
...
@@ -6,11 +6,6 @@
{%
block
content
%}
<h3>
{{
album.get_display_name
()
}}
</h3>
<form
action=
""
method=
"post"
enctype=
"multipart/form-data"
>
{%
csrf_token
%}
{{
form.as_p
()
}}
<p><input
type=
"submit"
value=
"
{%
trans
%}
Upload
{%
endtrans
%}
"
/></p>
</form>
<div>
{%
for
a
in
album.children.
filter
(
is_folder
=
True
,
is_moderated
=
True
)
.
all
()
%}
<div
style=
"display: inline-block; border: solid 1px black;"
>
...
...
@@ -22,13 +17,18 @@
{# for a in album.children.filter(mime_type__in=['image/jpeg', 'image/png']).all() #}
{%
for
p
in
album.children.
filter
(
is_folder
=
False
,
is_moderated
=
True
)
.
all
()
%}
{%
if
p.as_picture.can_be_viewed_by
(
user
)
%}
<div
style=
"display: inline-block; border: solid 1px black;"
>
<a
href=
"
{{
url
(
"sas:picture"
,
picture_id
=
p.id
)
}}
"
>
<img
src=
"
{{
p.as_picture.get_download_url
()
}}
"
alt=
"
{{
p.get_display_name
()
}}
"
style=
"
width: 50px
"
/>
<div
style=
"display: inline-block; border: solid 1px black;
width: 9%; margin: 0.1%
"
>
<a
href=
"
{{
url
(
"sas:picture"
,
picture_id
=
p.id
)
}}
#pict
"
>
<img
src=
"
{{
p.as_picture.get_download_url
()
}}
"
alt=
"
{{
p.get_display_name
()
}}
"
style=
"
max-width: 100%
"
/>
</a>
</div>
{%
endif
%}
{%
endfor
%}
</div>
<form
action=
""
method=
"post"
enctype=
"multipart/form-data"
>
{%
csrf_token
%}
{{
form.as_p
()
}}
<p><input
type=
"submit"
value=
"
{%
trans
%}
Upload
{%
endtrans
%}
"
/></p>
</form>
{%
endblock
%}
sas/templates/sas/moderation.jinja
View file @
22ab21e4
...
...
@@ -23,6 +23,9 @@
{%
trans
%}
Owner:
{%
endtrans
%}{{
p.owner.get_display_name
()
}}
<br/>
{%
trans
%}
Date:
{%
endtrans
%}{{
p.date
|
date
(
DATE_FORMAT
)
}}
{{
p.date
|
time
(
TIME_FORMAT
)
}}
<br/>
</p>
{%
if
p.asked_for_removal
%}
<p
class=
"important"
>
{%
trans
%}
Asked for removal
{%
endtrans
%}
</p>
{%
endif
%}
<p>
<input
type=
"radio"
name=
"action_
{{
p.id
}}
"
id=
"m_
{{
p.id
}}
"
value=
"moderate"
/>
<a
href=
"
{{
url
(
'core:file_moderate'
,
file_id
=
p.id
)
}}
?next=
{{
url
(
'sas:moderation'
)
}}
"
>
{%
trans
%}
Moderate
{%
endtrans
%}
</a>
...
...
sas/templates/sas/picture.jinja
View file @
22ab21e4
{%
extends
"core/base.jinja"
%}
{%
block
head
%}
{{
super
()
}}
<style>
#prev
,
#next
{
display
:
inline-block
;
width
:
42%
;
margin
:
0.5%
;
border
:
solid
1px
grey
;
overflow
:
auto
;
background
:
#333
;
}
#prev
img
,
#next
img
{
display
:
block
;
margin
:
auto
;
max-width
:
100%
;
max-height
:
100%
;
}
</style>
{%
endblock
%}
{%
block
title
%}
{%
trans
%}
SAS
{%
endtrans
%}
{%
endblock
%}
{%
macro
print_path
(
file
)
%}
{%
if
file
%}
{{
print_path
(
file.parent
)
}}
<a
href=
"
{{
url
(
'sas:album'
,
album_id
=
file.id
)
}}
"
>
{{
file.get_display_name
()
}}
</a>
>
{%
endif
%}
{%
endmacro
%}
{%
block
content
%}
{{
print_path
(
picture.parent
)
}}
{{
picture.get_display_name
()
}}
<h3>
{{
picture.get_display_name
()
}}
</h3>
<div
style=
"
float: righ
t"
>
PREV / NEXT
<div
style=
"
display: inline-block; width: 89%; background: #333;"
id=
"pic
t"
>
<img
src=
"
{{
picture.get_download_url
()
}}
"
alt=
"
{{
picture.get_display_name
()
}}
"
style=
"width: 90%; display: block; margin: auto"
/>
</div>
<div>
<img
src=
"
{{
picture.get_download_url
()
}}
"
alt=
"
{{
picture.get_display_name
()
}}
"
style=
"width: 90%"
/>
<div
style=
"display: inline-block; width: 10%; vertical-align: top;"
>
<div>
<div
id=
"prev"
>
{%
if
picture.get_previous
()
%}
<a
href=
"
{{
url
(
"sas:picture"
,
picture_id
=
picture.get_previous
()
.
id
)
}}
#pict"
>
<img
src=
"
{{
picture.get_previous
()
.
as_picture.get_download_url
()
}}
"
alt=
"
{{
picture.get_previous
()
.
get_display_name
()
}}
"
/>
</a>
{%
endif
%}
</div>
<div
id=
"next"
>
{%
if
picture.get_next
()
%}
<a
href=
"
{{
url
(
"sas:picture"
,
picture_id
=
picture.get_next
()
.
id
)
}}
#pict"
>
<img
src=
"
{{
picture.get_next
()
.
as_picture.get_download_url
()
}}
"
alt=
"
{{
picture.get_next
()
.
get_display_name
()
}}
"
/>
</a>
{%
endif
%}
</div>
</div>
<div>
<ul>
{%
for
r
in
picture.people.all
()
%}
<li>
<a
href=
"
{{
r.user.get_absolute_url
()
}}
"
>
{{
r.user.get_display_name
()
}}
</a>
{%
if
user
==
r.user
or
user.is_in_group
(
settings.SITH_SAS_ADMIN_GROUP_ID
)
%}
<a
href=
"?remove_user=
{{
r.user.id
}}
"
>
{%
trans
%}
Delete
{%
endtrans
%}
</a>
{%
endif
%}
</li>
{%
endfor
%}
</ul>
</div>
<div>
<form
action=
""
method=
"post"
enctype=
"multipart/form-data"
>
{%
csrf_token
%}
{{
form.as_p
()
}}
<p><input
type=
"submit"
value=
"
{%
trans
%}
Go
{%
endtrans
%}
"
/></p>
</form>
</div>
<p
style=
"font-size: smaller;"
>
<a
href=
"?ask_removal"
>
{%
trans
%}
Ask for removal
{%
endtrans
%}
</a>
</p>
</div>
{%
endblock
%}
{%
block
script
%}
{{
super
()
}}
<script>
$
(
function
()
{
$
(
document
).
keydown
(
function
(
e
)
{
if
(
e
.
keyCode
==
37
)
{
console
.
log
(
"
prev
"
);
$
(
'
#prev a
'
)[
0
].
click
();
}
else
if
(
e
.
keyCode
==
39
)
{
console
.
log
(
"
next
"
);
$
(
'
#next a
'
)[
0
].
click
();
}
});
}
);
</script>
{%
endblock
%}
sas/views.py
View file @
22ab21e4
from
django.shortcuts
import
render
from
django.core.urlresolvers
import
reverse_lazy
from
django.shortcuts
import
render
,
redirect
from
django.core.urlresolvers
import
reverse_lazy
,
reverse
from
django.views.generic
import
ListView
,
DetailView
,
RedirectView
,
TemplateView
from
django.views.generic.edit
import
UpdateView
,
CreateView
,
DeleteView
,
ProcessFormView
,
FormMixin
,
FormView
from
django.utils.translation
import
ugettext
as
_
...
...
@@ -8,14 +8,14 @@ from django.conf import settings
from
django
import
forms
from
django.core.exceptions
import
PermissionDenied
from
ajax_select
.fields
import
AutoCompleteSelectField
,
AutoCompleteSelectMultipleF
ield
from
ajax_select
import
make_ajax_form
,
make_ajax_f
ield
from
core.views
import
CanViewMixin
,
CanEditMixin
,
CanEditPropMixin
,
CanCreateMixin
,
TabedViewMixin
from
core.views.forms
import
SelectUser
,
LoginForm
,
SelectDate
,
SelectDateTime
from
core.views.files
import
send_file
from
core.models
import
SithFile
,
User
from
sas.models
import
Picture
,
Album
from
sas.models
import
Picture
,
Album
,
PeoplePictureRelation
class
SASForm
(
forms
.
Form
):
album_name
=
forms
.
CharField
(
label
=
_
(
"Add a new album"
),
max_length
=
30
,
required
=
False
)
...
...
@@ -41,6 +41,13 @@ class SASForm(forms.Form):
except
Exception
as
e
:
self
.
add_error
(
None
,
_
(
"Error uploading file %(file_name)s: %(msg)s"
)
%
{
'file_name'
:
f
,
'msg'
:
repr
(
e
)})
class
RelationForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
PeoplePictureRelation
fields
=
[
'picture'
,
'user'
]
widgets
=
{
'picture'
:
forms
.
HiddenInput
}
user
=
make_ajax_field
(
PeoplePictureRelation
,
'user'
,
'users'
,
help_text
=
""
)
class
SASMainView
(
FormView
):
form_class
=
SASForm
template_name
=
"sas/main.jinja"
...
...
@@ -65,11 +72,51 @@ class SASMainView(FormView):
kwargs
[
'root_file'
]
=
SithFile
.
objects
.
filter
(
id
=
settings
.
SITH_SAS_ROOT_DIR_ID
).
first
()
return
kwargs
class
PictureView
(
DetailView
,
CanView
Mixin
):
class
PictureView
(
CanViewMixin
,
DetailView
,
Form
Mixin
):
model
=
Picture
form_class
=
RelationForm
pk_url_kwarg
=
"picture_id"
template_name
=
"sas/picture.jinja"
def
get_initial
(
self
):
return
{
'picture'
:
self
.
object
}
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
object
=
self
.
get_object
()
self
.
form
=
self
.
get_form
()
if
'remove_user'
in
request
.
GET
.
keys
():
try
:
user
=
User
.
objects
.
filter
(
id
=
int
(
request
.
GET
[
'remove_user'
])).
first
()
if
user
.
id
==
request
.
user
.
id
or
request
.
user
.
is_in_group
(
settings
.
SITH_SAS_ADMIN_GROUP_ID
):
r
=
PeoplePictureRelation
.
objects
.
filter
(
user
=
user
,
picture
=
self
.
object
).
delete
()
except
:
pass
if
'ask_removal'
in
request
.
GET
.
keys
():
self
.
object
.
is_moderated
=
False
self
.
object
.
asked_for_removal
=
True
self
.
object
.
save
()
return
redirect
(
"sas:album"
,
album_id
=
self
.
object
.
parent
.
id
)
return
super
(
PictureView
,
self
).
get
(
request
,
*
args
,
**
kwargs
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
object
=
self
.
get_object
()
self
.
form
=
self
.
get_form
()
if
request
.
user
.
is_authenticated
()
and
request
.
user
.
is_in_group
(
'ae-membres'
):
if
self
.
form
.
is_valid
():
PeoplePictureRelation
(
user
=
self
.
form
.
cleaned_data
[
'user'
],
picture
=
self
.
form
.
cleaned_data
[
'picture'
]).
save
()
return
super
(
PictureView
,
self
).
form_valid
(
self
.
form
)
else
:
self
.
form
.
add_error
(
None
,
_
(
"You do not have the permission to do that"
))
return
self
.
form_invalid
(
self
.
form
)
def
get_context_data
(
self
,
**
kwargs
):
kwargs
=
super
(
PictureView
,
self
).
get_context_data
(
**
kwargs
)
kwargs
[
'form'
]
=
self
.
form
return
kwargs
def
get_success_url
(
self
):
return
reverse
(
'sas:picture'
,
kwargs
=
{
'picture_id'
:
self
.
object
.
id
})
def
send_pict
(
request
,
picture_id
):
return
send_file
(
request
,
picture_id
,
Picture
)
...
...
@@ -98,7 +145,7 @@ class AlbumView(CanViewMixin, DetailView, FormMixin):
return
self
.
form_invalid
(
self
.
form
)
def
get_success_url
(
self
):
return
reverse
_lazy
(
'sas:album'
,
kwargs
=
{
'album_id'
:
self
.
object
.
id
})
return
reverse
(
'sas:album'
,
kwargs
=
{
'album_id'
:
self
.
object
.
id
})
def
get_context_data
(
self
,
**
kwargs
):
kwargs
=
super
(
AlbumView
,
self
).
get_context_data
(
**
kwargs
)
...
...
@@ -120,6 +167,7 @@ class ModerationView(TemplateView):
pict
.
delete
()
elif
v
==
"moderate"
:
pict
.
is_moderated
=
True
pict
.
asked_for_removal
=
False
pict
.
save
()
except
:
pass
return
super
(
ModerationView
,
self
).
get
(
request
,
*
args
,
**
kwargs
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment