Skip to content

Commit d317c41

Browse files
authored
Merge branch 'dev' into 1347-add-official-dark-mode-theme
2 parents 0699915 + 55e83fa commit d317c41

5 files changed

Lines changed: 46 additions & 27 deletions

File tree

poetry.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tom_common/templatetags/tom_common_extras.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@
2222
def navbar_app_addons(context, position='left'):
2323
"""
2424
Imports the navbar content from appropriate apps
25-
This should be a list of partials containing an <li> element that you would like displayed in the navbar with the
26-
following format:
27-
`<li class="nav-item"> <a class="nav-link" href="{% url 'namespace:view_name' %}">Link Text</a> </li>`
25+
Each nav_item should be contained in a list of dictionaries in an app's apps.py `nav_items` method.
26+
Each nav_item dictionary should contain a 'partial' key with the path to the html partial template and
27+
optionally a 'context' key with the path to the context processor class (typically a templatetag). An optional
28+
'position' key will add the partial to either the right or left side of the nav bar.
29+
30+
FOR EXAMPLE:
31+
[{'partial': 'path/to/partial.html',
32+
'context': 'path/to/context/data/method',
33+
'position: 'left'}]
2834
"""
2935
nav_items_to_display = []
3036
for app in apps.get_app_configs():
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
{% for button in button_list %}
2-
<a href="{% url button.namespace pk=target.id %}" title="{{button.title}}" class="{{ button.class }}">{{button.text}}</a>
1+
{% load tom_common_extras %}
2+
{% for button in target_buttons_to_display %}
3+
{% show_individual_app_partial button %}
34
{% endfor %}

tom_targets/templates/tom_targets/partials/target_buttons.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
<a href="{% url 'tom_targets:share' pk=target.id %}" title="Share target" class="btn btn-info">Share</a>
66
{% endif %}
77
<a href="{% url 'tom_targets:delete' pk=target.id %}" title="Delete target" class="btn btn-warning">Delete</a>
8-
{% get_buttons target %}
8+
{% get_buttons %}
99
</div>

tom_targets/templatetags/targets_extras.py

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -475,29 +475,41 @@ def create_persistent_share(context, target):
475475
return {'form': form, 'target': target}
476476

477477

478-
@register.inclusion_tag('tom_targets/partials/module_buttons.html')
479-
def get_buttons(target):
478+
@register.inclusion_tag('tom_targets/partials/module_buttons.html', takes_context=True)
479+
def get_buttons(context):
480480
"""
481-
Returns a list of buttons from imported modules to be displayed on the target detail page.
482-
In order to add a button to the target detail page, an app must contain an integration points attribute.
483-
The Integration Points attribute must be a dictionary with a key of 'target_detail_button':
484-
'target_detail_button' = {'namespace': <<redirect path, i.e. 'app:name'>>,
485-
'title': <<Button title>>,
486-
'class': <<Button class i.e 'btn btn-info'>>,
487-
'text': <<What you want the button to actually say>>,
488-
}
481+
Imports the target detail Button content from relevant apps into the template.
489482
483+
Each target_button should be contained in a list of dictionaries in an app's apps.py `target_detail_buttons` method.
484+
Each target_button dictionary should contain a 'partial' key with the path to the html partial template and
485+
optionally a 'context' key with the path to the context processor class (typically a templatetag).
486+
487+
FOR EXAMPLE:
488+
[{'partial': 'path/to/partial.html',
489+
'context': 'path/to/context/data/method'}]
490490
"""
491-
button_list = []
491+
target_buttons_to_display = []
492492
for app in apps.get_app_configs():
493493
try:
494-
button_info = app.target_detail_buttons()
495-
if button_info:
496-
button_list.append(button_info)
494+
target_buttons = app.target_detail_buttons()
497495
except AttributeError:
498-
pass
499-
500-
return {'target': target, 'button_list': button_list}
496+
continue
497+
if target_buttons:
498+
for button in target_buttons:
499+
new_context = {}
500+
if button.get('context'):
501+
try:
502+
context_method = import_string(button.get('context'))
503+
except ImportError as e:
504+
logger.warning(f'WARNING: Could not import context for {app.name} target detail button from '
505+
f'{button["context"]}.\n'
506+
f'{e}')
507+
continue
508+
new_context = context_method(context)
509+
target_buttons_to_display.append({'partial': button['partial'],
510+
'context': new_context})
511+
context['target_buttons_to_display'] = target_buttons_to_display
512+
return context
501513

502514

503515
@register.filter

0 commit comments

Comments
 (0)