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 @@