Child: [bea16d] (diff)

Download this file

follow.py    43 lines (36 with data), 1.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from pylons import c
from formencode import validators as fev
import ew as ew_core
import ew.jinja2_ew as ew
class FollowToggle(ew.SimpleForm):
template='jinja:forgeactivity:templates/widgets/follow.html'
defaults=dict(
ew.SimpleForm.defaults,
thing='project',
action='follow',
action_label='watch',
icon='watch',
following=False)
class fields(ew_core.NameList):
follow = ew.HiddenField(validator=fev.StringBool())
def resources(self):
yield ew.JSLink('activity_js/follow.js')
def prepare_context(self, context):
default_context = super(FollowToggle, self).prepare_context({})
if c.project.is_user_project:
default_context.update(
thing=c.project.user_project_of.display_name,
action_label='follow',
icon='star',
)
else:
default_context.update(thing=c.project.name)
default_context.update(context)
return default_context
def success_message(self, following):
context = self.prepare_context({})
return u'You are {state} {action}ing {thing}.'.format(
state='now' if following else 'no longer',
action=context['action_label'],
thing=context['thing'],
)