Skip to content

Commit da44758

Browse files
committed
consolodate app import code
1 parent 9f65ce1 commit da44758

1 file changed

Lines changed: 15 additions & 45 deletions

File tree

tom_targets/templatetags/targets_extras.py

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -509,54 +509,14 @@ def extra_form_field(form, field):
509509
return form[field]
510510

511511

512-
@register.inclusion_tag('tom_targets/partials/app_tab_divs.html', takes_context=True)
513-
def include_app_tab_divs(context):
514-
"""
515-
Imports the user list content from relevant apps into the template.
516-
517-
Each user_list should be contained in a list of dictionaries in an app's apps.py `user_lists` method.
518-
Each user_list dictionary should contain a 'context' key with the path to the context processor class (typically a
519-
templatetag), and a 'partial' key with the path to the html partial template.
520-
521-
FOR EXAMPLE:
522-
[{'partial': 'path/to/partial.html',
523-
'context': 'path/to/context/data/method'}]
524-
"""
525-
target_tabs_to_display = []
526-
for app in apps.get_app_configs():
527-
try:
528-
target_tabs = app.target_detail_tabs()
529-
except AttributeError:
530-
continue
531-
if target_tabs:
532-
for tab in target_tabs:
533-
new_context = {}
534-
if tab.get('context'):
535-
try:
536-
context_method = import_string(tab['context'])
537-
except ImportError as e:
538-
logger.warning(f'WARNING: Could not import context for {app.name} target detail tab from '
539-
f'{tab["context"]}.\n'
540-
f'{e}')
541-
continue
542-
new_context = context_method(context)
543-
target_tabs_to_display.append({'partial': tab['partial'],
544-
'context': new_context,
545-
'label': tab['label']})
546-
547-
context['target_tabs_to_display'] = target_tabs_to_display
548-
return context
549-
550-
551-
@register.inclusion_tag('tom_targets/partials/app_tabs.html', takes_context=True)
552-
def include_app_tabs(context):
512+
def get_app_tabs(context):
553513
"""
554514
Imports the target detail tab content from relevant apps into the template.
555515
556516
Each target_tab should be contained in a list of dictionaries in an app's apps.py `target_detail_tabs` method.
557-
Each target_tab dictionary should contain a 'context' key with the path to the context processor class (typically a
558-
templatetag), a 'partial' key with the path to the html partial template, and a 'label' key with a string
559-
describing the label for the tab.
517+
Each target_tab dictionary should contain a 'context' key with the path to the context processor class
518+
(typically a templatetag), a 'partial' key with the path to the html partial template, and a 'label' key with
519+
a string describing the label for the tab.
560520
561521
FOR EXAMPLE:
562522
[{'partial': 'path/to/partial.html',
@@ -584,6 +544,16 @@ def include_app_tabs(context):
584544
target_tabs_to_display.append({'partial': tab['partial'],
585545
'context': new_context,
586546
'label': tab['label']})
547+
return target_tabs_to_display
548+
549+
550+
@register.inclusion_tag('tom_targets/partials/app_tab_divs.html', takes_context=True)
551+
def include_app_tab_divs(context):
552+
context['target_tabs_to_display'] = get_app_tabs(context)
553+
return context
554+
587555

588-
context['target_tabs_to_display'] = target_tabs_to_display
556+
@register.inclusion_tag('tom_targets/partials/app_tabs.html', takes_context=True)
557+
def include_app_tabs(context):
558+
context['target_tabs_to_display'] = get_app_tabs(context)
589559
return context

0 commit comments

Comments
 (0)