Skip to content

Commit

Permalink
pep8
Browse files Browse the repository at this point in the history
  • Loading branch information
jmerdich committed Nov 19, 2016
1 parent 4883717 commit bbc5605
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 2 additions & 0 deletions report_builder/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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')
20 changes: 9 additions & 11 deletions report_builder/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@

AUTH_USER_MODEL = getattr(settings, 'AUTH_USER_MODEL', 'auth.User')


@lru_cache(maxsize=None)
def get_model_contenttype(name):
if "." in name:
# Fully qualified model 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
Expand All @@ -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)
Expand Down

0 comments on commit bbc5605

Please sign in to comment.