Skip to content

Commit

Permalink
Merge branch 'release/0.2.13'
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Jan 12, 2019
2 parents 81323aa + 3a5e00b commit 7e810ef
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.12
0.2.13
37 changes: 21 additions & 16 deletions edc_export/exportables.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from collections import OrderedDict
from django.apps import apps as django_apps
from django.contrib import messages
from django.contrib.admin import sites
from django.core.exceptions import ObjectDoesNotExist
from edc_permissions.constants.group_names import EXPORT

from .model_options import ModelOptions
from django.contrib.admin.sites import site
from django.contrib.admin import sites


class Exportables(OrderedDict):
Expand All @@ -22,22 +21,10 @@ class Exportables(OrderedDict):

def __init__(self, app_configs=None, user=None, request=None):
super().__init__()
self._inlines = {}
app_configs = app_configs or self.get_app_configs()
app_configs.sort(key=lambda x: x.verbose_name)

inlines = {}
for site in sites.all_sites:
for model_cls, admin_site in site._registry.items():
for inline_cls in admin_site.inlines:
model_opts = ModelOptions(
model=inline_cls.model._meta.label_lower)
try:
inlines[model_cls._meta.app_label].append(model_opts)
except KeyError:
inlines[model_cls._meta.app_label] = [model_opts]
inlines[model_cls._meta.app_label].sort(
key=lambda x: x.verbose_name.title())

try:
user.groups.get(name=self.export_group_name)
except ObjectDoesNotExist:
Expand All @@ -61,11 +48,29 @@ def __init__(self, app_configs=None, user=None, request=None):
list_models.sort(key=lambda x: x.verbose_name.title())
exportable = {
'models': models,
'inlines': inlines.get(model._meta.app_label),
'inlines': self.inlines.get(model._meta.app_label),
'historicals': historical_models,
'lists': list_models}
self.update({app_config: exportable})

@property
def inlines(self):
if not self._inlines:
for site in sites.all_sites:
for model_cls, admin_site in site._registry.items():
for inline_cls in admin_site.inlines:
model_opts = ModelOptions(
model=inline_cls.model._meta.label_lower)
try:
self._inlines[model_cls._meta.app_label].append(
model_opts)
except KeyError:
self._inlines[model_cls._meta.app_label] = [
model_opts]
self._inlines[model_cls._meta.app_label].sort(
key=lambda x: x.verbose_name.title())
return self._inlines

def get_app_configs(self):
"""Returns a list of app_configs with exportable data.
"""
Expand Down
4 changes: 2 additions & 2 deletions edc_export/tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ def create_crf(self, i=None):
date1=get_utcnow(),
int1=i,
uuid1=uuid.uuid4())
crf_one = CrfOne.objects.create(
CrfOne.objects.create(
subject_visit=self.subject_visit,
dte=get_utcnow())
crf_two = CrfTwo.objects.create(
CrfTwo.objects.create(
subject_visit=self.subject_visit,
dte=get_utcnow())
CrfThree.objects.create(
Expand Down

0 comments on commit 7e810ef

Please sign in to comment.