-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompany_views.py
183 lines (142 loc) · 6.18 KB
/
company_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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# -*- coding: UTF-8 -*-
# Copyright (C) 2009-2010 Nicolas Deram <[email protected]>
# Copyright (C) 2010-2011 Hervé Cauwelier <[email protected]>
# Copyright (C) 2011 Taverne Sylvain <[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 the Standard Library
# Import from itools
from itools.core import merge_dicts, freeze, is_thingy
from itools.database import PhraseQuery
from itools.datatypes import PathDataType, String, Unicode
from itools.gettext import MSG
from itools.web import INFO, ERROR
# Import from ikaaro
from ikaaro.autoform import ImageSelectorWidget, MultilineWidget
from ikaaro.autoform import TextWidget
from ikaaro.datatypes import Multilingual
from ikaaro.resource_views import DBResource_Edit
from ikaaro.views import CompositeForm
# Import from crm
from base_views import CRMFolder_AddForm
from crm_views import CRM_SearchContacts
from menus import MissionsMenu, ContactsByCompanyMenu, CompanyMenu
from utils import get_crm
from views import TagsAware_Edit
from widgets import LinkWidget
MSG_NEW_COMPANY = INFO(u"Company added. You can now add a contact from "
u"this company.")
company_schema = freeze(merge_dicts(
DBResource_Edit.schema,
description=Multilingual(hidden_by_default=False),
crm_c_address_1=Unicode,
crm_c_address_2=Unicode,
crm_c_zipcode=String,
crm_c_town=Unicode,
# TODO Country should be CountryName (listed)
crm_c_country=Unicode,
crm_c_phone=Unicode,
crm_c_fax=Unicode,
crm_c_website=Unicode,
crm_c_activity=Unicode,
crm_c_logo=PathDataType))
company_widgets = freeze(
DBResource_Edit.widgets[:2] + [
TextWidget('crm_c_address_1', title=MSG(u'Address')),
TextWidget('crm_c_address_2', title=MSG(u'Address (next)')),
TextWidget('crm_c_zipcode', title=MSG(u'Zip Code'), size=10),
TextWidget('crm_c_town', title=MSG(u'Town')),
TextWidget('crm_c_country', title=MSG(u'Country')),
TextWidget('crm_c_phone', title=MSG(u'Phone'), size=15),
TextWidget('crm_c_fax', title=MSG(u'Fax'), size=15),
LinkWidget('crm_c_website', title=MSG(u'Website'), size=30),
TextWidget('crm_c_activity', title=MSG(u'Activity'), size=30),
ImageSelectorWidget('crm_c_logo', title=MSG(u'Logo'),
action='add_logo'),
MultilineWidget('description', title=MSG(u'Observations'), rows=4)])
class Company_EditForm(TagsAware_Edit, DBResource_Edit):
template = '/ui/crm/generic/auto_form.xml'
title = MSG(u'Edit Company')
styles = ['/ui/crm/style.css']
context_menus = []
query_schema = company_schema
def _get_schema(self, resource, context):
tags_schema = TagsAware_Edit._get_schema(self, resource, context)
return freeze(merge_dicts(
company_schema,
# title is mandatory
title=company_schema['title'](mandatory=True),
# Tags
tags=tags_schema['tags']))
def _get_widgets(self, resource, context):
tags_widgets = TagsAware_Edit._get_widgets(self, resource, context)
return freeze(
company_widgets
+ [tags_widgets[0]])
def get_value(self, resource, context, name, datatype):
if name == 'tags':
return TagsAware_Edit.get_value(self, resource, context, name,
datatype)
return DBResource_Edit.get_value(self, resource, context, name,
datatype)
def set_value(self, resource, context, name, form):
if name == 'tags':
return TagsAware_Edit.set_value(self, resource, context, name,
form)
return DBResource_Edit.set_value(self, resource, context, name, form)
class Company_AddForm(CRMFolder_AddForm, Company_EditForm):
title = MSG(u'New Company')
context_menus = []
def action(self, resource, context, form):
company = resource.add_company()
Company_EditForm.action(self, company, context, form)
if is_thingy(context.message, ERROR):
return
crm = get_crm(resource)
goto = '%s/contacts/;new_contact?crm_p_company=%s' % (
context.get_link(crm), company.name)
return context.come_back(MSG_NEW_COMPANY, goto)
class Company_ViewContacts(CRM_SearchContacts):
search_template = None
csv_columns = None
columns_to_keep = ('sprite', 'title', 'email', 'phones', 'crm_p_position',
'crm_p_opportunity', 'crm_p_project', 'crm_p_nogo',
'crm_p_assured', 'crm_p_probable')
def get_table_columns(self, resource, context):
proxy = super(Company_ViewContacts, self)
columns = proxy.get_table_columns(resource, context)
to_keep = self.columns_to_keep
return [column for column in columns if column[0] in to_keep]
def get_items(self, resource, context, *args):
args = list(args)
args.append(PhraseQuery('crm_p_company', resource.name))
proxy = super(Company_ViewContacts, self)
return proxy.get_items(resource, context, *args)
def get_namespace(self, resource, context):
proxy = super(Company_ViewContacts, self)
namespace = proxy.get_namespace(resource, context)
namespace['crm-infos'] = False
namespace['export-csv'] = False
return namespace
class Company_View(CompositeForm):
access = 'is_allowed_to_edit'
title = MSG(u'View Company')
styles = ['/ui/crm/style.css']
context_menus = [
MissionsMenu(contact_menu=ContactsByCompanyMenu()),
ContactsByCompanyMenu(),
CompanyMenu()]
subviews = [
Company_EditForm(),
Company_ViewContacts()]