Parent: [059b64] (diff)

Child: [87173e] (diff)

Download this file

forum_widgets.py    131 lines (112 with data), 4.9 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
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
from pylons import c
from formencode import validators as fev
import ew
from pyforge.lib import validators as V
from pyforge.lib.widgets import discuss as DW
from forgediscussion import model as M
class _ForumSummary(ew.Widget):
template='forgediscussion.widgets.templates.forum_summary'
params=['value', 'show_label', 'label', 'name']
name=None
value=None
show_label = True
label=None
class _ForumsTable(ew.TableField):
class hidden_fields(ew.WidgetsList):
_id=ew.HiddenField(validator=V.Ming(M.ForumThread))
class fields(ew.WidgetsList):
num_topics=ew.HTMLField(show_label=True, label='Topics')
num_posts=ew.HTMLField(show_label=True, label='Posts')
last_post=ew.HTMLField(text="${value and value.summary()}",
show_label=True)
subscribed=ew.Checkbox(suppress_label=True, show_label=True)
fields.insert(0, _ForumSummary())
class ForumSubscriptionForm(ew.SimpleForm):
class fields(ew.WidgetsList):
forums=_ForumsTable()
submit_text='Update Subscriptions'
class _ThreadsTable(DW._ThreadsTable):
class fields(ew.WidgetsList):
num_replies=ew.HTMLField(show_label=True, label='Num Replies')
num_views=ew.HTMLField(show_label=True)
flags=ew.HTMLField(show_label=True, text="${unicode(', '.join(value))}")
last_post=ew.HTMLField(text="${value and value.summary()}", show_label=True)
subscription=ew.Checkbox(suppress_label=True, show_label=True)
fields.insert(0, ew.LinkField(
label='Subject', text="${value['subject']}",
href="${value['url']()}", show_label=True))
class ThreadSubscriptionForm(DW.SubscriptionForm):
class fields(ew.WidgetsList):
threads=_ThreadsTable()
new_topic = DW.EditPost(submit_text='New Topic')
class AnnouncementsTable(DW._ThreadsTable):
class fields(ew.WidgetsList):
num_replies=ew.HTMLField(show_label=True, label='Num Replies')
num_views=ew.HTMLField(show_label=True)
flags=ew.HTMLField(show_label=True, text="${unicode(', '.join(value))}")
last_post=ew.HTMLField(text="${value and value.summary()}", show_label=True)
fields.insert(0, ew.LinkField(
label='Subject', text="${value['subject']}",
href="${value['url']()}", show_label=True))
name='announcements'
class _ForumSelector(ew.SingleSelectField):
def _options(self):
return [
ew.Option(label=f.name, py_value=f, html_value=f.shortname)
for f in c.app.forums ]
def to_python(self, value, state):
result = M.Forum.query.get(shortname=value)
if not result:
raise fev.Invalid('Illegal forum shortname: %s' % value, value, state)
return result
def from_python(self, value, state):
return value.shortname
class ModerateThread(ew.SimpleForm):
submit_text='Save Changes'
class fields(ew.WidgetsList):
forum=_ForumSelector(label='New Forum')
flags=ew.CheckboxSet(options=['Sticky', 'Announcement'])
class buttons(ew.WidgetsList):
delete=ew.SubmitButton(label='Delete Thread')
class ModeratePost(ew.SimpleForm):
submit_text=None
fields=[
ew.FieldSet(legend='Promote post to its own thread', fields=[
ew.TextField(name='subject', label='Thread title'),
ew.SubmitButton(name='promote', label='Promote to thread')])]
class PromoteToThread(ew.SimpleForm):
submit_text=None
fields=[
ew.TextField(name='subject', label='Thread title'),
ew.SubmitButton(name='promote', label='Promote to thread')]
class ForumHeader(DW.DiscussionHeader):
template='forgediscussion.widgets.templates.forum_header'
widgets=dict(DW.DiscussionHeader.widgets,
announcements_table=AnnouncementsTable(),
forum_subscription_form=ForumSubscriptionForm())
class ThreadHeader(DW.ThreadHeader):
template='forgediscussion.widgets.templates.thread_header'
show_subject=True
show_moderate=True
widgets=dict(DW.ThreadHeader.widgets,
moderate_thread=ModerateThread(),
announcements_table=AnnouncementsTable())
class Post(DW.Post):
show_subject=True
widgets=dict(DW.Post.widgets,
promote_to_thread=PromoteToThread())
class Thread(DW.Thread):
params=['show_subject']
show_subject=True
widgets=dict(DW.Thread.widgets,
thread_header=ThreadHeader(),
post=Post())
class Forum(DW.Discussion):
allow_create_thread=True
show_discussion_email = True
show_subject = True
widgets=dict(DW.Discussion.widgets,
discussion_header=ForumHeader(),
forum_subscription_form=ForumSubscriptionForm(),
subscription_form=ThreadSubscriptionForm()
)