saxix / django-adminactions

@@ -250,7 +250,8 @@
Loading
250 250
                             updated=updated)
251 251
252 252
    opts = modeladmin.model._meta
253 -
    perm = "{0}.{1}".format(opts.app_label, get_permission_codename('adminactions_massupdate', opts))
253 +
    perm = "{0}.{1}".format(opts.app_label,
254 +
                            get_permission_codename(mass_update.base_permission, opts))
254 255
    if not request.user.has_perm(perm):
255 256
        messages.error(request, _('Sorry you do not have rights to execute this action'))
256 257
        return
@@ -382,3 +383,4 @@
Loading
382 383
383 384
384 385
mass_update.short_description = _("Mass update")
386 +
mass_update.base_permission = 'adminactions_massupdate'

@@ -21,7 +21,8 @@
Loading
21 21
    """
22 22
23 23
    opts = modeladmin.model._meta
24 -
    perm = "{0}.{1}".format(opts.app_label.lower(), get_permission_codename('adminactions_byrowsupdate', opts))
24 +
    perm = "{0}.{1}".format(opts.app_label.lower(),
25 +
                            get_permission_codename(byrows_update.base_permission, opts))
25 26
    if not request.user.has_perm(perm):
26 27
        messages.error(request, _('Sorry you do not have rights to execute this action'))
27 28
        return
@@ -40,6 +41,7 @@
Loading
40 41
41 42
    def formfield_callback(field, **kwargs):
42 43
        return modeladmin.formfield_for_dbfield(field, request=request, **kwargs)
44 +
43 45
    ActionForm = modelform_factory(
44 46
        modeladmin.model,
45 47
        form=GenericActionForm,
@@ -89,6 +91,7 @@
Loading
89 91
90 92
91 93
byrows_update.short_description = _("By rows update")
94 +
byrows_update.base_permission = 'adminactions_byrowsupdate'
92 95
93 96
94 97
def byrows_update_get_fields(modeladmin):

@@ -37,7 +37,8 @@
Loading
37 37
38 38
def graph_queryset(modeladmin, request, queryset):  # noqa
39 39
    opts = modeladmin.model._meta
40 -
    perm = "{0}.{1}".format(opts.app_label.lower(), get_permission_codename('adminactions_chart', opts))
40 +
    perm = "{0}.{1}".format(opts.app_label.lower(),
41 +
                            get_permission_codename(graph_queryset.base_permission, opts))
41 42
    if not request.user.has_perm(perm):
42 43
        messages.error(request, _('Sorry you do not have rights to execute this action'))
43 44
        return
@@ -153,3 +154,4 @@
Loading
153 154
154 155
155 156
graph_queryset.short_description = _("Graph selected records")
157 +
graph_queryset.base_permission = 'adminactions_chart'

@@ -35,7 +35,8 @@
Loading
35 35
        export a queryset to csv file
36 36
    """
37 37
    opts = modeladmin.model._meta
38 -
    perm = "{0}.{1}".format(opts.app_label, get_permission_codename('adminactions_export', opts))
38 +
    perm = "{0}.{1}".format(opts.app_label,
39 +
                            get_permission_codename(base_export.base_permission, opts))
39 40
    if not request.user.has_perm(perm):
40 41
        messages.error(request, _('Sorry you do not have rights to execute this action'))
41 42
        return
@@ -118,6 +119,9 @@
Loading
118 119
    return render(request, template, ctx)
119 120
120 121
122 +
base_export.base_permission = 'adminactions_export'
123 +
124 +
121 125
def export_as_csv(modeladmin, request, queryset):
122 126
    return base_export(modeladmin, request, queryset,
123 127
                       impl=_export_as_csv,
@@ -132,6 +136,7 @@
Loading
132 136
133 137
134 138
export_as_csv.short_description = _("Export as CSV")
139 +
export_as_csv.base_permission = 'adminactions_export'
135 140
136 141
137 142
def export_as_xls(modeladmin, request, queryset):
@@ -148,6 +153,7 @@
Loading
148 153
149 154
150 155
export_as_xls.short_description = _("Export as XLS")
156 +
export_as_xls.base_permission = 'adminactions_export'
151 157
152 158
153 159
class FlatCollector:
@@ -199,7 +205,8 @@
Loading
199 205
                                       widget=forms.HiddenInput({'class': 'select-across'}))
200 206
    action = forms.CharField(label='', required=True, initial='', widget=forms.HiddenInput())
201 207
202 -
    use_natural_key = forms.BooleanField(required=False)
208 +
    use_natural_pk = forms.BooleanField(label=_('Use Natural Primary Keys'), required=False)
209 +
    use_natural_fk = forms.BooleanField(label=_('Use Natural Foreign Keys'), required=False)
203 210
    on_screen = forms.BooleanField(label='Dump on screen', required=False)
204 211
    add_foreign_keys = forms.BooleanField(required=False)
205 212
@@ -212,7 +219,8 @@
Loading
212 219
213 220
    json = ser.get_serializer(fmt)()
214 221
    ret = json.serialize(data,
215 -
                         use_natural_foreign_keys=form.cleaned_data.get('use_natural_key', False),
222 +
                         use_natural_foreign_keys=form.cleaned_data.get('use_natural_fk', False),
223 +
                         use_natural_primary_keys=form.cleaned_data.get('use_natural_pk', False),
216 224
                         indent=form.cleaned_data.get('indent'))
217 225
218 226
    response = HttpResponse(content_type='application/json')
@@ -231,7 +239,8 @@
Loading
231 239
               'serializer': 'json',
232 240
               'indent': 4}
233 241
    opts = modeladmin.model._meta
234 -
    perm = "{0}.{1}".format(opts.app_label, get_permission_codename('adminactions_export', opts))
242 +
    perm = "{0}.{1}".format(opts.app_label,
243 +
                            get_permission_codename(export_as_fixture.base_permission, opts))
235 244
    if not request.user.has_perm(perm):
236 245
        messages.error(request, _('Sorry you do not have rights to execute this action'))
237 246
        return
@@ -305,6 +314,7 @@
Loading
305 314
306 315
307 316
export_as_fixture.short_description = _("Export as fixture")
317 +
export_as_fixture.base_permission = 'adminactions_export'
308 318
309 319
310 320
def export_delete_tree(modeladmin, request, queryset):  # noqa
@@ -313,7 +323,8 @@
Loading
313 323
    That mean that dump what will be deleted if the queryset was deleted
314 324
    """
315 325
    opts = modeladmin.model._meta
316 -
    perm = "{0}.{1}".format(opts.app_label, get_permission_codename('adminactions_export', opts))
326 +
    perm = "{0}.{1}".format(opts.app_label,
327 +
                            get_permission_codename(export_delete_tree.base_permission, opts))
317 328
    if not request.user.has_perm(perm):
318 329
        messages.error(request, _('Sorry you do not have rights to execute this action'))
319 330
        return
@@ -397,3 +408,4 @@
Loading
397 408
398 409
399 410
export_delete_tree.short_description = _("Export delete tree")
411 +
export_delete_tree.base_permission = 'adminactions_export'

@@ -83,7 +83,8 @@
Loading
83 83
    """
84 84
85 85
    opts = modeladmin.model._meta
86 -
    perm = "{0}.{1}".format(opts.app_label, get_permission_codename('adminactions_merge', opts))
86 +
    perm = "{0}.{1}".format(opts.app_label,
87 +
                            get_permission_codename(merge.base_permission, opts))
87 88
    if not request.user.has_perm(perm):
88 89
        messages.error(request, _('Sorry you do not have rights to execute this action'))
89 90
        return
@@ -212,3 +213,4 @@
Loading
212 213
213 214
214 215
merge.short_description = _("Merge selected %(verbose_name_plural)s")
216 +
merge.base_permission = 'adminactions_merge'

@@ -18,13 +18,17 @@
Loading
18 18
def create_extra_permissions():
19 19
    from django.contrib.auth.models import Permission
20 20
    from django.contrib.contenttypes.models import ContentType
21 +
22 +
    from .actions import actions as aa
23 +
24 +
    #  ('adminactions_export', 'adminactions_massupdate',
25 +
    #                        'adminactions_merge', 'adminactions_chart',
26 +
    #                        'adminactions_byrowsupdate')
21 27
    for model in apps.get_models():
22 -
        for action in ('adminactions_export', 'adminactions_massupdate',
23 -
                       'adminactions_merge', 'adminactions_chart',
24 -
                       'adminactions_byrowsupdate'):
28 +
        for action in aa:
25 29
            opts = model._meta
26 -
            codename = get_permission_codename(action, opts)
27 -
            label = 'Can {} {} (adminactions)'.format(action.replace('adminactions_', ""),
30 +
            codename = get_permission_codename(action.base_permission, opts)
31 +
            label = 'Can {} {} (adminactions)'.format(action.base_permission.replace('adminactions_', ""),
28 32
                                                      opts.verbose_name_raw)
29 33
            ct = ContentType.objects.get_for_model(model)
30 34
            params = dict(codename=codename,

@@ -4,6 +4,8 @@
Loading
4 4
from django.core.exceptions import ValidationError
5 5
from django.template.response import TemplateResponse
6 6
7 +
from .perms import get_permission_codename
8 +
7 9
8 10
class ImportFixtureForm(forms.Form):
9 11
    fixture_file = forms.FileField(required=False)
@@ -51,4 +53,17 @@
Loading
51 53
    return TemplateResponse(request, "adminactions/helpers/import_fixture.html", context)
52 54
53 55
54 -
56 +
class AdminActionPermMixin:
57 +
    def _filter_actions_by_permissions(self, request, actions):
58 +
        opts = self.model._meta
59 +
        filtered_actions = []
60 +
        actions = super()._filter_actions_by_permissions(request, actions)
61 +
        from .actions import actions as aa
62 +
        for action in actions:
63 +
            if action[0] in aa:
64 +
                perm = "{0}.{1}".format(opts.app_label,
65 +
                                        get_permission_codename(action[0].base_permission, opts))
66 +
                if not request.user.has_perm(perm):
67 +
                    continue
68 +
            filtered_actions.append(action)
69 +
        return filtered_actions
Files Coverage
src/adminactions 84.75%
Project Totals (23 files) 84.75%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading