@@ -344,6 +344,48 @@ def get_modified_date(self, obj: models.Model) -> typing.Union[str, None]:
344344 """
345345 return getattr (obj , "content_modified" , None )
346346
347+ def can_change_content (self , request : HttpRequest , content_obj : models .Model ) -> bool :
348+ """Returns True if user can change content_obj"""
349+ if content_obj is None :
350+ # Creating an object is never restricted by versioning
351+ return True
352+ version = Version .objects .get_for_content (content_obj )
353+ return version .check_modify .as_bool (request .user )
354+
355+
356+
357+ class DefaultGrouperVersioningAdminMixin (StateIndicatorMixin , ExtendedGrouperVersionAdminMixin ):
358+ """Default mixin for grouper model admin classes: Includes state indicator, author and modified date.
359+ Usage::
360+ class MyContentModelAdmin(DefaultGrouperAdminMixin, cms.admin.utils.GrouperModelAdmin):
361+ list_display = [
362+ ...,
363+ "get_author", # Adds the author column
364+ "get_modified_date", # Adds the modified column
365+ "state_indicator", # Adds the state indicator column
366+ ...]
367+
368+ If "state_indicator" is not in `list_display`, it will be added automatically before the
369+ "admin_list_actions" field, or - together with the actions - at the end of the list_display
370+ if no actions are present.
371+ """
372+ def get_list_display (self , request ):
373+ list_display = getattr (self , "list_display" , ())
374+ if "state_indicator" not in list_display :
375+ if "admin_list_actions" in list_display :
376+ # If the admin_list_actions is present, we need to add the state_indicator
377+ # to the end of the list_display, so it doesn't interfere with the actions
378+ index = list_display .index ("admin_list_actions" )
379+ self .list_display = (
380+ * list_display [:index ], # All items before admin_list_actions
381+ "state_indicator" , # Add the state indicator before admin_list_actions
382+ * list_display [index :], # All items after admin_list_actions
383+ )
384+ else :
385+ # Add the state indicator and admin_list_actions to the end of the list_display
386+ self .list_display = (* list_display , "state_indicator" , "admin_list_actions" ,)
387+ return super ().get_list_display (request )
388+
347389
348390class ExtendedVersionAdminMixin (
349391 ExtendedListDisplayMixin ,
0 commit comments