Handle permissions in migdal admin.
[prawokultury.git] / migdal / admin.py
index 4043921..6bdfb59 100644 (file)
@@ -7,8 +7,8 @@ from django.contrib import admin
 from django.utils.translation import ugettext_lazy as _
 from migdal.models import Entry, Attachment
 from migdal import app_settings
-from migdal.helpers import translated_fields
-from prawokultury.model_helpers import filtered_model
+from fnpdjango.utils.models import filtered_model
+from fnpdjango.utils.models.translation import translated_fields
 
 
 class AttachmentInline(admin.TabularInline):
@@ -21,6 +21,15 @@ def filtered_entry_admin(typ):
         def queryset(self, request):
             return self.model.objects.filter(type=typ)
 
+        def has_add_permission(self, request):
+            return request.user.has_perm('migdal.add_entry')
+
+        def has_change_permission(self, request, obj=None):
+            return request.user.has_perm('migdal.change_entry')
+
+        def has_delete_permission(self, request, obj=None):
+            return request.user.has_perm('migdal.delete_entry')
+
         date_hierarchy = 'date'
         readonly_fields = ('date', 'changed_at') + \
             translated_fields(('published_at',))