-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailing_views.py
106 lines (81 loc) · 3.63 KB
/
mailing_views.py
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# -*- coding: utf-8 -*-
# Copyright (C) 2007 Taverne Sylvain <[email protected]>
# Copyright (C) 2010-2011 David Versmisse <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Import from itools
from itools.core import freeze, merge_dicts
from itools.database import PhraseQuery, AndQuery
from itools.datatypes import Email
from itools.gettext import MSG
# import from ikaaro
from ikaaro.autoform import TextWidget
from ikaaro.buttons import RemoveButton
from ikaaro.cc import SubscribeForm, ManageForm
from ikaaro.folder_views import Folder_BrowseContent
from ikaaro.resource_views import DBResource_Edit
from ikaaro.utils import get_base_path_query
class Mailing_View(Folder_BrowseContent):
access = 'is_admin'
title = MSG(u'View')
search_template = None
# Table
batch_msg1 = MSG(u"There is 1 newsletter.")
batch_msg2 = MSG(u"There are {n} newsletters.")
table_columns = [
('checkbox', None),
('title', MSG(u'Title')),
('email_subject', MSG(u'Newsletter subject')),
('is_sent', MSG(u'Sent ?')),
('mtime', MSG(u'Last Modified')),
('last_author', MSG(u'Last Author'))]
table_actions = [RemoveButton]
def get_items(self, resource, context, *args):
path = resource.get_canonical_path()
query = AndQuery(get_base_path_query(str(path)),
PhraseQuery('format', 'mailing-letter'))
return context.root.search(query)
def get_item_value(self, resource, context, item, column):
if column == 'title':
brain, item_resource = item
href = '%s/' % context.get_link(item_resource)
return item_resource.get_title(), href
elif column == 'is_sent':
brain, item_resource = item
is_sent = item_resource.get_property('is_sent')
if is_sent:
nb_users = item_resource.get_property('number')
return MSG(u'Yes (To {x} users)').gettext(x=nb_users)
return MSG(u'No')
proxy = super(Mailing_View, self)
return proxy.get_item_value(resource, context, item, column)
class Mailing_Edit(DBResource_Edit):
access = 'is_admin'
title = MSG(u'Configure')
schema = merge_dicts(DBResource_Edit.schema,
sender=Email(source='metadata', mandatory=True))
widgets = DBResource_Edit.widgets + [TextWidget('sender',
title=MSG(u"Sender's Email"))]
class Mailing_ManageForm(ManageForm):
table_columns = freeze(ManageForm.table_columns + [
('grey_list', 'Unsubscribed')])
def get_item_value(self, resource, context, item, column):
if column == 'grey_list':
on_grey_list = item.name in resource.get_property('grey_list')
return MSG(u"Yes") if on_grey_list else MSG(u"No")
proxy = super(Mailing_ManageForm, self)
return proxy.get_item_value(resource, context, item, column)
class Mailing_SubscribeForm(SubscribeForm):
subviews = SubscribeForm.subviews[:]
subviews[1] = Mailing_ManageForm()