Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add integration point to user list page #1157

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tom_common/templates/auth/partials/app_user_lists.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% load user_extras %}
{% for user_list in user_lists_to_display %}
{% show_individual_app_partial user_list %}
<hr/>
{% endfor %}
1 change: 1 addition & 0 deletions tom_common/templates/auth/user_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{% load user_extras %}
{% block title %}User Management{% endblock %}
{% block content %}
{% include_app_user_lists %}
{% group_list %}
<hr/>
{% user_list %}
Expand Down
2 changes: 1 addition & 1 deletion tom_common/templates/tom_common/partials/app_profiles.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="row">
<div class="col-6">
{% for profile in profiles_to_display %}
{% show_individual_app_profile profile %}
{% show_individual_app_partial profile %}

{% comment %}
Start new column halfway through the list of profiles.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% comment %}
This partial template includes another partial from the context specific to a specific App's profile.
This allows the partial to be rendered with only the context specified by the app, without interference from
other app profile contexts.
This partial template includes another partial from the context specific to a specific App's partial.
This allows the partial to be rendered with only the context specified by the app, without interference from contexts
from other apps.
{% endcomment %}

{% include profile_partial %}
{% include app_partial %}
47 changes: 41 additions & 6 deletions tom_common/templatetags/user_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,41 @@ def user_list(context):
}


@register.inclusion_tag('auth/partials/app_user_lists.html', takes_context=True)
def include_app_user_lists(context):
"""
Imports the user list content from relevant apps into the template.

Each user_list should be contained in a list of dictionaries in an app's apps.py `user_lists` method.
Each user_list dictionary should contain a 'context' key with the path to the context processor class (typically a
templatetag), and a 'partial' key with the path to the html partial template.

FOR EXAMPLE:
[{'partial': 'path/to/partial.html',
'context': 'path/to/context/data/method'}]
"""
user_lists_to_display = []
for app in apps.get_app_configs():
try:
user_lists = app.user_lists()
except AttributeError:
continue
if user_lists:
for app_users in user_lists:
try:
context_method = import_string(app_users['context'])
except ImportError:
logger.warning(f'WARNING: Could not import context for {app.name} user list from '
f'{app_users["context"]}.\n'
f'Are you sure you have the right path?')
continue
new_context = context_method(context)
user_lists_to_display.append({'partial': app_users['partial'], 'context': new_context})

context['user_lists_to_display'] = user_lists_to_display
return context


@register.inclusion_tag('tom_common/partials/user_data.html')
def user_data(user):
"""
Expand Down Expand Up @@ -84,12 +119,12 @@ def show_app_profiles(context, user):
return context


@register.inclusion_tag('tom_common/partials/include_profile_card.html', takes_context=True)
def show_individual_app_profile(context, profile_data):
@register.inclusion_tag('tom_common/partials/include_app_partial.html', takes_context=True)
def show_individual_app_partial(context, app_partial_data):
"""
An Inclusion tag for setting the unique context for each app's user profile.
An Inclusion tag for setting the unique context for an app's partial.
"""
for item in profile_data['context']:
context[item] = profile_data['context'][item]
context['profile_partial'] = profile_data['partial']
for item in app_partial_data['context']:
context[item] = app_partial_data['context'][item]
context['app_partial'] = app_partial_data['partial']
return context
Loading