|
@@ -2,18 +2,51 @@ from django.contrib import admin
|
2
|
2
|
from simple_history.admin import SimpleHistoryAdmin
|
3
|
3
|
|
4
|
4
|
from .models import PikiPage
|
|
5
|
+from .forms import GroupForm, PermForm
|
|
6
|
+
|
|
7
|
+from django.shortcuts import render
|
|
8
|
+from django.http import HttpResponseRedirect
|
|
9
|
+from django.contrib.auth.models import Group
|
5
|
10
|
|
6
|
11
|
|
7
|
12
|
class PikiPageAdmin(SimpleHistoryAdmin):
|
8
|
|
- list_display = ('rel_path', 'tags', 'deleted')
|
|
13
|
+ list_display = ('rel_path', 'tags', 'group', 'other_perms_read', 'other_perms_write')
|
9
|
14
|
history_list_display = ('rel_path', 'tags', 'deleted')
|
10
|
15
|
search_fields = ('rel_path', 'tags', )
|
11
|
16
|
list_filter = (
|
12
|
|
- ('deleted', admin.BooleanFieldListFilter),
|
|
17
|
+ ('group', admin.RelatedFieldListFilter),
|
13
|
18
|
('other_perms_read', admin.BooleanFieldListFilter),
|
14
|
19
|
('other_perms_write', admin.BooleanFieldListFilter),
|
15
|
20
|
)
|
16
|
21
|
ordering = ["rel_path"]
|
|
22
|
+ actions = ["remove_access_others", "set_group", "set_perms", ]
|
|
23
|
+
|
|
24
|
+ @admin.action(description="Remove access for others")
|
|
25
|
+ def remove_access_others(self, request, query_set):
|
|
26
|
+ query_set.update(other_perms_read=False, other_perms_write=False)
|
|
27
|
+
|
|
28
|
+ @admin.action(description="Set group for pages")
|
|
29
|
+ def set_group(self, request, queryset):
|
|
30
|
+ if 'apply' in request.POST:
|
|
31
|
+ if request.POST.get("group"):
|
|
32
|
+ group = Group.objects.get(id=request.POST.get("group"))
|
|
33
|
+ else:
|
|
34
|
+ group = None
|
|
35
|
+ queryset.update(group=group)
|
|
36
|
+ self.message_user(request, "Changed group for {} pages".format(queryset.count()))
|
|
37
|
+ return HttpResponseRedirect(request.get_full_path())
|
|
38
|
+ return render(request, 'admin/set_group.html', context={'pages': queryset, 'form': GroupForm()})
|
|
39
|
+
|
|
40
|
+ @admin.action(description="Set permissions")
|
|
41
|
+ def set_perms(self, request, queryset):
|
|
42
|
+ if 'apply' in request.POST:
|
|
43
|
+ keys = ["owner_perms_read", "owner_perms_write", "group_perms_read", "group_perms_write", "other_perms_read", "other_perms_write"]
|
|
44
|
+ perms = {key: key in request.POST for key in keys}
|
|
45
|
+ queryset.update(**perms)
|
|
46
|
+ self.message_user(request, "Changed permissions for {} pages".format(queryset.count()))
|
|
47
|
+ return HttpResponseRedirect(request.get_full_path())
|
|
48
|
+ return render(request, 'admin/set_perms.html', context={'pages': queryset, 'form': PermForm()})
|
17
|
49
|
|
18
|
50
|
|
|
51
|
+admin.site.disable_action('delete_selected')
|
19
|
52
|
admin.site.register(PikiPage, PikiPageAdmin)
|