Browse Source

fix #731: admin actions props cleanup

Rafał Pitoń 8 years ago
parent
commit
77a800cd41

+ 4 - 4
docs/WritingNewAdminActions.md

@@ -24,7 +24,7 @@ Next you define your own views inheriting from your mixin and base views. Misago
 
 
 Base class for admin mixins that contain properties and behaviours shared between admin views. While you are allowed to set any properties and function on your own mixins to dry your admin views more, bare minimum expected from you is following:
 Base class for admin mixins that contain properties and behaviours shared between admin views. While you are allowed to set any properties and function on your own mixins to dry your admin views more, bare minimum expected from you is following:
 
 
-* `Model` property or `get_model(self)` method to get model type.
+* `model` property or `get_model(self)` method to get model type.
 * `root_link` property that is string with link name for "index" view for admin actions (usually link to items list).
 * `root_link` property that is string with link name for "index" view for admin actions (usually link to items list).
 * `templates_dir` property being string with name of directory with admin templates used by mixin views.
 * `templates_dir` property being string with name of directory with admin templates used by mixin views.
 
 
@@ -37,7 +37,7 @@ Base class for lists if items. Supports following properties:
 
 
 * `template` - name of template file located in `templates_dir` used to render this view. Defaults to `list.html`
 * `template` - name of template file located in `templates_dir` used to render this view. Defaults to `list.html`
 * `items_per_page` - integer controlling number of items displayed on single page. Defaults to 0 which means no pagination
 * `items_per_page` - integer controlling number of items displayed on single page. Defaults to 0 which means no pagination
-* `SearchForm` - Form type used to construct form for filtering this list. Either this field or `get_search_form` method is required to make list searchable.
+* `search_form` - Form type used to construct form for filtering this list. Either this field or `get_search_form` method is required to make list searchable.
 * `ordering` - list of supported sorting methods. List of tuples. Each tuple should countain two items: name of ordering method (eg. "Usernames, descending") and `order_by` argument (`-username`). Defaults to none which means queryset will not be ordered. If contains only one element, queryset is ordered, but option for changing ordering method is not displayed.
 * `ordering` - list of supported sorting methods. List of tuples. Each tuple should countain two items: name of ordering method (eg. "Usernames, descending") and `order_by` argument (`-username`). Defaults to none which means queryset will not be ordered. If contains only one element, queryset is ordered, but option for changing ordering method is not displayed.
 * `mass_actions` - list of dicts defining list's mass actions. Each dict should have `action` key that will be used to identify method to call, `name` for displayed name, `icon` for icon and optional `confirmation` message. Actions can define optional "is_atomic" key to control if they should be wrapped in transaction or not. This is default behaviour for mass actions.
 * `mass_actions` - list of dicts defining list's mass actions. Each dict should have `action` key that will be used to identify method to call, `name` for displayed name, `icon` for icon and optional `confirmation` message. Actions can define optional "is_atomic" key to control if they should be wrapped in transaction or not. This is default behaviour for mass actions.
 * `selection_label` - Label displayed on mass action button if there are items selected. `0` will be replaced with number of selected items automatically.
 * `selection_label` - Label displayed on mass action button if there are items selected. `0` will be replaced with number of selected items automatically.
@@ -85,12 +85,12 @@ If you add custom mass action to view, besides adding new entry to `mass_actions
 Base class for forms views.
 Base class for forms views.
 
 
 * `template` - name of template file located in `templates_dir` used to render this view. Defaults to `form.html`
 * `template` - name of template file located in `templates_dir` used to render this view. Defaults to `form.html`
-* `Form` property or **create_form_type** method - `create_form` method is called with `request` as its argument and is expected to return form type that will be used by view. If you need to build form type dynamically, instead of defining `Form` property, define your own `create_form`.
+* `form` property or **create_form_type** method - `create_form` method is called with `request` as its argument and is expected to return form type that will be used by view. If you need to build form type dynamically, instead of defining `form` property, define your own `create_form`.
 
 
 
 
 #### `create_form_type(self, request)`
 #### `create_form_type(self, request)`
 
 
-Returns form type that will be used to create form instance. By default returns value of `Form` property.
+Returns form type that will be used to create form instance. By default returns value of `form` property.
 
 
 
 
 #### `initialize_form(self, FormType, request)`
 #### `initialize_form(self, FormType, request)`

+ 1 - 1
misago/acl/views.py

@@ -11,7 +11,7 @@ from .models import Role
 
 
 class RoleAdmin(generic.AdminBaseMixin):
 class RoleAdmin(generic.AdminBaseMixin):
     root_link = 'misago:admin:permissions:users:index'
     root_link = 'misago:admin:permissions:users:index'
-    Model = Role
+    model = Role
     templates_dir = 'misago/admin/roles'
     templates_dir = 'misago/admin/roles'
     message_404 = _("Requested role does not exist.")
     message_404 = _("Requested role does not exist.")
 
 

+ 9 - 9
misago/admin/views/generic/formsbuttons.py

@@ -54,17 +54,17 @@ class TargetedView(AdminView):
 
 
 
 
 class FormView(TargetedView):
 class FormView(TargetedView):
-    Form = None
+    form = None
     template = 'form.html'
     template = 'form.html'
 
 
     def create_form_type(self, request):
     def create_form_type(self, request):
-        return self.Form
+        return self.form
 
 
-    def initialize_form(self, FormType, request):
+    def initialize_form(self, form, request):
         if request.method == 'POST':
         if request.method == 'POST':
-            return FormType(request.POST, request.FILES)
+            return form(request.POST, request.FILES)
         else:
         else:
-            return FormType()
+            return form()
 
 
     def handle_form(self, form, request):
     def handle_form(self, form, request):
         raise NotImplementedError(
         raise NotImplementedError(
@@ -92,13 +92,13 @@ class ModelFormView(FormView):
     message_submit = None
     message_submit = None
 
 
     def create_form_type(self, request, target):
     def create_form_type(self, request, target):
-        return self.Form
+        return self.form
 
 
-    def initialize_form(self, FormType, request, target):
+    def initialize_form(self, form, request, target):
         if request.method == 'POST':
         if request.method == 'POST':
-            return FormType(request.POST, request.FILES, instance=target)
+            return form(request.POST, request.FILES, instance=target)
         else:
         else:
-            return FormType(instance=target)
+            return form(instance=target)
 
 
     def handle_form(self, form, request, target):
     def handle_form(self, form, request, target):
         form.instance.save()
         form.instance.save()

+ 8 - 8
misago/admin/views/generic/list.py

@@ -185,23 +185,23 @@ class ListView(AdminView):
     """
     """
     Filter list items
     Filter list items
     """
     """
-    SearchForm = None
+    search_form = None
 
 
     def get_search_form(self, request):
     def get_search_form(self, request):
-        return self.SearchForm
+        return self.search_form
 
 
     @property
     @property
     def filters_session_key(self):
     def filters_session_key(self):
         return 'misago_admin_%s_filters' % self.root_link
         return 'misago_admin_%s_filters' % self.root_link
 
 
-    def get_filters_from_GET(self, SearchForm, request):
-        form = SearchForm(request.GET)
+    def get_filters_from_GET(self, search_form, request):
+        form = search_form(request.GET)
         form.is_valid()
         form.is_valid()
         return self.clean_filtering_data(form.cleaned_data)
         return self.clean_filtering_data(form.cleaned_data)
 
 
-    def get_filters_from_session(self, SearchForm, request):
+    def get_filters_from_session(self, search_form, request):
         session_filters = request.session.get(self.filters_session_key, {})
         session_filters = request.session.get(self.filters_session_key, {})
-        form = SearchForm(session_filters)
+        form = search_form(session_filters)
         form.is_valid()
         form.is_valid()
         return self.clean_filtering_data(form.cleaned_data)
         return self.clean_filtering_data(form.cleaned_data)
 
 
@@ -230,9 +230,9 @@ class ListView(AdminView):
         else:
         else:
             return {}
             return {}
 
 
-    def apply_filtering_on_context(self, context, active_filters, SearchForm):
+    def apply_filtering_on_context(self, context, active_filters, search_form):
         context['active_filters'] = active_filters
         context['active_filters'] = active_filters
-        context['search_form'] = SearchForm(initial=context['active_filters'])
+        context['search_form'] = search_form(initial=context['active_filters'])
 
 
         if context['active_filters']:
         if context['active_filters']:
             context['items'] = context['search_form'].filter_queryset(
             context['items'] = context['search_form'].filter_queryset(

+ 6 - 6
misago/admin/views/generic/mixin.py

@@ -4,12 +4,12 @@ class AdminBaseMixin(object):
 
 
     Takes following attributes:
     Takes following attributes:
 
 
-    Model = Model instance
-    root_link = name of link leading to root action (eg. list of all items
-    templates_dir = directory with templates
-    message_404 = string used in "requested item not found" messages
+    model - Model instance
+    root_link - name of link leading to root action (eg. list of all items
+    templates_dir - directory with templates
+    message_404 - string used in "requested item not found" messages
     """
     """
-    Model = None
+    model = None
     root_link = None
     root_link = None
     templates_dir = None
     templates_dir = None
     message_404 = None
     message_404 = None
@@ -18,4 +18,4 @@ class AdminBaseMixin(object):
         """
         """
         Basic method for retrieving Model, used in cases such as User model.
         Basic method for retrieving Model, used in cases such as User model.
         """
         """
-        return self.Model
+        return self.model

+ 1 - 1
misago/categories/views/categoriesadmin.py

@@ -13,7 +13,7 @@ from misago.categories.models import Category, RoleCategoryACL
 
 
 class CategoryAdmin(generic.AdminBaseMixin):
 class CategoryAdmin(generic.AdminBaseMixin):
     root_link = 'misago:admin:categories:nodes:index'
     root_link = 'misago:admin:categories:nodes:index'
-    Model = Category
+    model = Category
     templates_dir = 'misago/admin/categories'
     templates_dir = 'misago/admin/categories'
     message_404 = _("Requested category does not exist.")
     message_404 = _("Requested category does not exist.")
 
 

+ 1 - 1
misago/categories/views/permsadmin.py

@@ -15,7 +15,7 @@ from .categoriesadmin import CategoriesList, CategoryAdmin
 
 
 class CategoryRoleAdmin(generic.AdminBaseMixin):
 class CategoryRoleAdmin(generic.AdminBaseMixin):
     root_link = 'misago:admin:permissions:categories:index'
     root_link = 'misago:admin:permissions:categories:index'
-    Model = CategoryRole
+    model = CategoryRole
     templates_dir = 'misago/admin/categoryroles'
     templates_dir = 'misago/admin/categoryroles'
     message_404 = _("Requested role does not exist.")
     message_404 = _("Requested role does not exist.")
 
 

+ 1 - 1
misago/threads/views/admin/attachments.py

@@ -13,7 +13,7 @@ from ...models import Attachment, Post
 
 
 class AttachmentAdmin(generic.AdminBaseMixin):
 class AttachmentAdmin(generic.AdminBaseMixin):
     root_link = 'misago:admin:system:attachments:index'
     root_link = 'misago:admin:system:attachments:index'
-    Model = Attachment
+    model = Attachment
     templates_dir = 'misago/admin/attachments'
     templates_dir = 'misago/admin/attachments'
     message_404 = _("Requested attachment could not be found.")
     message_404 = _("Requested attachment could not be found.")
 
 

+ 2 - 2
misago/threads/views/admin/attachmenttypes.py

@@ -12,8 +12,8 @@ from ...models import AttachmentType
 
 
 class AttachmentTypeAdmin(generic.AdminBaseMixin):
 class AttachmentTypeAdmin(generic.AdminBaseMixin):
     root_link = 'misago:admin:system:attachment-types:index'
     root_link = 'misago:admin:system:attachment-types:index'
-    Model = AttachmentType
-    Form = AttachmentTypeForm
+    model = AttachmentType
+    form = AttachmentTypeForm
     templates_dir = 'misago/admin/attachmenttypes'
     templates_dir = 'misago/admin/attachmenttypes'
     message_404 = _("Requested attachment type could not be found.")
     message_404 = _("Requested attachment type could not be found.")
 
 

+ 3 - 3
misago/users/views/admin/bans.py

@@ -9,8 +9,8 @@ from ...models import Ban
 
 
 class BanAdmin(generic.AdminBaseMixin):
 class BanAdmin(generic.AdminBaseMixin):
     root_link = 'misago:admin:users:bans:index'
     root_link = 'misago:admin:users:bans:index'
-    Model = Ban
-    Form = BanForm
+    model = Ban
+    form = BanForm
     templates_dir = 'misago/admin/bans'
     templates_dir = 'misago/admin/bans'
     message_404 = _("Requested ban does not exist.")
     message_404 = _("Requested ban does not exist.")
 
 
@@ -27,7 +27,7 @@ class BansList(BanAdmin, generic.ListView):
         ('banned_value', _("A to z")),
         ('banned_value', _("A to z")),
         ('-banned_value', _("Z to a")),
         ('-banned_value', _("Z to a")),
     )
     )
-    SearchForm = SearchBansForm
+    search_form = SearchBansForm
     selection_label = _('With bans: 0')
     selection_label = _('With bans: 0')
     empty_selection_label = _('Select bans')
     empty_selection_label = _('Select bans')
     mass_actions = (
     mass_actions = (

+ 2 - 2
misago/users/views/admin/ranks.py

@@ -11,8 +11,8 @@ from ...models import Rank
 
 
 class RankAdmin(generic.AdminBaseMixin):
 class RankAdmin(generic.AdminBaseMixin):
     root_link = 'misago:admin:users:ranks:index'
     root_link = 'misago:admin:users:ranks:index'
-    Model = Rank
-    Form = RankForm
+    model = Rank
+    form = RankForm
     templates_dir = 'misago/admin/ranks'
     templates_dir = 'misago/admin/ranks'
     message_404 = _("Requested rank does not exist.")
     message_404 = _("Requested rank does not exist.")
 
 

+ 4 - 4
misago/users/views/admin/users.py

@@ -27,7 +27,7 @@ UserModel = get_user_model()
 class UserAdmin(generic.AdminBaseMixin):
 class UserAdmin(generic.AdminBaseMixin):
     root_link = 'misago:admin:users:accounts:index'
     root_link = 'misago:admin:users:accounts:index'
     templates_dir = 'misago/admin/users'
     templates_dir = 'misago/admin/users'
-    Model = UserModel
+    model = UserModel
 
 
     def create_form_type(self, request, target):
     def create_form_type(self, request, target):
         add_is_active_fields = False
         add_is_active_fields = False
@@ -43,7 +43,7 @@ class UserAdmin(generic.AdminBaseMixin):
             add_admin_fields = request.user.pk != target.pk
             add_admin_fields = request.user.pk != target.pk
 
 
         return EditUserFormFactory(
         return EditUserFormFactory(
-            self.Form, target,
+            self.form, target,
             add_is_active_fields=add_is_active_fields,
             add_is_active_fields=add_is_active_fields,
             add_admin_fields=add_admin_fields,
             add_admin_fields=add_admin_fields,
         )
         )
@@ -233,7 +233,7 @@ class UsersList(UserAdmin, generic.ListView):
 
 
 
 
 class NewUser(UserAdmin, generic.ModelFormView):
 class NewUser(UserAdmin, generic.ModelFormView):
-    Form = NewUserForm
+    form = NewUserForm
     template = 'new.html'
     template = 'new.html'
     message_submit = _('New user "%(user)s" has been registered.')
     message_submit = _('New user "%(user)s" has been registered.')
 
 
@@ -263,7 +263,7 @@ class NewUser(UserAdmin, generic.ModelFormView):
 
 
 
 
 class EditUser(UserAdmin, generic.ModelFormView):
 class EditUser(UserAdmin, generic.ModelFormView):
-    Form = EditUserForm
+    form = EditUserForm
     template = 'edit.html'
     template = 'edit.html'
     message_submit = _('User "%(user)s" has been edited.')
     message_submit = _('User "%(user)s" has been edited.')