Mercurial > libervia-website
diff pages/association/membership/page_meta.py @ 0:09d66acc7c73
initial commit, website first draft:
- presentation page
- documentation (generated from backend and Libervia)
- social contract (HTML generated from sat repository)
- press/conferences (adapted from former website)
- association page (adpated from former website)
- news (a selected blog is displayed)
- fr i18n
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 26 May 2019 22:26:30 +0200 |
parents | |
children | 9ce41ef66dfa |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pages/association/membership/page_meta.py Sun May 26 22:26:30 2019 +0200 @@ -0,0 +1,92 @@ +#!/usr/bin/env python2.7 +# -*- coding: utf-8 -*- + +from collections import namedtuple +from twisted.internet import defer +from libervia.server.constants import Const as C +from sat.core.i18n import D_ +from sat.tools import config +from sat.tools.common import email +from sat.core import exceptions +from sat.core.log import getLogger + +log = getLogger(__name__) + +name = u"association_membership" +template = u"association/membership.html" + +FIELDS = ( + 'name', + 'firstname', + 'address', + 'email', + 'jid', + 'subscription', + 'reference', + 'comment', + 'mailing_list', + 'documents_read', + ) +REQUIRED = ('name', 'firstname', 'address', 'email', 'subscription') +FormData = namedtuple("FormData", FIELDS) + +SUBJECT_ADMIN = D_(u"New subscription to the association") +BODY_ADMIN = D_(u"""\ +New subscription received: + +{fields_list}""").format( + fields_list=u"\n".join(u"- {0}: {{{0}}}".format(f) for f in FIELDS) + ) + +SUBJECT = D_(u"Your association membership request") +BODY = D_(u"""\ +Hello {firstname}, + +you request to join the "Salut à Toi" association has been well received. +Thank you and welcome to the SàT community. + +You can contact us at contact""" +# we split the address to avoid +# it being recognized too easily by spam bots ++ u'@' + u'salut-a-toi' + u'.org' +u""" +or on the official XMPP chat room: +xmpp: sat@chat.jabberfr.org +web: https://chat.jabberfr.org/converse.js/sat@chat.jabberfr.org + +The Salut à Toi team +""") + +WARNING_MSG_NOT_READ = D_( + u"You must have read the documents to validate your membership request") +WARNING_MSG_MISSING_FIELDS = D_( + u"The form you posted is not complete, we can't validate this membership request.\n" + u"Please fill all the required fields, thank you!") + +@defer.inlineCallbacks +def on_data_post(self, request): + data = FormData(*self.getPostedData(request, FIELDS, raise_on_missing=False)) + if any(not getattr(data, f) for f in REQUIRED): + log.warning(u"missing data fields:\n{data}".format(data=data)) + raise exceptions.DataError(WARNING_MSG_MISSING_FIELDS) + if not C.bool(data.documents_read or C.BOOL_FALSE): + log.warning(u"documents_read has not been checked:\n{data}".format(data=data)) + raise exceptions.DataError(WARNING_MSG_NOT_READ) + addresses = config.getConfig( + self.host.main_conf, + None, + "email_admins_list", + default=Exception) + yield email.sendEmail( + self.host.main_conf, + addresses, + SUBJECT_ADMIN, + BODY_ADMIN.format(**data._asdict()), + ) + yield email.sendEmail( + self.host.main_conf, + data.email, + SUBJECT, + BODY.format(**data._asdict()), + ) +