From bbc56052aa63b9b5b79ed28971fa2f180dc77064 Mon Sep 17 00:00:00 2001 From: Jake Merdich Date: Sat, 19 Nov 2016 17:02:29 -0500 Subject: [PATCH] pep8 --- report_builder/admin.py | 2 ++ report_builder/models.py | 20 +++++++++----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/report_builder/admin.py b/report_builder/admin.py index c452a57d..eb259634 100644 --- a/report_builder/admin.py +++ b/report_builder/admin.py @@ -79,6 +79,7 @@ def save_model(self, request, obj, form, change): if star_user: # Star created reports automatically obj.starred.add(request.user) + admin.site.register(Report, ReportAdmin) admin.site.register(Format) @@ -92,5 +93,6 @@ def export_to_report(modeladmin, request, queryset): ct = ContentType.objects.get_for_model(queryset.model) return HttpResponseRedirect(reverse('export_to_report') + "?ct=%s&admin_url=%s&ids=%s" % (ct.pk, admin_url, ",".join(selected))) + if getattr(settings, 'REPORT_BUILDER_GLOBAL_EXPORT', False): admin.site.add_action(export_to_report, 'Export to Report') diff --git a/report_builder/models.py b/report_builder/models.py index 116355f3..31cf5f13 100644 --- a/report_builder/models.py +++ b/report_builder/models.py @@ -22,6 +22,7 @@ AUTH_USER_MODEL = getattr(settings, 'AUTH_USER_MODEL', 'auth.User') + @lru_cache(maxsize=None) def get_model_contenttype(name): if "." in name: @@ -29,9 +30,9 @@ def get_model_contenttype(name): split_name = name.lower().split('.') # Negative indexing allows, eg. "django.contrib.auth.User" model_query = { - 'app_label':split_name[-2], - 'model': split_name[-1] - } + 'app_label': split_name[-2], + 'model': split_name[-1] + } model_name = "%s.%s" % (model_query['app_label'], model_query['model']) else: # short model name @@ -43,30 +44,27 @@ def get_model_contenttype(name): model_ct = ContentType.objects.get(**model_query) except ContentType.DoesNotExist: raise ImproperlyConfigured( - "REPORT_BUILDER: Model '%s' (from '%s') could not be found." % - (model_name, name) - ) + "REPORT_BUILDER: Model '%s' (from '%s') could not be found." % (model_name, name)) except ContentType.MultipleObjectsReturned: possible_cts = ContentType.objects.filter(**model_query).values_list('app_label', 'model') possible_cts = [".".join(ct) for ct in possible_cts] raise ImproperlyConfigured( - "REPORT_BUILDER: Model '%s' is ambiguous. Possible values: %s" % - (name, str(possible_cts)) - ) + "REPORT_BUILDER: Model '%s' is ambiguous. Possible values: %s" % (name, str(possible_cts))) else: return model_ct + def get_allowed_models(): models = ContentType.objects.all() if getattr(settings, 'REPORT_BUILDER_INCLUDE', False): - ct_pks = [] # pks of all included model contenttypes + ct_pks = [] # pks of all included model contenttypes for element in settings.REPORT_BUILDER_INCLUDE: ct_pks.append(get_model_contenttype(element).pk) models = ContentType.objects.filter(pk__in=ct_pks) if getattr(settings, 'REPORT_BUILDER_EXCLUDE', False): - ct_pks = [] # pks of all excluded model contenttypes + ct_pks = [] # pks of all excluded model contenttypes for element in settings.REPORT_BUILDER_EXCLUDE: ct_pks.append(get_model_contenttype(element).pk) models = models.exclude(pk__in=ct_pks)