-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatatypes.py
More file actions
152 lines (113 loc) · 4.39 KB
/
Copy pathdatatypes.py
File metadata and controls
152 lines (113 loc) · 4.39 KB
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
# -*- coding: UTF-8 -*-
# Copyright (C) 2007-2009 Henry Obein <henry@itaapy.com>
# Copyright (C) 2008, 2010 Nicolas Deram <nicolas@itaapy.com>
# Copyright (C) 2010-2011 Hervé Cauwelier <herve@itaapy.com>
#
# 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
from operator import itemgetter
# Import from itools
from itools.core import thingy_property
from itools.datatypes import Enumerate
from itools.gettext import MSG
from itools.handlers.utils import transmap
from itools.web import get_context
# Import from ikaaro
from ikaaro.cc import UsersList
# Import from crm
from utils import get_crm
############################################################
# CRM
############################################################
class CompanyName(Enumerate):
@classmethod
def get_options(cls):
context = get_context()
crm = get_crm(context.resource)
parent_path = '%s/companies' % crm.get_abspath()
root = context.root
results = root.search(format='company', parent_path=parent_path)
options = []
# FIXME catalog case-independant sort
for brain in results.get_documents():
value = brain.title
# Reduce the length of the title
if len(value) > 63:
value = '%s...%s' % (value[:30], value[-30:])
options.append({
'name': brain.name,
'value': value,
'sort_value': value.lower().translate(transmap)})
# FIXME move hack to a catalog index
options.sort(key=itemgetter('sort_value'))
return options
class MissionStatus(Enumerate):
options = [
{'name': 'opportunity', 'value': MSG(u"Opportunity")},
{'name': 'project', 'value': MSG(u"Project")},
{'name': 'finished', 'value': MSG(u"Finished")},
{'name': 'nogo', 'value': MSG(u"NoGo")}]
class MissionStatusShortened(Enumerate):
options = [
{'name': 'opportunity', 'value': MSG(u"Opportunity")},
{'name': 'project', 'value': MSG(u"Win")},
{'name': 'finished', 'value': MSG(u"Finished")},
{'name': 'nogo', 'value': MSG(u"NoGo")}]
class ContactStatus(Enumerate):
options = [
{'name': 'lead', 'value': MSG(u"Lead")},
{'name': 'client', 'value': MSG(u"Client")},
{'name': 'dead', 'value': MSG(u"Dead")}]
class ContactName(Enumerate):
@classmethod
def get_options(cls):
context = get_context()
crm = get_crm(context.resource)
parent_path = '%s/contacts' % crm.get_abspath()
root = context.root
results = root.search(format='contact', parent_path=parent_path)
options = []
for brain in results.get_documents(sort_by='crm_p_lastname'):
options.append({
'name': brain.name,
'value': brain.title})
return options
class CSVEditor(Enumerate):
options = [
{'name': 'oo', 'value': MSG(u"OpenOffice.org / LibreOffice"),
'parameters': ('UTF-8', ','),
},
{'name': 'excel', 'value': MSG(u"MS Excel"),
'parameters': ('CP1252', ';'),
}]
def get_parameters(cls, name):
"""Returns the value matching the given name, or the default value.
"""
for option in cls.options:
if option['name'] == name:
return option['parameters']
raise ValueError, name
class AssignedList(UsersList):
NOT_ASSIGNED = 'notassigned'
def get_default(self):
return get_context().user.name
@thingy_property
def resource(self):
return get_context().resource
def get_options(self):
options = super(AssignedList, self).get_options()
options.append({
'name': self.NOT_ASSIGNED,
'value': MSG(u"(Not Assigned)")})
return options