Merge branch 'production'

This commit is contained in:
2016-11-03 12:41:11 +01:00
5 changed files with 41 additions and 19 deletions

View File

@@ -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."""

View File

@@ -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'],
)

View File

@@ -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'

View File

@@ -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,

View File

@@ -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)