[f34308]: / ForgeDiscussion / forgediscussion / widgets / admin.py  Maximize  Restore  History

Download this file

68 lines (59 with data), 2.5 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
from pylons import c
from formencode import validators as fev
from formencode import All
import formencode
from bson import ObjectId
import ew as ew_core
import ew.jinja2_ew as ew
from allura.lib.widgets import forms as ff
from allura.lib.widgets import form_fields as ffw
from allura.lib import helpers as h
from forgediscussion import model as DM
class OptionsAdmin(ff.AdminForm):
defaults=dict(
ff.ForgeForm.defaults,
submit_text = 'Save')
@property
def fields(self):
fields = [
ew.SingleSelectField(
name='PostingPolicy',
label='Posting Policy',
options=[
ew.Option(py_value='ApproveOnceModerated', label='Approve Once Moderated'),
ew.Option(py_value='ApproveAll', label='Approve All')])
]
return fields
class AddForum(ff.AdminForm):
template = 'jinja:discussion_widgets/add_forum.html'
defaults=dict(
ff.ForgeForm.defaults,
name="add_forum",
value=None,
app=None,
submit_text = 'Save')
@property
def fields(self):
fields = [
ew.HiddenField(name='app_id', label='App'),
ew.TextField(name='name', label='Name'),
ew.TextField(name='shortname', label='Short Name',
validator=All(
fev.Regex(r"^[^\s\/\.]*$", not_empty=True, messages={
'invalid':'Shortname cannot contain space . or /',
'empty':'You must create a short name for the forum.'}),
UniqueForumShortnameValidator())),
ew.TextField(name='parent', label='Parent Forum'),
ew.TextField(name='description', label='Description',validator=fev.UnicodeString()),
ffw.FileChooser(name='icon', label='Icon')
]
return fields
class AddForumShort(AddForum):
template = 'jinja:discussion_widgets/add_forum_short.html'
class UniqueForumShortnameValidator(fev.FancyValidator):
def _to_python(self, value, state):
forums = DM.Forum.query.find(dict(app_config_id=ObjectId(state.full_dict['app_id']))).all()
value = h.really_unicode(value.lower() or '').encode('utf-8')
if value in [ f.shortname for f in forums ]:
raise formencode.Invalid('A forum already exists with that short name, please choose another.', value, state)
return value