CVS commit (wiking): cms.py
Milan Zamazal
pdm at devel.brailcom.org
Fri May 15 21:47:21 CEST 2009
Update of /var/lib/cvs/wiking/lib/wiking/cms
In directory devel:/tmp/cvs-serv21341/lib/wiking/cms
Modified Files:
cms.py
Log Message:
Preliminary support for predefined e-mail texts
/var/www/hosts/cvs.freebsoft.org/src/wiking:
Index: lib/wiking/cms/cms.py
===================================================================
RCS file: /var/lib/cvs/wiking/lib/wiking/cms/cms.py,v
retrieving revision 1.171
retrieving revision 1.170
diff -u -r1.171 -r1.170
--- lib/wiking/cms/cms.py 15 May 2009 19:47:09 -0000 1.170
+++ lib/wiking/cms/cms.py 15 May 2009 19:47:19 -0000 1.171
@@ -2474,11 +2474,14 @@
super(Texts, self)._delayed_init()
self._register_texts()
+ def _is_text(self, object):
+ return isinstance(object, Text)
+
def _register_texts(self):
for module in self._TEXT_MODULES:
for identifier in dir(module):
text = getattr(module, identifier)
- if isinstance(text, Text):
+ if self._is_text(text):
self._call_db_function('add_text_label', text.label())
self.Spec._register_text(text)
@@ -2577,3 +2580,65 @@
"""
assert isinstance(text, Text)
return self.text(req, text, lang=lang, args=args, _method=Texts.parsed_text)
+
+class EmailText(Structure):
+ """Representation of a predefined e-mail.
+
+ Each predefined e-mail consists of the following attributes:
+
+ label -- unique identifier of the e-mail, string
+ description -- human description of the e-mail, presented to application
+ administrators managing the e-mails
+ subject -- subject of the mail, as a translatable string or unicode
+ text -- body of the mail, as a translatable string or unicode
+ cc -- body of the mail, as a translatable string or unicode
+
+ Note the predefined e-mail texts get automatically translated using gettext
+ mechanism.
+
+ """
+ _attributes = (Attribute('label', str),
+ Attribute('description', basestring),
+ Attribute('text', basestring),
+ Attribute('subject', basestring),
+ Attribute('cc', str, default=''),)
+ def __init__(self, label, description, subject, text, **kwargs):
+ super(Text, self).__init__(label=label, description=description, text=text, subject=subject,
+ **kwargs)
+
+class Emails(Texts):
+ """Management of e-mail predefined texts.
+
+ This is similar to managing general predefined texts. But e-mails may
+ contain more data such as subjects or CC lists.
+
+ """
+
+ class Spec(Texts.Spec):
+
+ table = 'emails'
+ title = _("E-mails")
+ help = _("Edit e-mail texts.")
+
+ def fields(self): return (
+ Field('text_id', editable=NEVER),
+ Field('label', _("Label"), width=32, editable=NEVER),
+ Field('lang', editable=NEVER),
+ Field('descr', _("Purpose"), type=pytis.data.String(), width=64, editable=NEVER, virtual=True,
+ computer=computer(self._description)),
+ Field('content', _("Text"), width=80, height=10,
+ descr=_("Edit the given text as needed, in accordance with structured text rules.")),
+ Field('subject', _("Subject")),
+ Field('cc', _("Additional recipients"),
+ descr=_("Comma separated list of e-mail addresses.")),
+ )
+
+ columns = ('label', 'descr',)
+ sorting = (('label', ASC,),)
+ layout = ('label', 'descr', 'subject', 'cc', 'content',)
+
+ WMI_SECTION = WikingManagementInterface.SECTION_SETUP
+ WMI_ORDER = 910
+
+ def _is_text(self, object):
+ return isinstance(object, Email)
Index: sql/wiking.sql
===================================================================
RCS file: /var/lib/cvs/wiking/sql/wiking.sql,v
retrieving revision 1.58
retrieving revision 1.57
diff -u -r1.58 -r1.57
--- sql/wiking.sql 15 May 2009 19:46:28 -0000 1.57
+++ sql/wiking.sql 15 May 2009 19:47:19 -0000 1.58
@@ -403,6 +403,39 @@
end
$$ language plpgsql;
+create table email_labels (
+ label name primary key
+);
+
+create table _emails (
+ label name not null references email_labels,
+ lang char(2) not null references languages(lang) on delete cascade,
+ subject text,
+ cc text,
+ content text default '',
+ primary key (label, lang)
+);
+
+create or replace view emails as
+select label || '@' || lang as text_id, label, lang,
+ coalesce(subject, '') as subject,
+ coalesce(cc, '') as cc,
+ coalesce(content, '') as content
+from email_labels cross join languages left outer join _emails using (label, lang);
+
+create or replace rule emails_update as
+ on update to emails do instead (
+ delete from _emails where label = new.label and lang = new.lang;
+ insert into _emails values (new.label, new.lang, new.subject, new.cc, new.content);
+);
+
+create table email_attachments (
+ attachment_id serial primary key,
+ label name not null references email_labels on delete cascade,
+ filename varchar(64) not null,
+ mime_type text not null
+);
+
-------------------------------------------------------------------------------
CREATE TABLE config (
More information about the Wiking-cvs
mailing list