remove support for announces (#37967)

This commit is contained in:
Frédéric Péters 2019-11-26 14:04:44 +01:00
parent 813372abb3
commit 741fa07466
11 changed files with 5 additions and 3181 deletions

View File

@ -6,7 +6,6 @@ from wcs.qommon.misc import get_cfg
from modules import admin
from modules import backoffice
from modules import announces_ui
from modules import categories_admin
from modules import payments_ui
from modules import strongbox_ui
@ -26,9 +25,6 @@ rdb = get_publisher_class().backoffice_directory_class
rdb.items = []
rdb.register_directory('announces', announces_ui.AnnouncesDirectory())
rdb.register_menu_item('announces/', _('Announces'))
rdb.register_directory('payments', payments_ui.PaymentsDirectory())
rdb.register_menu_item('payments/', _('Payments'))

View File

@ -22,8 +22,8 @@ from .abelium_domino_ui import AbeliumDominoDirectory
class PanelDirectory(Directory):
_q_exports = ['', 'update', 'announces', 'permissions',
'announce_themes', 'strongbox', 'domino']
_q_exports = ['', 'update', 'permissions',
'strongbox', 'domino']
label = N_('Control Panel')
domino = AbeliumDominoDirectory()
@ -37,49 +37,12 @@ class PanelDirectory(Directory):
if string_value:
form.get_widget('mobile_mask').value = string_value.upper()
def announces(self):
announces_cfg = get_cfg('announces', {})
sms_cfg = get_cfg('sms', {})
form = Form(enctype='multipart/form-data')
hint = ""
if sms_cfg.get('mode','') in ("none",""):
hint = htmltext(_('You must also <a href="%s">configure your SMS provider</a>') % "../settings/sms")
form.add(CheckboxWidget, 'sms_support', title = _('SMS support'),
hint = hint, value = announces_cfg.get('sms_support', 0))
form.add(StringWidget, 'mobile_mask', title = _('Mask for mobile numbers'),
hint = _('example: 06XXXXXXXX'),
value = announces_cfg.get('mobile_mask',''))
form.add_submit('submit', _('Submit'))
form.add_submit('cancel', _('Cancel'))
self._verify_mask(form)
if form.get_widget('cancel').parse():
return redirect('..')
if not form.is_submitted() or form.has_errors():
get_response().breadcrumb.append(('aq/announces', _('Announces Options')))
html_top('settings', _('Announces Options'))
r = TemplateIO(html=True)
r += htmltext('<h2>%s</h2>') % _('Announces Options')
r += form.render()
return r.getvalue()
else:
from wcs.admin.settings import cfg_submit
cfg_submit(form, 'announces', ('sms_support','mobile_mask'))
return redirect('..')
def permissions(self):
permissions_cfg = get_cfg('aq-permissions', {})
form = Form(enctype='multipart/form-data')
form.add(SingleSelectWidget, 'forms', title = _('Admin role for forms'),
value = permissions_cfg.get('forms', None),
options = [(None, _('Nobody'), None)] + get_user_roles())
if get_publisher().has_site_option('auquotidien-announces'):
form.add(SingleSelectWidget, 'announces', title = _('Admin role for announces'),
value = permissions_cfg.get('announces', None),
options = [(None, _('Nobody'), None)] + get_user_roles())
if get_publisher().has_site_option('auquotidien-payments'):
form.add(SingleSelectWidget, 'payments', title = _('Admin role for payments'),
value = permissions_cfg.get('payments', None),
@ -104,34 +67,7 @@ class PanelDirectory(Directory):
else:
from wcs.admin.settings import cfg_submit
cfg_submit(form, 'aq-permissions',
('forms', 'announces', 'payments', 'strongbox'))
return redirect('..')
def announce_themes(self):
misc_cfg = get_cfg('misc', {})
form = Form(enctype='multipart/form-data')
form.add(WidgetList, 'announce_themes', title = _('Announce Themes'),
value = misc_cfg.get('announce_themes', []),
elemnt_type = StringWidget,
add_element_label = _('Add Theme'),
element_kwargs = {str('render_br'): False, str('size'): 30})
form.add_submit('submit', _('Submit'))
form.add_submit('cancel', _('Cancel'))
if form.get_widget('cancel').parse():
return redirect('..')
if not form.is_submitted() or form.has_errors():
get_response().breadcrumb.append(('aq/announce_themes', _('Announce Themes')))
html_top('settings', _('Announce Themes'))
r = TemplateIO(html=True)
r += htmltext('<h2>%s</h2>') % _('Announce Themes')
r += form.render()
return r.getvalue()
else:
from wcs.admin.settings import cfg_submit
cfg_submit(form, 'misc', ('announce_themes',))
('forms', 'payments', 'strongbox'))
return redirect('..')
def strongbox(self):
@ -163,8 +99,7 @@ class PanelDirectory(Directory):
class SettingsDirectory(wcs.admin.settings.SettingsDirectory):
def _q_index(self):
if not (get_publisher().has_site_option('auquotidien-announces') or
get_publisher().has_site_option('auquotidien-payments') or
if not (get_publisher().has_site_option('auquotidien-payments') or
get_publisher().has_site_option('auquotidien-strongvox')):
return super(SettingsDirectory, self)._q_index()
r = TemplateIO(html=True)
@ -173,11 +108,7 @@ class SettingsDirectory(wcs.admin.settings.SettingsDirectory):
r += htmltext('<div class="bo-block">')
r += htmltext('<h2>%s</h2>') % _('Extra Options')
r += htmltext('<ul>')
if get_publisher().has_site_option('auquotidien-announces'):
r += htmltext('<li><a href="aq/announces">%s</a></li>') % _('Announces Options')
r += htmltext('<li><a href="aq/permissions">%s</a></li>') % _('Permissions')
if get_publisher().has_site_option('auquotidien-announces'):
r += htmltext('<li><a href="aq/announce_themes">%s</a></li>') % _('Announce Themes')
if get_publisher().has_site_option('strongbox'):
r += htmltext('<li><a href="aq/strongbox">%s</a></li>') % _('Strongbox Support')
if get_publisher().has_site_option('domino'):

View File

@ -1,182 +0,0 @@
import time
from quixote import get_publisher
from quixote.html import htmlescape
from wcs.qommon import _
from wcs.qommon.storage import StorableObject
from wcs.qommon import get_cfg, get_logger
from wcs.qommon import errors
from wcs.qommon import misc
from wcs.qommon import emails
from wcs.qommon.sms import SMS
from wcs.qommon.admin.emails import EmailsDirectory
class AnnounceSubscription(StorableObject):
_names = 'announce-subscriptions'
_indexes = ['user_id']
user_id = None
email = None
sms = None
enabled = True
enabled_sms = False
enabled_themes = None
def remove(self, type=None):
""" type (string) : email or sms """
if type == "email":
self.email = None
elif type == "sms":
self.sms = None
self.enabled_sms = False
if not type or (not self.sms and not self.email):
self.remove_self()
else:
self.store()
def get_user(self):
if self.user_id:
try:
return get_publisher().user_class.get(self.user_id)
except KeyError:
return None
return None
user = property(get_user)
class Announce(StorableObject):
_names = 'announces'
title = None
text = None
hidden = False
publication_time = None
modification_time = None
expiration_time = None
sent_by_email_time = None
sent_by_sms_time = None
theme = None
position = None
def sort_by_position(cls, links):
def cmp_position(x, y):
if x.position == y.position:
return 0
if x.position is None:
return 1
if y.position is None:
return -1
return cmp(x.position, y.position)
links.sort(cmp_position)
sort_by_position = classmethod(sort_by_position)
def get_atom_entry(self):
from pyatom import pyatom
entry = pyatom.Entry()
entry.id = self.get_url()
entry.title = self.title
entry.content.attrs['type'] = 'html'
entry.content.text = str('<p>' + htmlescape(
unicode(self.text, get_publisher().site_charset).encode('utf-8')) + '</p>')
link = pyatom.Link(self.get_url())
entry.links.append(link)
if self.publication_time:
entry.published = misc.format_time(self.publication_time,
'%(year)s-%(month)02d-%(day)02dT%(hour)02d:%(minute)02d:%(second)02dZ',
gmtime = True)
if self.modification_time:
entry.updated = misc.format_time(self.modification_time,
'%(year)s-%(month)02d-%(day)02dT%(hour)02d:%(minute)02d:%(second)02dZ',
gmtime = True)
return entry
def get_url(self):
return '%s/announces/%s/' % (get_publisher().get_frontoffice_url(), self.id)
def store(self):
self.modification_time = time.gmtime()
StorableObject.store(self)
def email(self, job=None):
self.sent_by_email_time = time.gmtime()
StorableObject.store(self)
data = {
'title': self.title,
'text': self.text
}
subscribers = AnnounceSubscription.select(lambda x: x.enabled)
rcpts = []
for l in subscribers:
if self.theme:
if l.enabled_themes is not None:
if self.theme not in l.enabled_themes:
continue
if l.user and l.user.email:
rcpts.append(l.user.email)
elif l.email:
rcpts.append(l.email)
emails.custom_template_email('aq-announce', data, email_rcpt=rcpts, hide_recipients=True)
def sms(self, job=None):
self.sent_by_sms_time = time.gmtime()
StorableObject.store(self)
subscribers = AnnounceSubscription.select(lambda x: x.enabled_sms)
rcpts = []
for sub in subscribers:
if self.theme:
if sub.enabled_themes is not None:
if self.theme not in sub.enabled_themes:
continue
if sub.sms:
rcpts.append(sub.sms)
sms_cfg = get_cfg('sms', {})
sender = sms_cfg.get('sender', 'AuQuotidien')[:11]
message = "%s: %s" % (self.title, self.text)
mode = sms_cfg.get('mode', 'none')
sms = SMS.get_sms_class(mode)
try:
sms.send(sender, rcpts, message[:160])
except errors.SMSError, e:
get_logger().error(e)
def get_published_announces(cls):
announces = cls.select(lambda x: not x.hidden)
announces.sort(lambda x,y: cmp(x.publication_time or x.modification_time,
y.publication_time or y.modification_time))
announces = [x for x in announces if x.publication_time < time.gmtime()
and (x.expiration_time is None or x.expiration_time > time.gmtime())]
announces.reverse()
return announces
get_published_announces = classmethod(get_published_announces)
EmailsDirectory.register('aq-announce',
N_('Publication of announce to subscriber'),
N_('Available variables: title, text'),
default_subject = N_('Announce: [title]'),
default_body = N_("""\
[text]
--
This is an announce sent to you by your city, you can opt to not receive
those messages anymore on the city website.
"""))

View File

@ -1,459 +0,0 @@
from quixote import get_request, get_response, get_session, redirect
from quixote.directory import Directory, AccessControlled
from quixote.html import htmltext, TemplateIO
import wcs
from wcs.qommon import _
from wcs.qommon.backoffice.menu import html_top
from wcs.qommon.admin.menu import command_icon
from wcs.qommon import get_cfg
from wcs.qommon import errors
from wcs.qommon.form import *
from wcs.qommon.afterjobs import AfterJob
from .announces import Announce, AnnounceSubscription
class SubscriptionDirectory(Directory):
_q_exports = ['delete_email', "delete_sms"]
def __init__(self, subscription):
self.subscription = subscription
def delete_email(self):
form = Form(enctype='multipart/form-data')
form.widgets.append(HtmlWidget('<p>%s</p>' % _(
'You are about to delete this subscription.')))
form.add_submit('submit', _('Submit'))
form.add_submit('cancel', _('Cancel'))
if form.get_submit() == 'cancel':
return redirect('..')
if not form.is_submitted() or form.has_errors():
get_response().breadcrumb.append(('delete', _('Delete')))
html_top('announces', title = _('Delete Subscription'))
r = TemplateIO(html=True)
r += htmltext('<h2>%s</h2>') % _('Deleting Subscription')
r += form.render()
return r.getvalue()
else:
self.subscription.remove("email")
return redirect('..')
def delete_sms(self):
form = Form(enctype='multipart/form-data')
form.widgets.append(HtmlWidget('<p>%s</p>' % _(
'You are about to delete this subscription.')))
form.add_submit('submit', _('Submit'))
form.add_submit('cancel', _('Cancel'))
if form.get_submit() == 'cancel':
return redirect('..')
if not form.is_submitted() or form.has_errors():
get_response().breadcrumb.append(('delete', _('Delete')))
html_top('announces', title = _('Delete Subscription'))
r = TemplateIO(html=True)
r += htmltext('<h2>%s</h2>') % _('Deleting Subscription')
r += form.render()
return r.getvalue()
else:
self.subscription.remove("sms")
return redirect('..')
class SubscriptionsDirectory(Directory):
_q_exports = ['']
def _q_traverse(self, path):
get_response().breadcrumb.append(('subscriptions', _('Subscriptions')))
return Directory._q_traverse(self, path)
def _q_index(self):
html_top('announces', _('Announces Subscribers'))
r = TemplateIO(html=True)
r += htmltext('<h2>%s</h2>') % _('Announces Subscribers')
subscribers = AnnounceSubscription.select()
r += htmltext('<ul class="biglist" id="subscribers-list">')
for l in subscribers:
if l.email:
if l.enabled is False:
r += htmltext('<li class="disabled">')
else:
r += htmltext('<li>')
r += htmltext('<strong class="label">')
if l.user:
r += l.user.display_name
elif l.email:
r += l.email
r += htmltext('</strong>')
r += htmltext('<p class="details">')
if l.user:
r += l.user.email
r += htmltext('</p>')
r += htmltext('<p class="commands">')
r += command_icon('%s/delete_email' % l.id, 'remove', popup = True)
r += htmltext('</p></li>')
r += htmltext('</li>')
if l.sms:
if l.enabled_sms is False:
r += htmltext('<li class="disabled">')
else:
r += htmltext('<li>')
r += htmltext('<strong class="label">')
if l.user:
r += l.user.display_name
elif l.email:
r += l.email
r += htmltext('</strong>')
r += htmltext('<p class="details">')
r += l.sms
r += htmltext('</p>')
r += htmltext('<p class="commands">')
r += command_icon('%s/delete_sms' % l.id, 'remove', popup = True)
r += htmltext('</p></li>')
r += htmltext('</li>')
r += htmltext('</ul>')
return r.getvalue()
def _q_lookup(self, component):
try:
sub = AnnounceSubscription.get(component)
except KeyError:
raise errors.TraversalError()
get_response().breadcrumb.append((str(sub.id), str(sub.id)))
return SubscriptionDirectory(sub)
def listing(self):
return redirect('.')
class AnnounceDirectory(Directory):
_q_exports = ['', 'edit', 'delete', 'email', 'sms']
def __init__(self, announce):
self.announce = announce
def _q_index(self):
form = Form(enctype='multipart/form-data')
get_response().filter['sidebar'] = self.get_sidebar()
if self.announce.sent_by_email_time is None:
form.add_submit('email', _('Send email'))
announces_cfg = get_cfg('announces', {})
if announces_cfg.get('sms_support', 0) and self.announce.sent_by_sms_time is None:
form.add_submit('sms', _('Send SMS'))
if form.get_submit() == 'edit':
return redirect('edit')
if form.get_submit() == 'delete':
return redirect('delete')
if form.get_submit() == 'email':
return redirect('email')
if form.get_submit() == 'sms':
return redirect('sms')
html_top('announces', title = _('Announce: %s') % self.announce.title)
r = TemplateIO(html=True)
r += htmltext('<h2>%s</h2>') % _('Announce: %s') % self.announce.title
r += htmltext('<div class="bo-block">')
r += htmltext('<p>')
r += self.announce.text
r += htmltext('</p>')
r += htmltext('</div>')
if form.get_submit_widgets():
r += form.render()
return r.getvalue()
def get_sidebar(self):
r = TemplateIO(html=True)
r += htmltext('<ul>')
r += htmltext('<li><a href="edit">%s</a></li>') % _('Edit')
r += htmltext('<li><a href="delete">%s</a></li>') % _('Delete')
r += htmltext('</ul>')
return r.getvalue()
def email(self):
if get_request().form.get('job'):
try:
job = AfterJob.get(get_request().form.get('job'))
except KeyError:
return redirect('..')
html_top('announces', title = _('Announce: %s') % self.announce.title)
r = TemplateIO(html=True)
get_response().add_javascript(['jquery.js', 'afterjob.js'])
r += htmltext('<dl class="job-status">')
r += htmltext('<dt>')
r += _(job.label)
r += htmltext('</dt>')
r += htmltext('<dd>')
r += htmltext('<span class="afterjob" id="%s">') % job.id
r += _(job.status)
r += htmltext('</span>')
r += htmltext('</dd>')
r += htmltext('</dl>')
r += htmltext('<div class="done">')
r += htmltext('<a href="../">%s</a>') % _('Back')
r += htmltext('</div>')
return r.getvalue()
else:
job = get_response().add_after_job(
str(N_('Sending emails for announce')),
self.announce.email)
return redirect('email?job=%s' % job.id)
def sms(self):
if get_request().form.get('job'):
try:
job = AfterJob.get(get_request().form.get('job'))
except KeyError:
return redirect('..')
html_top('announces', title = _('Announce: %s') % self.announce.title)
get_response().add_javascript(['jquery.js', 'afterjob.js'])
r = TemplateIO(html=True)
r += htmltext('<dl class="job-status">')
r += htmltext('<dt>')
r += _(job.label)
r += htmltext('</dt>')
r += htmltext('<dd>')
r += htmltext('<span class="afterjob" id="%s">') % job.id
r += _(job.status)
r += htmltext('</span>')
r += htmltext('</dd>')
r += htmltext('</dl>')
r += htmltext('<div class="done">')
r += htmltext('<a href="../">%s</a>') % _('Back')
r += htmltext('</div>')
return r.getvalue()
else:
job = get_response().add_after_job(
str(N_('Sending sms for announce')),
self.announce.sms)
return redirect('sms?job=%s' % job.id)
def edit(self):
form = self.form()
if form.get_submit() == 'cancel':
return redirect('.')
if form.is_submitted() and not form.has_errors():
self.submit(form)
return redirect('..')
html_top('announces', title = _('Edit Announce: %s') % self.announce.title)
r = TemplateIO(html=True)
r += htmltext('<h2>%s</h2>') % _('Edit Announce: %s') % self.announce.title
r += form.render()
return r.getvalue()
def form(self):
form = Form(enctype='multipart/form-data')
form.add(StringWidget, 'title', title = _('Title'), required = True,
value = self.announce.title)
if self.announce.publication_time:
pub_time = time.strftime(misc.date_format(), self.announce.publication_time)
else:
pub_time = None
form.add(DateWidget, 'publication_time', title = _('Publication Time'),
value = pub_time)
if self.announce.expiration_time:
exp_time = time.strftime(misc.date_format(), self.announce.expiration_time)
else:
exp_time = None
form.add(DateWidget, 'expiration_time', title = _('Expiration Time'),
value = exp_time)
form.add(TextWidget, 'text', title = _('Text'), required = True,
value = self.announce.text, rows = 10, cols = 70)
if get_cfg('misc', {}).get('announce_themes'):
form.add(SingleSelectWidget, 'theme', title = _('Announce Theme'),
value = self.announce.theme,
options = get_cfg('misc', {}).get('announce_themes'))
form.add(CheckboxWidget, 'hidden', title = _('Hidden'),
value = self.announce.hidden)
form.add_submit('submit', _('Submit'))
form.add_submit('cancel', _('Cancel'))
return form
def submit(self, form):
for k in ('title', 'text', 'hidden', 'theme'):
widget = form.get_widget(k)
if widget:
setattr(self.announce, k, widget.parse())
for k in ('publication_time', 'expiration_time'):
widget = form.get_widget(k)
if widget:
wid_time = widget.parse()
if wid_time:
setattr(self.announce, k, time.strptime(wid_time, misc.date_format()))
else:
setattr(self.announce, k, None)
self.announce.store()
def delete(self):
form = Form(enctype='multipart/form-data')
form.widgets.append(HtmlWidget('<p>%s</p>' % _(
'You are about to irrevocably delete this announce.')))
form.add_submit('submit', _('Submit'))
form.add_submit('cancel', _('Cancel'))
if form.get_submit() == 'cancel':
return redirect('..')
if not form.is_submitted() or form.has_errors():
get_response().breadcrumb.append(('delete', _('Delete')))
html_top('announces', title = _('Delete Announce'))
r = TemplateIO(html=True)
r += htmltext('<h2>%s</h2>') % _('Deleting Announce: %s') % self.announce.title
r += form.render()
return r.getvalue()
else:
self.announce.remove_self()
return redirect('..')
class AnnouncesDirectory(AccessControlled, Directory):
_q_exports = ['', 'new', 'listing', 'subscriptions', 'update_order', 'log']
label = N_('Announces')
subscriptions = SubscriptionsDirectory()
def is_accessible(self, user):
from .backoffice import check_visibility
return check_visibility('announces', user)
def _q_access(self):
user = get_request().user
if not user:
raise errors.AccessUnauthorizedError()
if not self.is_accessible(user):
raise errors.AccessForbiddenError(
public_msg = _('You are not allowed to access Announces Management'),
location_hint = 'backoffice')
get_response().breadcrumb.append(('announces/', _('Announces')))
def _q_index(self):
html_top('announces', _('Announces'))
r = TemplateIO(html=True)
get_response().filter['sidebar'] = self.get_sidebar()
announces = Announce.select()
announces.sort(lambda x,y: cmp(x.publication_time or x.modification_time,
y.publication_time or y.modification_time))
announces.reverse()
r += htmltext('<ul class="biglist" id="announces-list">')
for l in announces:
announce_id = l.id
if l.hidden:
r += htmltext('<li class="disabled" class="biglistitem" id="itemId_%s">') % announce_id
else:
r += htmltext('<li class="biglistitem" id="itemId_%s">') % announce_id
r += htmltext('<strong class="label"><a href="%s/">%s</a></strong>') % (l.id, l.title)
if l.publication_time:
r += htmltext('<p class="details">')
r += time.strftime(misc.date_format(), l.publication_time)
r += htmltext('</p>')
r += htmltext('</li>')
r += htmltext('</ul>')
return r.getvalue()
def get_sidebar(self):
r = TemplateIO(html=True)
r += htmltext('<ul id="sidebar-actions">')
r += htmltext(' <li><a class="new-item" href="new">%s</a></li>') % _('New')
r += htmltext(' <li><a href="subscriptions/">%s</a></li>') % _('Subscriptions')
r += htmltext(' <li><a href="log">%s</a></li>') % _('Log')
r += htmltext('</ul>')
return r.getvalue()
def log(self):
announces = Announce.select()
log = []
for l in announces:
if l.publication_time:
log.append((l.publication_time, _('Publication'), l))
if l.sent_by_email_time:
log.append((l.sent_by_email_time, _('Email'), l))
if l.sent_by_sms_time:
log.append((l.sent_by_sms_time, _('SMS'), l))
log.sort()
get_response().breadcrumb.append(('log', _('Log')))
html_top('announces', title = _('Log'))
r = TemplateIO(html=True)
r += htmltext('<table>')
r += htmltext('<thead>')
r += htmltext('<tr>')
r += htmltext('<th>%s</th>') % _('Time')
r += htmltext('<th>%s</th>') % _('Type')
r += htmltext('<td></td>')
r += htmltext('</tr>')
r += htmltext('</thead>')
r += htmltext('<tbody>')
for log_time, log_type, log_announce in log:
r += htmltext('<tr>')
r += htmltext('<td>')
r += misc.localstrftime(log_time)
r += htmltext('</td>')
r += htmltext('<td>')
r += log_type
r += htmltext('</td>')
r += htmltext('<td>')
r += htmltext('<a href="%s">%s</a>') % (log_announce.id, log_announce.title)
r += htmltext('</td>')
r += htmltext('</tr>')
r += htmltext('</tbody>')
r += htmltext('</table>')
return r.getvalue()
def update_order(self):
request = get_request()
new_order = request.form['order'].strip(';').split(';')
announces = Announce.select()
dict = {}
for l in announces:
dict[str(l.id)] = l
for i, o in enumerate(new_order):
dict[o].position = i + 1
dict[o].store()
return 'ok'
def new(self):
announce = Announce()
announce.publication_time = time.gmtime()
announce_ui = AnnounceDirectory(announce)
form = announce_ui.form()
if form.get_submit() == 'cancel':
return redirect('.')
if form.is_submitted() and not form.has_errors():
announce_ui.submit(form)
return redirect('%s/' % announce_ui.announce.id)
get_response().breadcrumb.append(('new', _('New Announce')))
html_top('announces', title = _('New Announce'))
r = TemplateIO(html=True)
r += htmltext('<h2>%s</h2>') % _('New Announce')
r += form.render()
return r.getvalue()
def _q_lookup(self, component):
try:
announce = Announce.get(component)
except KeyError:
raise errors.TraversalError()
get_response().breadcrumb.append((str(announce.id), announce.title))
return AnnounceDirectory(announce)
def listing(self):
return redirect('.')

View File

@ -25,7 +25,6 @@ from wcs.qommon.admin.texts import TextsDirectory
from wcs.formdef import FormDef
import wcs.myspace
from .announces import AnnounceSubscription
from .strongbox import StrongboxItem, StrongboxType
from .payments import Invoice, Regie, is_payment_supported
@ -411,7 +410,7 @@ class JsonDirectory(Directory):
class MyspaceDirectory(wcs.myspace.MyspaceDirectory):
_q_exports = ['', 'profile', 'new', 'password', 'remove', 'drafts', 'forms',
'announces', 'strongbox', 'invoices', 'json']
'strongbox', 'invoices', 'json']
strongbox = StrongboxDirectory()
invoices = MyInvoicesDirectory()
@ -492,17 +491,6 @@ class MyspaceDirectory(wcs.myspace.MyspaceDirectory):
r += htmltext(' <strong><a href="remove" rel="popup">%s</a></strong>.') % _('Delete My Account')
r += htmltext('</p>')
options = get_cfg('misc', {}).get('announce_themes')
if options:
try:
subscription = AnnounceSubscription.get_on_index(
get_request().user.id, str('user_id'))
except KeyError:
pass
else:
r += htmltext('<p class="command"><a href="announces">%s</a></p>') % _(
'Edit my Subscription to Announces')
if user_forms:
r += htmltext('<h3 id="my-forms">%s</h3>') % _('My Forms')
from . import root
@ -675,45 +663,6 @@ class MyspaceDirectory(wcs.myspace.MyspaceDirectory):
template.html_top(_('Removing Account'))
return form.render()
def announces(self):
options = get_cfg('misc', {}).get('announce_themes')
if not options:
raise errors.TraversalError()
user = get_request().user
if not user or user.anonymous:
raise errors.AccessUnauthorizedError()
subscription = AnnounceSubscription.get_on_index(get_request().user.id, str('user_id'))
if not subscription:
raise errors.TraversalError()
if subscription.enabled_themes is None:
enabled_themes = options
else:
enabled_themes = subscription.enabled_themes
form = Form(enctype = 'multipart/form-data')
form.add(CheckboxesWidget, 'themes', title=_('Announce Themes'),
value=enabled_themes, options=[(x, x, x) for x in options],
inline=False, required=False)
form.add_submit('submit', _('Apply Changes'))
form.add_submit('cancel', _('Cancel'))
if form.get_submit() == 'cancel':
return redirect('.')
if form.is_submitted() and not form.has_errors():
chosen_themes = form.get_widget('themes').parse()
if chosen_themes == options:
chosen_themes = None
subscription.enabled_themes = chosen_themes
subscription.store()
return redirect('.')
template.html_top()
get_response().breadcrumb.append(('announces', _('Announce Subscription')))
return form.render()
TextsDirectory.register('aq-myspace-invoice',
N_('Message on top of invoices page'),

View File

@ -1,54 +0,0 @@
# Larry Rosen has ceased to use or recommend any version
# of the Academic Free License below version 2.1
The Academic Free License
v. 2.1
This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following notice immediately following the copyright notice for the Original Work:
Licensed under the Academic Free License version 2.1
1) Grant of Copyright License. Licensor hereby grants You a world-wide, royalty-free, non-exclusive, perpetual, sublicenseable license to do the following:
a) to reproduce the Original Work in copies;
b) to prepare derivative works ("Derivative Works") based upon the Original Work;
c) to distribute copies of the Original Work and Derivative Works to the public;
d) to perform the Original Work publicly; and
e) to display the Original Work publicly.
2) Grant of Patent License. Licensor hereby grants You a world-wide, royalty-free, non-exclusive, perpetual, sublicenseable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, to make, use, sell and offer for sale the Original Work and Derivative Works.
3) Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor hereby agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work, and by publishing the address of that information repository in a notice immediately following the copyright notice that applies to the Original Work.
4) Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior written permission of the Licensor. Nothing in this License shall be deemed to grant any rights to trademarks, copyrights, patents, trade secrets or any other intellectual property of Licensor except as expressly stated herein. No patent license is granted to make, use, sell or offer to sell embodiments of any patent claims other than the licensed claims defined in Section 2. No right is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under different terms from this License any Original Work that Licensor otherwise would have a right to license.
5) This section intentionally omitted.
6) Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work.
7) Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately proceeding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to Original Work is granted hereunder except under this disclaimer.
8) Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to any person for any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to liability for death or personal injury resulting from Licensor's negligence to the extent applicable law prohibits such limitation. Some jurisdictions do not allow the exclusion or limitation of incidental or consequential damages, so this exclusion and limitation may not apply to You.
9) Acceptance and Termination. If You distribute copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. Nothing else but this License (or another written agreement between Licensor and You) grants You permission to create Derivative Works based upon the Original Work or to exercise any of the rights granted in Section 1 herein, and any attempt to do so except under the terms of this License (or another written agreement between Licensor and You) is expressly prohibited by U.S. copyright law, the equivalent laws of other countries, and by international treaty. Therefore, by exercising any of the rights granted to You in Section 1 herein, You indicate Your acceptance of this License and all of its terms and conditions.
10) Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware.
11) Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of the U.S. Copyright Act, 17 U.S.C. § 101 et seq., the equivalent laws of other countries, and international treaty. This section shall survive the termination of this License.
12) Attorneys Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License.
13) Miscellaneous. This License represents the complete agreement concerning the subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable.
14) Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
15) Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You.
This license is Copyright (C) 2003-2004 Lawrence E. Rosen. All rights reserved. Permission is hereby granted to copy and distribute this license without modification. This license may not be modified without the express written permission of its copyright owner.

File diff suppressed because it is too large Load Diff

View File

@ -1,64 +0,0 @@
PyAtom
PyAtom is a Python library module I wrote to make it very easy to create
an Atom syndication feed.
http://atomenabled.org/developers/syndication/
I have released PyAtom under The Academic Free License 2.1. I intend to
donate PyAtom to the Python Software Foundation.
Notes on PyAtom:
XML is best represented in a tree structure, and PyAtom is a set of
classes that automatically manage the tree structure for the user. The
top level of an Atom feed is an XML "Feed" element with a "<feed>" tag;
the Feed element has other elements nested inside it that describe the
feed, and then it has 0 or more Entry elements, each of which has
elements that describe the Entry.
Take a look at RunPyAtomTestCases(), at the end of pyatom.py, for
example code showing how to set up a feed with an entry.
To create an XML document with a feed in it, the user does this:
xmldoc = XMLDoc()
feed = Feed()
xmldoc.root_element = feed
To assign an entry to a feed, the user just does this:
feed.entries.append(entry)
This adds "entry" to the internal list that keeps track of entries.
"entry" is now nested inside "feed", which is nested inside "xmldoc".
Later, when the user wants to save the XML in a file, the user can just
do this:
f = open("file.xml", "w")
s = str(xmldoc)
f.write(s)
To make the string from xmldoc, the XMLDoc class walks through the XML
elements nested inside xmldoc, asking each one to return its string.
Each element that has other elements nested inside does the same thing.
The whole tree is recursively walked, and the tags all return strings
that are indented properly for their level in the tree.
The classes that implement Atom in PyAtom just use the heck out of
inheritance. There are abstract base classes that implement broadly
useful behavior, and lots of classes that just inherit and use this
behavior; but there are plenty of places where the child classes
overload the inherited behavior and do something different. The way
Python handles inheritance made this a joy to code up.
If you have any questions about anything here, please contact me using
this email address:
pyatom@langri.com

View File

@ -34,7 +34,6 @@ from wcs.qommon.tokens import Token
from wcs.qommon.admin.emails import EmailsDirectory
from wcs.qommon.admin.texts import TextsDirectory
from .announces import Announce, AnnounceSubscription
from .myspace import MyspaceDirectory
from .payments import PublicPaymentDirectory
from .payments_ui import InvoicesDirectory
@ -134,493 +133,6 @@ class FormsRootDirectory(wcs.forms.root.RootDirectory):
return r.getvalue()
class AnnounceDirectory(Directory):
_q_exports = ['', 'edit', 'delete', 'email']
def __init__(self, announce):
self.announce = announce
def _q_index(self):
template.html_top(_('Announces to citizens'))
r = TemplateIO(html=True)
if self.announce.publication_time:
date_heading = '%s - ' % time.strftime(misc.date_format(), self.announce.publication_time)
else:
date_heading = ''
r += htmltext('<h3>%s%s</h3>') % (date_heading, self.announce.title)
r += htmltext('<p>')
r += self.announce.text
r += htmltext('</p>')
r += htmltext('<p>')
r += htmltext('<a href="../">%s</a>') % _('Back')
r += htmltext('</p>')
return r.getvalue()
class AnnouncesDirectory(Directory):
_q_exports = ['', 'subscribe', 'email', 'atom', 'sms', 'emailconfirm',
'email_unsubscribe', 'sms_unsubscribe', 'smsconfirm', 'rawlist']
def _q_traverse(self, path):
get_response().breadcrumb.append(('announces/', _('Announces')))
return Directory._q_traverse(self, path)
def _q_index(self):
template.html_top(_('Announces to citizens'))
r = TemplateIO(html=True)
r += self.announces_list()
r += htmltext('<ul id="announces-links">')
r += htmltext('<li><a href="subscribe">%s</a></li>') % _('Receiving those Announces')
r += htmltext('</ul>')
return r.getvalue()
def _get_announce_subscription(self):
""" """
sub = None
if get_request().user:
subs = AnnounceSubscription.select(lambda x: x.user_id == get_request().user.id)
if subs:
sub = subs[0]
return sub
def rawlist(self):
get_response().filter = None
return self.announces_list()
def announces_list(self):
announces = Announce.get_published_announces()
if not announces:
raise errors.TraversalError()
# XXX: will need pagination someday
r = TemplateIO(html=True)
for item in announces:
r += htmltext('<div class="announce-item">\n')
r += htmltext('<h4>')
if item.publication_time:
r += time.strftime(misc.date_format(), item.publication_time)
r += ' - '
r += item.title
r += htmltext('</h4>\n')
r += htmltext('<p>\n')
r += item.text
r += htmltext('\n</p>\n')
r += htmltext('</div>\n')
return r.getvalue()
def sms(self):
sms_mode = get_cfg('sms', {}).get('mode', 'none')
if sms_mode == 'none':
raise errors.TraversalError()
get_response().breadcrumb.append(('sms', _('SMS')))
template.html_top(_('Receiving announces by SMS'))
r = TemplateIO(html=True)
if sms_mode == 'demo':
r += TextsDirectory.get_html_text('aq-sms-demo')
else:
announces_cfg = get_cfg('announces',{})
mobile_mask = announces_cfg.get('mobile_mask')
if mobile_mask:
mobile_mask = ' (' + mobile_mask + ')'
else:
mobile_mask = ''
form = Form(enctype='multipart/form-data')
form.add(StringWidget, 'mobile', title = _('Mobile number %s') % mobile_mask, size=12, required=True)
form.add_submit('submit', _('Subscribe'))
form.add_submit('cancel', _('Cancel'))
if form.get_submit() == 'cancel':
return redirect('subscribe')
if form.is_submitted() and not form.has_errors():
s = self.sms_submit(form)
if s == False:
r += form.render()
else:
return redirect("smsconfirm")
else:
r += form.render()
return r.getvalue()
def sms_submit(self, form):
mobile = form.get_widget("mobile").parse()
# clean the string, remove any extra character
mobile = re.sub('[^0-9+]','',mobile)
# if a mask was set, validate
announces_cfg = get_cfg('announces',{})
mobile_mask = announces_cfg.get('mobile_mask')
if mobile_mask:
mobile_regexp = re.sub('X','[0-9]', mobile_mask) + '$'
if not re.match(mobile_regexp, mobile):
form.set_error("mobile", _("Phone number invalid ! It must match ") + mobile_mask)
return False
if mobile.startswith('00'):
mobile = '+' + mobile[2:]
else:
# Default to france international prefix
if not mobile.startswith('+'):
mobile = re.sub("^0", "+33", mobile)
sub = self._get_announce_subscription()
if not sub:
sub = AnnounceSubscription()
if get_request().user:
sub.user_id = get_request().user.id
if mobile:
sub.sms = mobile
if not get_request().user:
sub.enabled = False
sub.store()
# Asking sms confirmation
token = Token(3 * 86400, 4, string.digits)
token.type = 'announces-subscription-confirmation'
token.subscription_id = sub.id
token.store()
message = _("Confirmation code : %s") % str(token.id)
sms_cfg = get_cfg('sms', {})
sender = sms_cfg.get('sender', 'AuQuotidien')[:11]
mode = sms_cfg.get('mode', 'none')
sms = SMS.get_sms_class(mode)
try:
sms.send(sender, [mobile], message)
except errors.SMSError, e:
get_logger().error(e)
form.set_error("mobile", _("Send SMS confirmation failed"))
sub.remove("sms")
return False
def smsconfirm(self):
template.html_top(_('Receiving announces by SMS confirmation'))
r = TemplateIO(html=True)
r += htmltext("<p>%s</p>") % _("You will receive a confirmation code by SMS.")
form = Form(enctype='multipart/form-data')
form.add(StringWidget, 'code', title = _('Confirmation code (4 characters)'), size=12, required=True)
form.add_submit('submit', _('Subscribe'))
form.add_submit('cancel', _('Cancel'))
if form.get_submit() == 'cancel':
return redirect('..')
if form.is_submitted() and not form.has_errors():
token = None
id = form.get_widget("code").parse()
try:
token = Token.get(id)
except KeyError:
form.set_error("code", _('Invalid confirmation code.'))
else:
if token.type != 'announces-subscription-confirmation':
form.set_error("code", _('Invalid confirmation code.'))
else:
sub = AnnounceSubscription.get(token.subscription_id)
token.remove_self()
sub.enabled_sms = True
sub.store()
return redirect('.')
r += form.render()
else:
r += form.render()
return r.getvalue()
def sms_unsubscribe(self):
sub = self._get_announce_subscription()
form = Form(enctype='multipart/form-data')
if not sub:
return redirect('..')
form.add_submit('submit', _('Unsubscribe'))
form.add_submit('cancel', _('Cancel'))
if form.get_submit() == 'cancel':
return redirect('..')
get_response().breadcrumb.append(('sms', _('SMS Unsubscription')))
template.html_top()
r = TemplateIO(html=True)
if form.is_submitted() and not form.has_errors():
if sub:
sub.remove("sms")
root_url = get_publisher().get_root_url()
r += htmltext('<p>')
r += _('You have been unsubscribed from announces')
r += htmltext('</p>')
r += htmltext('<a href="%s">%s</a>') % (root_url, _('Back Home'))
else:
r += htmltext('<p>')
r += _('Do you want to stop receiving announces by sms ?')
r += htmltext('</p>')
r += form.render()
return r.getvalue()
def subscribe(self):
get_response().breadcrumb.append(('subscribe', _('Subscription')))
template.html_top(_('Receiving Announces'))
r = TemplateIO(html=True)
r += TextsDirectory.get_html_text('aq-announces-subscription')
sub = self._get_announce_subscription()
r += htmltext('<ul id="announce-modes">')
if sub and sub.email:
r += htmltext(' <li>')
r += htmltext('<span id="par_mail">%s</span>') % _('Email (currently subscribed)')
r += htmltext(' <a href="email_unsubscribe" rel="popup">%s</a></li>') % _('Unsubscribe')
else:
r += htmltext(' <li><a href="email" id="par_mail" rel="popup">%s</a></li>') % _('Email')
if sub and sub.sms:
r += htmltext(' <li>')
if sub.enabled_sms:
r += htmltext('<span id="par_sms">%s</span>') % _('SMS %s (currently subscribed)') % sub.sms
else:
r += htmltext('<span id="par_sms">%s</span>') % _('SMS %s (currently not confirmed)') % sub.sms
r += htmltext(' <a href="smsconfirm" rel="popup">%s</a> ') % _('Confirmation')
r += htmltext(' <a href="sms_unsubscribe" rel="popup">%s</a></li>') % _('Unsubscribe')
elif get_cfg('sms', {}).get('mode', 'none') != 'none':
r += htmltext(' <li><a href="sms" id="par_sms">%s</a></li>') % _('SMS')
r += htmltext(' <li><a class="feed-link" href="atom" id="par_rss">%s</a>') % _('Feed')
r += htmltext('</ul>')
return r.getvalue()
def email(self):
get_response().breadcrumb.append(('email', _('Email Subscription')))
template.html_top(_('Receiving Announces by email'))
r = TemplateIO(html=True)
form = Form(enctype='multipart/form-data')
if get_request().user:
if get_request().user.email:
r += htmltext('<p>')
r += _('You are logged in and your email is %s, ok to subscribe ?') % \
get_request().user.email
r += htmltext('</p>')
form.add_submit('submit', _('Subscribe'))
else:
r += htmltext('<p>')
r += _("You are logged in but there is no email address in your profile.")
r += htmltext('</p>')
form.add(EmailWidget, 'email', title = _('Email'), required = True)
form.add_submit('submit', _('Subscribe'))
form.add_submit('submit-remember', _('Subscribe and add this email to my profile'))
else:
r += htmltext('<p>')
r += _('FIXME will only be used for this purpose etc.')
r += htmltext('</p>')
form.add(EmailWidget, 'email', title = _('Email'), required = True)
form.add_submit('submit', _('Subscribe'))
form.add_submit('cancel', _('Cancel'))
if form.get_submit() == 'cancel':
return redirect('subscribe')
if form.is_submitted() and not form.has_errors():
s = self.email_submit(form)
if s is not False:
return s
else:
r += form.render()
return r.getvalue()
def email_submit(self, form):
sub = self._get_announce_subscription()
if not sub:
sub = AnnounceSubscription()
if get_request().user:
sub.user_id = get_request().user.id
if form.get_widget('email'):
sub.email = form.get_widget('email').parse()
elif get_request().user.email:
sub.email = get_request().user.email
if not get_request().user:
sub.enabled = False
sub.store()
if get_request().user:
r = TemplateIO(html=True)
root_url = get_publisher().get_root_url()
r += htmltext('<p>')
r += _('You have been subscribed to the announces.')
r += htmltext('</p>')
r += htmltext('<a href="%s">%s</a>') % (root_url, _('Back Home'))
return r.getvalue()
# asking email confirmation before subscribing someone
token = Token(3 * 86400)
token.type = 'announces-subscription-confirmation'
token.subscription_id = sub.id
token.store()
data = {
'confirm_url': get_request().get_url() + 'confirm?t=%s&a=cfm' % token.id,
'cancel_url': get_request().get_url() + 'confirm?t=%s&a=cxl' % token.id,
'time': misc.localstrftime(time.localtime(token.expiration)),
}
emails.custom_template_email('announces-subscription-confirmation',
data, sub.email, exclude_current_user = False)
r = TemplateIO(html=True)
root_url = get_publisher().get_root_url()
r += htmltext('<p>')
r += _('You have been sent an email for confirmation')
r += htmltext('</p>')
r += htmltext('<a href="%s">%s</a>') % (root_url, _('Back Home'))
return r.getvalue()
def emailconfirm(self):
tokenv = get_request().form.get('t')
action = get_request().form.get('a')
root_url = get_publisher().get_root_url()
try:
token = Token.get(tokenv)
except KeyError:
return template.error_page(
_('The token you submitted does not exist, has expired, or has been cancelled.'),
continue_to = (root_url, _('home page')))
if token.type != 'announces-subscription-confirmation':
return template.error_page(
_('The token you submitted is not appropriate for the requested task.'),
continue_to = (root_url, _('home page')))
sub = AnnounceSubscription.get(token.subscription_id)
if action == 'cxl':
r = TemplateIO(html=True)
root_url = get_publisher().get_root_url()
template.html_top(_('Email Subscription'))
r += htmltext('<h1>%s</h1>') % _('Request Cancelled')
r += htmltext('<p>%s</p>') % _('The request for subscription has been cancelled.')
r += htmltext('<p>')
r += htmltext(_('Continue to <a href="%s">home page</a>') % root_url)
r += htmltext('</p>')
token.remove_self()
sub.remove_self()
return r.getvalue()
if action == 'cfm':
token.remove_self()
sub.enabled = True
sub.store()
r = TemplateIO(html=True)
root_url = get_publisher().get_root_url()
template.html_top(_('Email Subscription'))
r += htmltext('<h1>%s</h1>') % _('Subscription Confirmation')
r += htmltext('<p>%s</p>') % _('Your subscription to announces is now effective.')
r += htmltext('<p>')
r += htmltext(_('Continue to <a href="%s">home page</a>') % root_url)
r += htmltext('</p>')
return r.getvalue()
def atom(self):
response = get_response()
response.set_content_type('application/atom+xml')
from pyatom import pyatom
xmldoc = pyatom.XMLDoc()
feed = pyatom.Feed()
xmldoc.root_element = feed
feed.title = get_cfg('misc', {}).get('sitename') or 'Publik'
feed.id = get_request().get_url()
author_email = get_cfg('emails', {}).get('reply_to')
if not author_email:
author_email = get_cfg('emails', {}).get('from')
if author_email:
feed.authors.append(pyatom.Author(author_email))
announces = Announce.get_published_announces()
if announces and announces[0].modification_time:
feed.updated = misc.format_time(announces[0].modification_time,
'%(year)s-%(month)02d-%(day)02dT%(hour)02d:%(minute)02d:%(second)02dZ',
gmtime = True)
feed.links.append(pyatom.Link(get_request().get_url(1) + '/'))
for item in announces:
entry = item.get_atom_entry()
if entry:
feed.entries.append(entry)
return str(feed)
def email_unsubscribe(self):
sub = self._get_announce_subscription()
form = Form(enctype='multipart/form-data')
if not sub:
form.add(EmailWidget, 'email', title = _('Email'), required = True)
form.add_submit('submit', _('Unsubscribe'))
form.add_submit('cancel', _('Cancel'))
if form.get_submit() == 'cancel':
return redirect('..')
get_response().breadcrumb.append(('email', _('Email Unsubscription')))
template.html_top()
r = TemplateIO(html=True)
if form.is_submitted() and not form.has_errors():
if sub:
sub.remove("email")
else:
email = form.get_widget('email').parse()
for s in AnnounceSubscription.select():
if s.email == email:
s.remove("email")
root_url = get_publisher().get_root_url()
r += htmltext('<p>')
r += _('You have been unsubscribed from announces')
r += htmltext('</p>')
r += htmltext('<a href="%s">%s</a>') % (root_url, _('Back Home'))
else:
r += htmltext('<p>')
r += _('Do you want to stop receiving announces by email?')
r += htmltext('</p>')
r += form.render()
return r.getvalue()
def _q_lookup(self, component):
try:
announce = Announce.get(component)
except KeyError:
raise errors.TraversalError()
if announce.hidden:
raise errors.TraversalError()
get_response().breadcrumb.append((str(announce.id), announce.title))
return AnnounceDirectory(announce)
OldRegisterDirectory = wcs.root.RegisterDirectory
class AlternateRegisterDirectory(OldRegisterDirectory):
@ -757,7 +269,6 @@ class AlternateRootDirectory(OldRootDirectory):
_q_exports = ['', 'admin', 'backoffice', 'forms', 'login', 'logout',
'saml', 'register', 'ident', 'afterjobs',
('informations-editeur', 'informations_editeur'),
('announces', 'announces_dir'),
'myspace', 'services', 'categories', 'user',
('tmp-upload', 'tmp_upload'), 'json', '__version__',
'themes', 'pages', 'payment', 'invoices', 'roles',
@ -765,7 +276,6 @@ class AlternateRootDirectory(OldRootDirectory):
('reload-top', 'reload_top'), 'static',
('i18n.js', 'i18n_js'), 'actions',]
announces_dir = AnnouncesDirectory()
register = AlternateRegisterDirectory()
login = AlternateLoginDirectory()
ident = AlternateIdentDirectory()
@ -909,7 +419,6 @@ class AlternateRootDirectory(OldRootDirectory):
r += self.myspace_snippet()
r += self.box_services(position='2nd')
r += self.consultations()
r += self.announces()
r += htmltext('</div>')
user = get_request().user
@ -1105,34 +614,6 @@ class AlternateRootDirectory(OldRootDirectory):
def has_anonymous_access_codes(self):
return any((x for x in FormDef.select() if x.enable_tracking_codes))
def announces(self):
announces = Announce.get_published_announces()
if not announces:
return
r = TemplateIO(html=True)
r += htmltext('<div id="announces">')
r += htmltext('<h3>%s</h3>') % _('Announces to citizens')
for item in announces[:3]:
r += htmltext('<div class="announce-item">')
r += htmltext('<h4>')
if item.publication_time:
r += time.strftime(misc.date_format(), item.publication_time)
r += ' - '
r += item.title
r += htmltext('</h4>')
r += htmltext('<p>')
r += item.text
r += htmltext('</p>')
r += htmltext('</div>')
r += htmltext('<ul id="announces-links">')
r += htmltext('<li><a href="announces/subscribe">%s</a></li>') % _('Receiving those Announces')
r += htmltext('<li><a href="announces/">%s</a></li>') % _('Previous Announces')
r += htmltext('</ul>')
r += htmltext('</div>')
return r.getvalue()
def myspace_snippet(self):
r = TemplateIO(html=True)
r += htmltext('<div id="myspace">')
@ -1183,41 +664,6 @@ get_publisher_class().after_login_url = 'myspace/'
get_publisher_class().use_sms_feature = True
EmailsDirectory.register('announces-subscription-confirmation',
N_('Confirmation of Announces Subscription'),
N_('Available variables: change_url, cancel_url, time, sitename'),
default_subject = N_('Announce Subscription Request'),
default_body = N_("""\
You have (or someone impersonating you has) requested to subscribe to
announces from [sitename]. To confirm this request, visit the
following link:
[confirm_url]
If you are not the person who made this request, or you wish to cancel
this request, visit the following link:
[cancel_url]
If you do nothing, the request will lapse after 3 days (precisely on
[time]).
"""))
TextsDirectory.register('aq-announces-subscription',
N_('Text on announces subscription page'),
default = N_('''\
<p>
FIXME
'</p>'''))
TextsDirectory.register('aq-sms-demo',
N_('Text when subscribing to announces SMS and configured as demo'),
default = N_('''
<p>
Receiving announces by SMS is not possible in this demo
</p>'''))
TextsDirectory.register('aq-editor-info', N_('Editor Informations'))
TextsDirectory.register('aq-accessibility', N_('Accessibility Statement'))
TextsDirectory.register('aq-contact', N_('Contact Information'))

View File

@ -43,11 +43,6 @@ def render_response(publisher, body):
elif section == 'consultations':
section_title = '<h2 id="consultations">%s</h2>\n' % _('Consultations')
response.filter['bigdiv'] = 'rub_consultation'
elif section == 'announces':
response.filter['bigdiv'] = 'rub_annonce'
section_title = '<h2 id="announces">%s</h2>\n' % _('Announces to citizens')
if page_title == _('Announces to citizens'):
page_title = ''
elif section and len(section) > 1:
# XXX: this works but is not efficient
if Category.has_urlname(section):