Linking comments works
This commit is contained in:
@@ -5,6 +5,7 @@ from werkzeug.local import LocalProxy
|
|||||||
from pillar.extension import PillarExtension
|
from pillar.extension import PillarExtension
|
||||||
import pillar.web.subquery
|
import pillar.web.subquery
|
||||||
from pillar.web.system_util import pillar_api
|
from pillar.web.system_util import pillar_api
|
||||||
|
from pillar.web.nodes.routes import url_for_node
|
||||||
|
|
||||||
import pillarsdk
|
import pillarsdk
|
||||||
|
|
||||||
@@ -193,6 +194,30 @@ class AttractExtension(PillarExtension):
|
|||||||
|
|
||||||
return activities
|
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():
|
def _get_current_attract():
|
||||||
"""Returns the Attract extension of the current application."""
|
"""Returns the Attract extension of the current application."""
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import flask
|
||||||
|
|
||||||
from pillar.api.nodes import only_for_node_type_decorator
|
from pillar.api.nodes import only_for_node_type_decorator
|
||||||
import pillar.api.activities
|
import pillar.api.activities
|
||||||
import pillar.api.utils.authentication
|
import pillar.api.utils.authentication
|
||||||
@@ -18,6 +20,13 @@ def activity_after_creating_node(comment):
|
|||||||
log.warning('Comment %s created without parent.' % comment_id)
|
log.warning('Comment %s created without parent.' % comment_id)
|
||||||
return
|
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)
|
log.debug('Recording creation of comment as activity on node %s', parent_id)
|
||||||
|
|
||||||
pillar.api.activities.register_activity(
|
pillar.api.activities.register_activity(
|
||||||
@@ -27,6 +36,7 @@ def activity_after_creating_node(comment):
|
|||||||
'node', parent_id,
|
'node', parent_id,
|
||||||
project_id=comment.get('project', None),
|
project_id=comment.get('project', None),
|
||||||
node_type=comment['node_type'],
|
node_type=comment['node_type'],
|
||||||
|
context_node_type=parent['node_type'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import functools
|
import functools
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from flask import Blueprint, render_template, url_for
|
from flask import Blueprint, render_template
|
||||||
import flask_login
|
import flask_login
|
||||||
|
|
||||||
from pillar.web.utils import attach_project_pictures
|
from pillar.web.utils import attach_project_pictures
|
||||||
@@ -50,25 +50,10 @@ def index():
|
|||||||
}, api=api)
|
}, api=api)
|
||||||
|
|
||||||
# Fetch more info for each activity.
|
# 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']:
|
for act in activities['_items']:
|
||||||
act.actor_user = pillar.web.subquery.get_user_info(act.actor_user)
|
act.actor_user = pillar.web.subquery.get_user_info(act.actor_user)
|
||||||
act.project = id_to_proj[act.project]
|
act.project = id_to_proj[act.project]
|
||||||
|
act.link = current_attract.link_for_activity(act)
|
||||||
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)
|
|
||||||
|
|
||||||
return render_template('attract/index.html',
|
return render_template('attract/index.html',
|
||||||
tasks=tasks,
|
tasks=tasks,
|
||||||
|
Reference in New Issue
Block a user