Révision d20d0549
Ajouté par Frédéric Péters il y a plus de 4 ans
auquotidien/auquotidien.py | ||
---|---|---|
6 | 6 |
|
7 | 7 |
from modules import admin |
8 | 8 |
from modules import backoffice |
9 |
from modules import links_ui |
|
10 | 9 |
from modules import announces_ui |
11 | 10 |
from modules import categories_admin |
12 | 11 |
from modules import events_ui |
... | ... | |
31 | 30 |
rdb.register_directory('announces', announces_ui.AnnouncesDirectory()) |
32 | 31 |
rdb.register_menu_item('announces/', _('Announces')) |
33 | 32 |
|
34 |
rdb.register_directory('links', links_ui.LinksDirectory()) |
|
35 |
rdb.register_menu_item('links/', _('Links')) |
|
36 |
|
|
37 | 33 |
rdb.register_directory('events', events_ui.EventsDirectory()) |
38 | 34 |
rdb.register_menu_item('events/', _('Events')) |
39 | 35 |
|
auquotidien/modules/admin.py | ||
---|---|---|
81 | 81 |
form.add(SingleSelectWidget, 'events', title = _('Admin role for events'), |
82 | 82 |
value = permissions_cfg.get('events', None), |
83 | 83 |
options = [(None, _('Nobody'), None)] + get_user_roles()) |
84 |
if get_publisher().has_site_option('auquotidien-links'): |
|
85 |
form.add(SingleSelectWidget, 'links', title = _('Admin role for links'), |
|
86 |
value = permissions_cfg.get('links', None), |
|
87 |
options = [(None, _('Nobody'), None)] + get_user_roles()) |
|
88 | 84 |
if get_publisher().has_site_option('auquotidien-announces'): |
89 | 85 |
form.add(SingleSelectWidget, 'announces', title = _('Admin role for announces'), |
90 | 86 |
value = permissions_cfg.get('announces', None), |
... | ... | |
113 | 109 |
else: |
114 | 110 |
from wcs.admin.settings import cfg_submit |
115 | 111 |
cfg_submit(form, 'aq-permissions', |
116 |
('forms', 'events', 'links', 'announces', 'payments', 'strongbox'))
|
|
112 |
('forms', 'events', 'announces', 'payments', 'strongbox')) |
|
117 | 113 |
return redirect('..') |
118 | 114 |
|
119 | 115 |
def event_keywords(self): |
... | ... | |
254 | 250 |
class SettingsDirectory(wcs.admin.settings.SettingsDirectory): |
255 | 251 |
def _q_index(self): |
256 | 252 |
if not (get_publisher().has_site_option('auquotidien-announces') or |
257 |
get_publisher().has_site_option('auquotidien-links') or |
|
258 | 253 |
get_publisher().has_site_option('auquotidien-events') or |
259 | 254 |
get_publisher().has_site_option('auquotidien-payments') or |
260 | 255 |
get_publisher().has_site_option('auquotidien-strongvox')): |
auquotidien/modules/links.py | ||
---|---|---|
1 |
from wcs.qommon.storage import StorableObject |
|
2 |
|
|
3 |
class Link(StorableObject): |
|
4 |
_names = 'links' |
|
5 |
|
|
6 |
title = None |
|
7 |
url = None |
|
8 |
position = None |
|
9 |
|
|
10 |
def sort_by_position(cls, links): |
|
11 |
def cmp_position(x, y): |
|
12 |
if x.position == y.position: |
|
13 |
return 0 |
|
14 |
if x.position is None: |
|
15 |
return 1 |
|
16 |
if y.position is None: |
|
17 |
return -1 |
|
18 |
return cmp(x.position, y.position) |
|
19 |
links.sort(cmp_position) |
|
20 |
sort_by_position = classmethod(sort_by_position) |
|
21 |
|
auquotidien/modules/links_ui.py | ||
---|---|---|
1 |
from quixote import get_request, get_response, get_session, redirect |
|
2 |
from quixote.directory import Directory, AccessControlled |
|
3 |
from quixote.html import TemplateIO, htmltext |
|
4 |
|
|
5 |
import wcs |
|
6 |
import wcs.admin.root |
|
7 |
|
|
8 |
from wcs.qommon import _ |
|
9 |
from wcs.qommon import errors |
|
10 |
from wcs.qommon.form import * |
|
11 |
from wcs.qommon.backoffice.menu import html_top |
|
12 |
from wcs.qommon.admin.menu import command_icon |
|
13 |
from wcs.qommon import get_cfg |
|
14 |
|
|
15 |
from .links import Link |
|
16 |
|
|
17 |
|
|
18 |
class LinkDirectory(Directory): |
|
19 |
_q_exports = ['', 'edit', 'delete'] |
|
20 |
|
|
21 |
def __init__(self, link): |
|
22 |
self.link = link |
|
23 |
|
|
24 |
def _q_index(self): |
|
25 |
form = Form(enctype='multipart/form-data') |
|
26 |
form.add_submit('edit', _('Edit')) |
|
27 |
form.add_submit('delete', _('Delete')) |
|
28 |
form.add_submit('back', _('Back')) |
|
29 |
|
|
30 |
if form.get_submit() == 'edit': |
|
31 |
return redirect('edit') |
|
32 |
if form.get_submit() == 'delete': |
|
33 |
return redirect('delete') |
|
34 |
if form.get_submit() == 'back': |
|
35 |
return redirect('..') |
|
36 |
|
|
37 |
html_top('links', title = _('Link: %s') % self.link.title) |
|
38 |
r = TemplateIO(html=True) |
|
39 |
r += htmltext('<h2>%s</h2>') % _('Link: %s') % self.link.title |
|
40 |
r += htmltext('<p>') |
|
41 |
r += self.link.url |
|
42 |
r += htmltext('</p>') |
|
43 |
|
|
44 |
r += form.render() |
|
45 |
return r.getvalue() |
|
46 |
|
|
47 |
def edit(self): |
|
48 |
form = self.form() |
|
49 |
if form.get_submit() == 'cancel': |
|
50 |
return redirect('.') |
|
51 |
|
|
52 |
if form.is_submitted() and not form.has_errors(): |
|
53 |
self.submit(form) |
|
54 |
return redirect('..') |
|
55 |
|
|
56 |
html_top('links', title = _('Edit Link: %s') % self.link.title) |
|
57 |
r = TemplateIO(html=True) |
|
58 |
r += htmltext('<h2>%s</h2>') % _('Edit Link: %s') % self.link.title |
|
59 |
r += form.render() |
|
60 |
return r.getvalue() |
|
61 |
|
|
62 |
|
|
63 |
def form(self): |
|
64 |
form = Form(enctype='multipart/form-data') |
|
65 |
form.add(StringWidget, 'title', title = _('Title'), required = True, |
|
66 |
value = self.link.title) |
|
67 |
form.add(StringWidget, 'url', title = _('URL'), required=False, |
|
68 |
value = self.link.url, |
|
69 |
hint=_('Leave empty to create a title')) |
|
70 |
form.add_submit('submit', _('Submit')) |
|
71 |
form.add_submit('cancel', _('Cancel')) |
|
72 |
return form |
|
73 |
|
|
74 |
def submit(self, form): |
|
75 |
for k in ('title', 'url'): |
|
76 |
widget = form.get_widget(k) |
|
77 |
if widget: |
|
78 |
setattr(self.link, k, widget.parse()) |
|
79 |
self.link.store() |
|
80 |
|
|
81 |
def delete(self): |
|
82 |
form = Form(enctype='multipart/form-data') |
|
83 |
form.widgets.append(HtmlWidget('<p>%s</p>' % _( |
|
84 |
'You are about to irrevocably delete this link.'))) |
|
85 |
form.add_submit('submit', _('Submit')) |
|
86 |
form.add_submit('cancel', _('Cancel')) |
|
87 |
if form.get_submit() == 'cancel': |
|
88 |
return redirect('..') |
|
89 |
if not form.is_submitted() or form.has_errors(): |
|
90 |
get_response().breadcrumb.append(('delete', _('Delete'))) |
|
91 |
html_top('links', title = _('Delete Link')) |
|
92 |
r = TemplateIO(html=True) |
|
93 |
r += htmltext('<h2>%s</h2>') % _('Deleting Link: %s') % self.link.title |
|
94 |
r += form.render() |
|
95 |
return r.getvalue() |
|
96 |
else: |
|
97 |
self.link.remove_self() |
|
98 |
return redirect('..') |
|
99 |
|
|
100 |
|
|
101 |
class LinksDirectory(AccessControlled, Directory): |
|
102 |
_q_exports = ['', 'new', 'listing', 'update_order'] |
|
103 |
label = N_('Links') |
|
104 |
|
|
105 |
def is_accessible(self, user): |
|
106 |
from .backoffice import check_visibility |
|
107 |
return check_visibility('links', user) |
|
108 |
|
|
109 |
def _q_access(self): |
|
110 |
user = get_request().user |
|
111 |
if not user: |
|
112 |
raise errors.AccessUnauthorizedError() |
|
113 |
|
|
114 |
if not self.is_accessible(user): |
|
115 |
raise errors.AccessForbiddenError( |
|
116 |
public_msg = _('You are not allowed to access Links Management'), |
|
117 |
location_hint = 'backoffice') |
|
118 |
|
|
119 |
get_response().breadcrumb.append(('links/', _('Links'))) |
|
120 |
|
|
121 |
|
|
122 |
def _q_index(self): |
|
123 |
html_top('links', _('Links')) |
|
124 |
r = TemplateIO(html=True) |
|
125 |
get_response().add_javascript(['jquery.js', 'jquery-ui.js', 'biglist.js']) |
|
126 |
get_response().filter['sidebar'] = self.get_sidebar() |
|
127 |
|
|
128 |
links = Link.select() |
|
129 |
Link.sort_by_position(links) |
|
130 |
|
|
131 |
r += htmltext('<ul class="biglist sortable" id="links-list">') |
|
132 |
for l in links: |
|
133 |
link_id = l.id |
|
134 |
r += htmltext('<li class="biglistitem" id="itemId_%s">') % link_id |
|
135 |
r += htmltext('<strong class="label"><a href="%s/">%s</a></strong>') % (link_id, l.title) |
|
136 |
r += htmltext('<p class="details">') |
|
137 |
r += l.url |
|
138 |
r += htmltext('</p>') |
|
139 |
r += htmltext('<p class="commands">') |
|
140 |
r += command_icon('%s/edit' % link_id, 'edit') |
|
141 |
r += command_icon('%s/delete' % link_id, 'remove') |
|
142 |
r += htmltext('</p></li>') |
|
143 |
r += htmltext('</ul>') |
|
144 |
return r.getvalue() |
|
145 |
|
|
146 |
def get_sidebar(self): |
|
147 |
r = TemplateIO(html=True) |
|
148 |
r += htmltext('<ul id="sidebar-actions">') |
|
149 |
r += htmltext(' <li><a class="new-item" href="new">%s</a></li>') % _('New Link') |
|
150 |
r += htmltext('</ul>') |
|
151 |
return r.getvalue() |
|
152 |
|
|
153 |
def update_order(self): |
|
154 |
request = get_request() |
|
155 |
new_order = request.form['order'].strip(';').split(';') |
|
156 |
links = Link.select() |
|
157 |
dict = {} |
|
158 |
for l in links: |
|
159 |
dict[str(l.id)] = l |
|
160 |
for i, o in enumerate(new_order): |
|
161 |
dict[o].position = i + 1 |
|
162 |
dict[o].store() |
|
163 |
return 'ok' |
|
164 |
|
|
165 |
|
|
166 |
def new(self): |
|
167 |
link_ui = LinkDirectory(Link()) |
|
168 |
|
|
169 |
form = link_ui.form() |
|
170 |
if form.get_submit() == 'cancel': |
|
171 |
return redirect('.') |
|
172 |
|
|
173 |
if form.is_submitted() and not form.has_errors(): |
|
174 |
link_ui.submit(form) |
|
175 |
return redirect('%s/' % link_ui.link.id) |
|
176 |
|
|
177 |
get_response().breadcrumb.append(('new', _('New Link'))) |
|
178 |
html_top('links', title = _('New Link')) |
|
179 |
r = TemplateIO(html=True) |
|
180 |
r += htmltext('<h2>%s</h2>') % _('New Link') |
|
181 |
r += form.render() |
|
182 |
return r.getvalue() |
|
183 |
|
|
184 |
def _q_lookup(self, component): |
|
185 |
try: |
|
186 |
link = Link.get(component) |
|
187 |
except KeyError: |
|
188 |
raise errors.TraversalError() |
|
189 |
get_response().breadcrumb.append((str(link.id), link.title)) |
|
190 |
return LinkDirectory(link) |
|
191 |
|
|
192 |
def listing(self): |
|
193 |
return redirect('.') |
|
194 |
|
auquotidien/modules/root.py | ||
---|---|---|
34 | 34 |
from wcs.qommon.admin.emails import EmailsDirectory |
35 | 35 |
from wcs.qommon.admin.texts import TextsDirectory |
36 | 36 |
|
37 |
from .links import Link |
|
38 | 37 |
from .announces import Announce, AnnounceSubscription |
39 | 38 |
from .myspace import MyspaceDirectory |
40 | 39 |
from .agenda import AgendaDirectory |
... | ... | |
781 | 780 |
preview = AlternatePreviewDirectory() |
782 | 781 |
|
783 | 782 |
def get_substitution_variables(self): |
784 |
d = {} |
|
785 |
def print_links(fd): |
|
786 |
fd.write(str(self.links())) |
|
787 |
d['links'] = print_links |
|
788 |
return d |
|
783 |
return {'links': ''} |
|
789 | 784 |
|
790 | 785 |
def _q_traverse(self, path): |
791 | 786 |
self.feed_substitution_parts() |
... | ... | |
1088 | 1083 |
r += htmltext('<input type="submit" value="%s"/>') % _('Load') |
1089 | 1084 |
r += htmltext('</form>') |
1090 | 1085 |
|
1091 |
if get_cfg('aq-permissions', {}).get('links'): |
|
1092 |
r += self.links() |
|
1093 |
|
|
1094 | 1086 |
cats = Category.select(order_by = 'name') |
1095 | 1087 |
cats = [x for x in cats if x.url_name != 'consultations' and x.get_homepage_position() == 'side'] |
1096 | 1088 |
Category.sort_by_position(cats) |
... | ... | |
1134 | 1126 |
def has_anonymous_access_codes(self): |
1135 | 1127 |
return any((x for x in FormDef.select() if x.enable_tracking_codes)) |
1136 | 1128 |
|
1137 |
def links(self): |
|
1138 |
links = Link.select() |
|
1139 |
if not links: |
|
1140 |
return '' |
|
1141 |
|
|
1142 |
Link.sort_by_position(links) |
|
1143 |
|
|
1144 |
r = TemplateIO(html=True) |
|
1145 |
|
|
1146 |
r += htmltext('<div id="links">') |
|
1147 |
if links[0].url: |
|
1148 |
# first link has an URL, so it's not a title, so we display a |
|
1149 |
# generic title |
|
1150 |
r += htmltext('<h3>%s</h3>') % _('Useful links') |
|
1151 |
has_ul = False |
|
1152 |
vars = get_publisher().substitutions.get_context_variables() |
|
1153 |
for link in links: |
|
1154 |
if not link.url: |
|
1155 |
# acting title |
|
1156 |
if has_ul: |
|
1157 |
r += htmltext('</ul>') |
|
1158 |
r += htmltext('<h3>%s</h3>') % link.title |
|
1159 |
r += htmltext('<ul>') |
|
1160 |
has_ul = True |
|
1161 |
else: |
|
1162 |
if not has_ul: |
|
1163 |
r += htmltext('<ul>') |
|
1164 |
has_ul = True |
|
1165 |
r += htmltext('<li class="link-%s"><a href="%s">%s</a></li>') % ( |
|
1166 |
simplify(link.title), get_variadic_url(link.url, vars), link.title) |
|
1167 |
if has_ul: |
|
1168 |
r += htmltext('</ul>') |
|
1169 |
r += htmltext('</div>') |
|
1170 |
return r.getvalue() |
|
1171 |
|
|
1172 | 1129 |
def announces(self): |
1173 | 1130 |
announces = Announce.get_published_announces() |
1174 | 1131 |
if not announces: |
Formats disponibles : Unified diff
remove support for custom links (#37967)