Task view: Show user name instead of ID.
This commit is contained in:
@@ -1,11 +1,10 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from flask import Blueprint, render_template, request
|
from flask import Blueprint, render_template, request, current_app
|
||||||
import flask
|
import flask
|
||||||
import flask_login
|
import flask_login
|
||||||
|
|
||||||
import pillarsdk
|
import pillarsdk
|
||||||
import pillarsdk.exceptions as sdk_exceptions
|
|
||||||
from pillar.web.system_util import pillar_api
|
from pillar.web.system_util import pillar_api
|
||||||
import pillar.api.utils
|
import pillar.api.utils
|
||||||
|
|
||||||
@@ -51,6 +50,24 @@ def for_project(project, task_id=None):
|
|||||||
project=project)
|
project=project)
|
||||||
|
|
||||||
|
|
||||||
|
def _get_user_info(user_id):
|
||||||
|
"""Returns email & full name of the user.
|
||||||
|
|
||||||
|
Only returns those two fields, so the return value is the same
|
||||||
|
for authenticated & non-authenticated users, which is why we're
|
||||||
|
allowed to cache it globally.
|
||||||
|
|
||||||
|
Returns None when the user cannot be found.
|
||||||
|
"""
|
||||||
|
|
||||||
|
user = pillarsdk.User.find(user_id, api=pillar_api())
|
||||||
|
if not user:
|
||||||
|
return user
|
||||||
|
|
||||||
|
return {'email': user.email,
|
||||||
|
'full_name': user.full_name}
|
||||||
|
|
||||||
|
|
||||||
@perproject_blueprint.route('/<task_id>')
|
@perproject_blueprint.route('/<task_id>')
|
||||||
@attract_project_view(extension_props=True)
|
@attract_project_view(extension_props=True)
|
||||||
def view_task(project, attract_props, task_id):
|
def view_task(project, attract_props, task_id):
|
||||||
@@ -60,12 +77,19 @@ def view_task(project, attract_props, task_id):
|
|||||||
api = pillar_api()
|
api = pillar_api()
|
||||||
task = pillarsdk.Node.find(task_id, api=api)
|
task = pillarsdk.Node.find(task_id, api=api)
|
||||||
node_type = project.get_node_type(node_type_task['name'])
|
node_type = project.get_node_type(node_type_task['name'])
|
||||||
|
|
||||||
# Fetch project users so that we can assign them tasks
|
# Fetch project users so that we can assign them tasks
|
||||||
try:
|
if 'PUT' in task.allowed_methods:
|
||||||
users = project.get_users(api=api)
|
users = project.get_users(api=api)
|
||||||
project.users = users['_items']
|
project.users = users['_items']
|
||||||
except sdk_exceptions.ForbiddenAccess:
|
else:
|
||||||
project.users = []
|
# Cache user info for 5 minutes.
|
||||||
|
@current_app.cache.memoize(timeout=300, make_name='%s._cached_user_info' % __name__)
|
||||||
|
def _cached_user_info(user_id):
|
||||||
|
return _get_user_info(user_id)
|
||||||
|
|
||||||
|
task.properties.assigned_to.users = [_cached_user_info(uid)
|
||||||
|
for uid in task.properties.assigned_to.users]
|
||||||
|
|
||||||
return render_template('attract/tasks/view_task_embed.html',
|
return render_template('attract/tasks/view_task_embed.html',
|
||||||
task=task,
|
task=task,
|
||||||
|
@@ -89,7 +89,7 @@
|
|||||||
dd {{ task.properties.status | undertitle }}
|
dd {{ task.properties.status | undertitle }}
|
||||||
dt Assignees:
|
dt Assignees:
|
||||||
| {% for u in task.properties.assigned_to['users'] %}
|
| {% for u in task.properties.assigned_to['users'] %}
|
||||||
dd {{ u }}
|
dd {{ u.full_name }}
|
||||||
| {% else %}
|
| {% else %}
|
||||||
dd not assigned
|
dd not assigned
|
||||||
| {% endfor %}
|
| {% endfor %}
|
||||||
|
Reference in New Issue
Block a user