From bf35b0a9b7d2eee255f208897701af2d573a9b17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 5 Oct 2016 11:51:07 +0200 Subject: [PATCH] Show user's task on /attract --- attract/routes.py | 12 ++++++++++- src/templates/attract/index.jade | 21 ++++++------------- .../attract/index_anon_left_column.jade | 3 +++ src/templates/attract/tasks/for_user.jade | 17 ++------------- .../attract/tasks/task_list_for_user.jade | 19 +++++++++++++++++ 5 files changed, 41 insertions(+), 31 deletions(-) create mode 100644 src/templates/attract/index_anon_left_column.jade create mode 100644 src/templates/attract/tasks/task_list_for_user.jade diff --git a/attract/routes.py b/attract/routes.py index e5ecfb4..dc7487c 100644 --- a/attract/routes.py +++ b/attract/routes.py @@ -2,18 +2,28 @@ import functools import logging from flask import Blueprint, render_template +import flask_login from pillar.api.utils import jsonify from pillar.web.system_util import pillar_api import pillarsdk +from attract import current_attract + blueprint = Blueprint('attract', __name__) log = logging.getLogger(__name__) @blueprint.route('/') def index(): - return render_template('attract/index.html') + user = flask_login.current_user + if user.is_authenticated: + tasks = current_attract.task_manager.tasks_for_user(user.objectid) + else: + tasks = None + + return render_template('attract/index.html', + tasks=tasks) def error_project_not_setup_for_attract(): diff --git a/src/templates/attract/index.jade b/src/templates/attract/index.jade index 1abc8ad..e0e4bc2 100644 --- a/src/templates/attract/index.jade +++ b/src/templates/attract/index.jade @@ -5,21 +5,12 @@ #dashboard .row .col-md-6 - h3 My Tasks - a.pull-right - small View All - - #task-list.col-list - - for (var i = 0; i < 15; ++i) { - a.col-list-item.task-list-item( - id="task-(TASK_ID)", - class="status-review task-link", - href="#") - span.status-indicator - span.name Task Name - span.type type - - } - + | {% if current_user.is_authenticated %} + | {% from "attract/tasks/task_list_for_user.html" import task_list_for_user %} + | {{ task_list_for_user(tasks['_meta']['total'], tasks['_items']) }} + | {% else %} + | {% include "attract/index_anon_left_column.html" %} + | {% endif %} .col-md-6 h3 Latest Edit img.img-responsive(src="//placehold.it/500x250") diff --git a/src/templates/attract/index_anon_left_column.jade b/src/templates/attract/index_anon_left_column.jade new file mode 100644 index 0000000..58f2e06 --- /dev/null +++ b/src/templates/attract/index_anon_left_column.jade @@ -0,0 +1,3 @@ +h3 Welcome to Attract + +p This is the left column. It contains left-handed things. diff --git a/src/templates/attract/tasks/for_user.jade b/src/templates/attract/tasks/for_user.jade index 979614e..3088d1f 100644 --- a/src/templates/attract/tasks/for_user.jade +++ b/src/templates/attract/tasks/for_user.jade @@ -3,21 +3,8 @@ | {% block page_title %}Tasks for you{% endblock %} | {% block body %} #col_main - .col_header.task-list-header - | Your tasks ({{ task_count }}) - - #task-list.col-list - | {% for task in tasks %} - //- NOTE: this is tightly linked to the JS in tasks.js, function task_add() - a.col-list-item.task-list-item( - class="status-{{ task.properties.status }} task-link", - title="In project '{{ task._project_info.name }}'", - href="{{ url_for('attract.tasks.perproject.view_task', project_url=task._project_info.url, task_id=task._id) }}") - span.status-indicator - span.name {{ task.name }} - span.type {{ task.properties.task_type }} - | {% endfor %} - + | {% from "attract/tasks/task_list_for_user.html" import task_list_for_user %} + | {{ task_list_for_user(task_count, tasks) }} .col-splitter #col_right diff --git a/src/templates/attract/tasks/task_list_for_user.jade b/src/templates/attract/tasks/task_list_for_user.jade new file mode 100644 index 0000000..e5225f9 --- /dev/null +++ b/src/templates/attract/tasks/task_list_for_user.jade @@ -0,0 +1,19 @@ +| {% macro task_list_for_user(task_count, tasks, include_shotname=True) -%} +.col_header.task-list-header + | Your tasks ({{ task_count }}) + +#task-list.col-list + | {% for task in tasks %} + //- NOTE: this is tightly linked to the JS in tasks.js, function task_add() + a.col-list-item.task-list-item( + class="status-{{ task.properties.status }} task-link", + title="In project '{{ task._project_info.name }}'", + href="{{ url_for('attract.tasks.perproject.view_task', project_url=task._project_info.url, task_id=task._id) }}") + span.status-indicator + span.name {{ task.name }} + | {% if include_shotname and task._parent_info %} + span.shotname {{ task._parent_info.name }} + | {% endif %} + span.type {{ task.properties.task_type }} + | {% endfor %} +| {%- endmacro %}