mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +00:00
Add clipboard to SAS
This commit is contained in:
parent
f594a99751
commit
bf9aa29a54
@ -141,6 +141,28 @@ class FileView(CanViewMixin, DetailView, FormMixin):
|
|||||||
context_object_name = "file"
|
context_object_name = "file"
|
||||||
form_class = AddFilesForm
|
form_class = AddFilesForm
|
||||||
|
|
||||||
|
def handle_clipboard(request, object):
|
||||||
|
if 'delete' in request.POST.keys():
|
||||||
|
for f_id in request.POST.getlist('file_list'):
|
||||||
|
sf = SithFile.objects.filter(id=f_id).first()
|
||||||
|
if sf:
|
||||||
|
sf.delete()
|
||||||
|
if 'clear' in request.POST.keys():
|
||||||
|
request.session['clipboard'] = []
|
||||||
|
if 'cut' in request.POST.keys():
|
||||||
|
for f_id in request.POST.getlist('file_list'):
|
||||||
|
f_id = int(f_id)
|
||||||
|
if f_id in [c.id for c in object.children.all()] and f_id not in request.session['clipboard']:
|
||||||
|
print(f_id)
|
||||||
|
request.session['clipboard'].append(f_id)
|
||||||
|
if 'paste' in request.POST.keys():
|
||||||
|
for f_id in request.session['clipboard']:
|
||||||
|
sf = SithFile.objects.filter(id=f_id).first()
|
||||||
|
if sf:
|
||||||
|
sf.move_to(object)
|
||||||
|
request.session['clipboard'] = []
|
||||||
|
request.session.modified = True
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
self.form = self.get_form()
|
self.form = self.get_form()
|
||||||
if 'clipboard' not in request.session.keys():
|
if 'clipboard' not in request.session.keys():
|
||||||
@ -152,25 +174,7 @@ class FileView(CanViewMixin, DetailView, FormMixin):
|
|||||||
if 'clipboard' not in request.session.keys():
|
if 'clipboard' not in request.session.keys():
|
||||||
request.session['clipboard'] = []
|
request.session['clipboard'] = []
|
||||||
if request.user.can_edit(self.object):
|
if request.user.can_edit(self.object):
|
||||||
if 'delete' in request.POST.keys():
|
FileView.handle_clipboard(request, self.object)
|
||||||
for f_id in request.POST.getlist('file_list'):
|
|
||||||
sf = SithFile.objects.filter(id=f_id).first()
|
|
||||||
if sf:
|
|
||||||
sf.delete()
|
|
||||||
if 'clear' in request.POST.keys():
|
|
||||||
request.session['clipboard'] = []
|
|
||||||
if 'cut' in request.POST.keys():
|
|
||||||
for f_id in request.POST.getlist('file_list'):
|
|
||||||
f_id = int(f_id)
|
|
||||||
if f_id in [c.id for c in self.object.children.all()] and f_id not in request.session['clipboard']:
|
|
||||||
request.session['clipboard'].append(f_id)
|
|
||||||
if 'paste' in request.POST.keys():
|
|
||||||
for f_id in request.session['clipboard']:
|
|
||||||
sf = SithFile.objects.filter(id=f_id).first()
|
|
||||||
if sf:
|
|
||||||
sf.move_to(self.object)
|
|
||||||
request.session['clipboard'] = []
|
|
||||||
request.session.modified = True
|
|
||||||
self.form = self.get_form() # The form handle only the file upload
|
self.form = self.get_form() # The form handle only the file upload
|
||||||
files = request.FILES.getlist('file_field')
|
files = request.FILES.getlist('file_field')
|
||||||
if request.user.is_authenticated() and request.user.can_edit(self.object) and self.form.is_valid():
|
if request.user.is_authenticated() and request.user.can_edit(self.object) and self.form.is_valid():
|
||||||
|
@ -24,7 +24,7 @@ class Picture(SithFile):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def can_be_edited_by(self, user):
|
def can_be_edited_by(self, user):
|
||||||
return user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID) or super(Picture, self).can_be_edited_by(user)
|
return user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID)
|
||||||
|
|
||||||
def can_be_viewed_by(self, user):
|
def can_be_viewed_by(self, user):
|
||||||
return self.can_be_edited_by(user) or (self.is_in_sas and self.is_moderated and
|
return self.can_be_edited_by(user) or (self.is_in_sas and self.is_moderated and
|
||||||
@ -87,7 +87,7 @@ class Album(SithFile):
|
|||||||
proxy = True
|
proxy = True
|
||||||
|
|
||||||
def can_be_edited_by(self, user):
|
def can_be_edited_by(self, user):
|
||||||
return user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID) or super(Album, self).can_be_edited_by(user)
|
return user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID)
|
||||||
|
|
||||||
def can_be_viewed_by(self, user):
|
def can_be_viewed_by(self, user):
|
||||||
return self.can_be_edited_by(user) or (self.is_in_sas and self.is_moderated and
|
return self.can_be_edited_by(user) or (self.is_in_sas and self.is_moderated and
|
||||||
|
@ -17,8 +17,31 @@
|
|||||||
<h3>{{ album.get_display_name() }}</h3>
|
<h3>{{ album.get_display_name() }}</h3>
|
||||||
<a href="{{ url('sas:album_edit', album_id=album.id) }}">{% trans %}Edit{% endtrans %}</a><br>
|
<a href="{{ url('sas:album_edit', album_id=album.id) }}">{% trans %}Edit{% endtrans %}</a><br>
|
||||||
<hr>
|
<hr>
|
||||||
<div>
|
{% if user.can_edit(album) %}
|
||||||
|
<form action="" method="post" enctype="multipart/form-data" style="width: 100%;">
|
||||||
|
{% csrf_token %}
|
||||||
|
<p>
|
||||||
|
<input name="delete" type="submit" value="{% trans %}Delete{% endtrans %}"> |
|
||||||
|
<input name="clear" type="submit" value="{% trans %}Clear clipboard{% endtrans %}"> |
|
||||||
|
<input name="cut" type="submit" value="{% trans %}Cut{% endtrans %}"> |
|
||||||
|
<input name="paste" type="submit" value="{% trans %}Paste{% endtrans %}">
|
||||||
|
</p>
|
||||||
|
{% if clipboard %}
|
||||||
|
<p>{% trans %}Clipboard: {% endtrans %}
|
||||||
|
<ul>
|
||||||
|
{% for f in clipboard %}
|
||||||
|
<li>{{ f.get_full_path() }}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
<div>
|
||||||
{% for a in album.children.filter(is_folder=True).order_by('-id') %}
|
{% for a in album.children.filter(is_folder=True).order_by('-id') %}
|
||||||
|
<div style="display: inline-block;">
|
||||||
|
{% if user.can_edit(album) %}
|
||||||
|
<input type="checkbox" name="file_list" value="{{ a.id }}">
|
||||||
|
{% endif %}
|
||||||
{% if a.as_album.can_be_viewed_by(user) %}
|
{% if a.as_album.can_be_viewed_by(user) %}
|
||||||
<a href="{{ url("sas:album", album_id=a.id) }}" style="display: inline-block">
|
<a href="{{ url("sas:album", album_id=a.id) }}" style="display: inline-block">
|
||||||
<div class="album{% if not a.is_moderated %} not_moderated{% endif %}">
|
<div class="album{% if not a.is_moderated %} not_moderated{% endif %}">
|
||||||
@ -35,10 +58,15 @@
|
|||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
{% for p in album.children.filter(is_folder=False).order_by('id') %}
|
{% for p in album.children.filter(is_folder=False).order_by('id') %}
|
||||||
|
<div style="display: inline-block;">
|
||||||
|
{% if user.can_edit(album) %}
|
||||||
|
<input type="checkbox" name="file_list" value="{{ p.id }}">
|
||||||
|
{% endif %}
|
||||||
{% if p.as_picture.can_be_viewed_by(user) %}
|
{% if p.as_picture.can_be_viewed_by(user) %}
|
||||||
<div class="picture{% if not p.is_moderated %} not_moderated{% endif %}">
|
<div class="picture{% if not p.is_moderated %} not_moderated{% endif %}">
|
||||||
<a href="{{ url("sas:picture", picture_id=p.id) }}#pict">
|
<a href="{{ url("sas:picture", picture_id=p.id) }}#pict">
|
||||||
@ -46,8 +74,12 @@
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
{% if user.can_edit(album) %}
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
<form action="" method="post" enctype="multipart/form-data">
|
<form action="" method="post" enctype="multipart/form-data">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form.as_p() }}
|
{{ form.as_p() }}
|
||||||
|
11
sas/views.py
11
sas/views.py
@ -17,7 +17,7 @@ from PIL import Image
|
|||||||
|
|
||||||
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin, TabedViewMixin
|
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin, TabedViewMixin
|
||||||
from core.views.forms import SelectUser, LoginForm, SelectDate, SelectDateTime
|
from core.views.forms import SelectUser, LoginForm, SelectDate, SelectDateTime
|
||||||
from core.views.files import send_file
|
from core.views.files import send_file, FileView
|
||||||
from core.models import SithFile, User, Notification, RealGroup
|
from core.models import SithFile, User, Notification, RealGroup
|
||||||
|
|
||||||
from sas.models import Picture, Album, PeoplePictureRelation
|
from sas.models import Picture, Album, PeoplePictureRelation
|
||||||
@ -154,14 +154,20 @@ class AlbumView(CanViewMixin, DetailView, FormMixin):
|
|||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
self.form = self.get_form()
|
self.form = self.get_form()
|
||||||
|
if 'clipboard' not in request.session.keys():
|
||||||
|
request.session['clipboard'] = []
|
||||||
return super(AlbumView, self).get(request, *args, **kwargs)
|
return super(AlbumView, self).get(request, *args, **kwargs)
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
self.object = self.get_object()
|
self.object = self.get_object()
|
||||||
self.form = self.get_form()
|
self.form = self.get_form()
|
||||||
|
if 'clipboard' not in request.session.keys():
|
||||||
|
request.session['clipboard'] = []
|
||||||
|
if request.user.can_edit(self.object): # Handle the copy-paste functions
|
||||||
|
FileView.handle_clipboard(request, self.object)
|
||||||
parent = SithFile.objects.filter(id=self.object.id).first()
|
parent = SithFile.objects.filter(id=self.object.id).first()
|
||||||
files = request.FILES.getlist('images')
|
files = request.FILES.getlist('images')
|
||||||
if request.user.is_authenticated() and request.user.is_in_group('ae-membres'):
|
if request.user.is_authenticated() and request.user.is_subscribed():
|
||||||
if self.form.is_valid():
|
if self.form.is_valid():
|
||||||
self.form.process(parent=parent, owner=request.user, files=files,
|
self.form.process(parent=parent, owner=request.user, files=files,
|
||||||
automodere=request.user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID))
|
automodere=request.user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID))
|
||||||
@ -177,6 +183,7 @@ class AlbumView(CanViewMixin, DetailView, FormMixin):
|
|||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
kwargs = super(AlbumView, self).get_context_data(**kwargs)
|
kwargs = super(AlbumView, self).get_context_data(**kwargs)
|
||||||
kwargs['form'] = self.form
|
kwargs['form'] = self.form
|
||||||
|
kwargs['clipboard'] = SithFile.objects.filter(id__in=self.request.session['clipboard'])
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
# Admin views
|
# Admin views
|
||||||
|
Loading…
Reference in New Issue
Block a user