From 464469f49665b9185615917f0aac82517d286fab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 3 Nov 2016 12:27:28 +0100 Subject: [PATCH 1/3] Linking comments works --- attract/__init__.py | 25 +++++++++++++++++++++++++ attract/comments/eve_hooks.py | 10 ++++++++++ attract/routes.py | 19 ++----------------- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/attract/__init__.py b/attract/__init__.py index 10430e7..afa336b 100644 --- a/attract/__init__.py +++ b/attract/__init__.py @@ -5,6 +5,7 @@ from werkzeug.local import LocalProxy from pillar.extension import PillarExtension import pillar.web.subquery from pillar.web.system_util import pillar_api +from pillar.web.nodes.routes import url_for_node import pillarsdk @@ -193,6 +194,30 @@ class AttractExtension(PillarExtension): return activities + def link_for_activity(self, act): + """Returns the URL for the activity. + + :type act: pillarsdk.Activity + """ + + from .node_types.task import node_type_task + from .node_types.shot import node_type_shot + + if act.node_type == node_type_task['name']: + if act.context_object: + return flask.url_for('attract.shots.perproject.with_task', + project_url=act.project.url, + task_id=act.object) + return flask.url_for('attract.tasks.perproject.view_task', + project_url=act.project.url, + task_id=act.object) + elif act.node_type == node_type_shot['name']: + return flask.url_for('attract.shots.perproject.view_shot', + project_url=act.project.url, + shot_id=act.object) + + return url_for_node(node_id=act.object) + def _get_current_attract(): """Returns the Attract extension of the current application.""" diff --git a/attract/comments/eve_hooks.py b/attract/comments/eve_hooks.py index c0b14ec..863d648 100644 --- a/attract/comments/eve_hooks.py +++ b/attract/comments/eve_hooks.py @@ -1,5 +1,7 @@ import logging +import flask + from pillar.api.nodes import only_for_node_type_decorator import pillar.api.activities import pillar.api.utils.authentication @@ -18,6 +20,13 @@ def activity_after_creating_node(comment): log.warning('Comment %s created without parent.' % comment_id) return + db = flask.current_app.db() + parent = db['nodes'].find_one({'_id': parent_id}, + projection={'node_type': 1}) + if not parent: + log.warning('Comment %s has non-existing parent %s' % (comment_id, parent_id)) + return + log.debug('Recording creation of comment as activity on node %s', parent_id) pillar.api.activities.register_activity( @@ -27,6 +36,7 @@ def activity_after_creating_node(comment): 'node', parent_id, project_id=comment.get('project', None), node_type=comment['node_type'], + context_node_type=parent['node_type'], ) diff --git a/attract/routes.py b/attract/routes.py index b7d6c4c..219c1a8 100644 --- a/attract/routes.py +++ b/attract/routes.py @@ -1,7 +1,7 @@ import functools import logging -from flask import Blueprint, render_template, url_for +from flask import Blueprint, render_template import flask_login from pillar.web.utils import attach_project_pictures @@ -50,25 +50,10 @@ def index(): }, api=api) # Fetch more info for each activity. - node_type_task_name = node_type_task['name'] - node_type_shot_name = node_type_shot['name'] for act in activities['_items']: act.actor_user = pillar.web.subquery.get_user_info(act.actor_user) act.project = id_to_proj[act.project] - - if act.node_type == node_type_task_name: - if act.context_object: - act.link = url_for('attract.shots.perproject.with_task', - project_url=act.project.url, - task_id=act.object) - else: - act.link = url_for('attract.tasks.perproject.view_task', - project_url=act.project.url, - task_id=act.object) - elif act.node_type == node_type_shot_name: - act.link = url_for('attract.shots.perproject.view_shot', - project_url=act.project.url, - shot_id=act.object) + act.link = current_attract.link_for_activity(act) return render_template('attract/index.html', tasks=tasks, From ff0951768e7815bb9f5ead1958a63bd3cf8286cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 3 Nov 2016 12:32:22 +0100 Subject: [PATCH 2/3] Fix for node finder --- attract/node_url_finders.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/attract/node_url_finders.py b/attract/node_url_finders.py index 5910ae0..456dd23 100644 --- a/attract/node_url_finders.py +++ b/attract/node_url_finders.py @@ -15,7 +15,9 @@ def find_for_shot(project, node): @register_node_finder(node_type_task['name']) def find_for_task(project, node): - if node['parent']: + + parent = node.get(u'parent') if isinstance(node, dict) else node.parent + if parent: endpoint = 'attract.shots.perproject.with_task' else: endpoint = 'attract.tasks.perproject.view_task' From 30e08126484143f0bdf5d4a9ec1ea42cca28f75f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 3 Nov 2016 12:33:37 +0100 Subject: [PATCH 3/3] Comments showing separately for shots too. --- src/templates/attract/shots/view_shot_embed.jade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/templates/attract/shots/view_shot_embed.jade b/src/templates/attract/shots/view_shot_embed.jade index cbc6fd4..20ffab9 100644 --- a/src/templates/attract/shots/view_shot_embed.jade +++ b/src/templates/attract/shots/view_shot_embed.jade @@ -117,7 +117,7 @@ script. var activities_url = "{{ url_for('.activities', project_url=project.url, shot_id=shot['_id']) }}"; loadActivities(activities_url); // from 10_tasks.js - loadComments("{{ url_for('nodes.commentform_for_node', node_id=shot['_id']) }}"); + loadComments("{{ url_for('nodes.comments_for_node', node_id=shot['_id']) }}"); $('body').on('pillar:comment-posted', function(e, comment_node_id) { loadActivities(activities_url)