Commits

Artur Barseghyan committed e3a3a9e Draft

Added ability to remove fields from the changelist form if permissions are not granted. Minor version update.

Comments (0)

Files changed (4)

 =====================================
 Release history
 =====================================
+0.4.2
+-------------------------------------
+2013-11-28
+Added ability to remove fields from the changelist form if permissions are not granted.
+
 0.4.1
 -------------------------------------
 2013-11-27
 # built documents.
 #
 # The short X.Y version.
-version = '0.4.1'
+version = '0.4.2'
 # The full version, including alpha/beta/rc tags.
-release = '0.4.1'
+release = '0.4.2'
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
 except:
     readme = ''
 
-version = '0.4.1'
+version = '0.4.2'
 
 setup(
     name = 'django-werewolf',

src/werewolf/admin.py

         defaults.update(kwargs)
         return modelform_factory(self.model, **defaults)
 
+    def get_changelist_formset(self, request, **kwargs):
+        """
+        Removes protected fields from the list_editiable field list.
+        """
+        if self.werewolf_protected_fields:
+            self.list_editable = list(self.list_editable)  # convert to a list so we can 'remove()'
+            for field_name, required_permission in self.werewolf_protected_fields:
+                # Remove field from the list_editable list if permissions are not granted.
+                if not request.user.has_perm('{0}.{1}'.format(self.model._meta.app_label, required_permission)):
+                    try:
+                        self.list_editable.remove(field_name)
+                    except:
+                        pass
+
+        return super(WerewolfBaseAdmin, self).get_changelist_formset(request, **kwargs)
+
     def get_fieldsets(self, request, obj=None):
         """
         Hiding fields that non-authorised users should not have access to. It's done based on the