diff --git a/core/views/files.py b/core/views/files.py index 35f50139..ab5dc33b 100644 --- a/core/views/files.py +++ b/core/views/files.py @@ -141,6 +141,28 @@ class FileView(CanViewMixin, DetailView, FormMixin): context_object_name = "file" 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): self.form = self.get_form() if 'clipboard' not in request.session.keys(): @@ -152,25 +174,7 @@ class FileView(CanViewMixin, DetailView, FormMixin): if 'clipboard' not in request.session.keys(): request.session['clipboard'] = [] if request.user.can_edit(self.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 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 + FileView.handle_clipboard(request, self.object) self.form = self.get_form() # The form handle only the file upload files = request.FILES.getlist('file_field') if request.user.is_authenticated() and request.user.can_edit(self.object) and self.form.is_valid(): diff --git a/sas/models.py b/sas/models.py index afaf25b0..c5513a89 100644 --- a/sas/models.py +++ b/sas/models.py @@ -24,7 +24,7 @@ class Picture(SithFile): return False 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): 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 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): return self.can_be_edited_by(user) or (self.is_in_sas and self.is_moderated and diff --git a/sas/templates/sas/album.jinja b/sas/templates/sas/album.jinja index 938226b9..e9054357 100644 --- a/sas/templates/sas/album.jinja +++ b/sas/templates/sas/album.jinja @@ -17,37 +17,69 @@

{{ album.get_display_name() }}

{% trans %}Edit{% endtrans %}

-
- {% for a in album.children.filter(is_folder=True).order_by('-id') %} - {% if a.as_album.can_be_viewed_by(user) %} - -
-
- {% if a.file %} - {% trans %}preview{% endtrans %} - {% elif a.children.filter(is_folder=False, is_moderated=True).exists() %} - {% trans %}preview{% endtrans %} - {% else %} - {% trans %}preview{% endtrans %} +{% if user.can_edit(album) %} +
+ {% csrf_token %} +

+ | + | + | + +

+ {% if clipboard %} +

{% trans %}Clipboard: {% endtrans %} +

    + {% for f in clipboard %} +
  • {{ f.get_full_path() }}
  • + {% endfor %} +
+

+ {% endif %} +{% endif %} +
+ {% for a in album.children.filter(is_folder=True).order_by('-id') %} + - {{ a.name }} + {% endfor %}
- - {% endif %} - {% endfor %} -
-
- {% for p in album.children.filter(is_folder=False).order_by('id') %} - {% if p.as_picture.can_be_viewed_by(user) %} -
- - {{ p.get_display_name() }} - +
+ {% for p in album.children.filter(is_folder=False).order_by('id') %} +
+ {% if user.can_edit(album) %} + + {% endif %} + {% if p.as_picture.can_be_viewed_by(user) %} +
+ + {{ p.get_display_name() }} + +
+ {% endif %} +
+ {% endfor %}
- {% endif %} - {% endfor %} -
+{% if user.can_edit(album) %} + +{% endif %}
{% csrf_token %} {{ form.as_p() }} diff --git a/sas/views.py b/sas/views.py index c17dbede..d12dbe95 100644 --- a/sas/views.py +++ b/sas/views.py @@ -17,7 +17,7 @@ from PIL import Image 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.views.files import send_file, FileView from core.models import SithFile, User, Notification, RealGroup from sas.models import Picture, Album, PeoplePictureRelation @@ -154,14 +154,20 @@ class AlbumView(CanViewMixin, DetailView, FormMixin): def get(self, request, *args, **kwargs): self.form = self.get_form() + if 'clipboard' not in request.session.keys(): + request.session['clipboard'] = [] return super(AlbumView, self).get(request, *args, **kwargs) def post(self, request, *args, **kwargs): self.object = self.get_object() 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() 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(): self.form.process(parent=parent, owner=request.user, files=files, 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): kwargs = super(AlbumView, self).get_context_data(**kwargs) kwargs['form'] = self.form + kwargs['clipboard'] = SithFile.objects.filter(id__in=self.request.session['clipboard']) return kwargs # Admin views