Piki is a minimal wiki
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

admin.py 2.3KB

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