Add recursive option to apply rights in the SAS

This commit is contained in:
Skia 2016-12-18 19:08:25 +01:00
parent dd2be2a31e
commit 352b8f0b4f
2 changed files with 17 additions and 1 deletions

View File

@ -612,6 +612,15 @@ class SithFile(models.Model):
if copy_rights:
self.copy_rights()
def apply_rights_recursively(self, only_folders=False):
print(self)
children = self.children.all()
if only_folders:
children = children.filter(is_folder=True)
for c in children:
c.copy_rights()
c.apply_rights_recursively(only_folders)
def copy_rights(self):
"""Copy, if possible, the rights of the parent folder"""
if self.parent is not None:

View File

@ -162,7 +162,8 @@ class AlbumView(CanViewMixin, DetailView, FormMixin):
def post(self, request, *args, **kwargs):
self.object = self.get_object()
self.object.generate_thumbnail()
if not self.object.file:
self.object.generate_thumbnail()
self.form = self.get_form()
if 'clipboard' not in request.session.keys():
request.session['clipboard'] = []
@ -232,6 +233,7 @@ class AlbumEditForm(forms.ModelForm):
fields=['name', 'file', 'parent', 'edit_groups']
parent = make_ajax_field(Album, 'parent', 'files', help_text="")
edit_groups = make_ajax_field(Album, 'edit_groups', 'groups', help_text="")
recursive = forms.BooleanField(label=_("Apply rights recursively"), required=False)
class PictureEditView(CanEditMixin, UpdateView):
model=Picture
@ -245,3 +247,8 @@ class AlbumEditView(CanEditMixin, UpdateView):
template_name='core/edit.jinja'
pk_url_kwarg = "album_id"
def form_valid(self, form):
ret = super(AlbumEditView, self).form_valid(form)
if form.cleaned_data['recursive']:
self.object.apply_rights_recursively(True)
return ret