-
Notifications
You must be signed in to change notification settings - Fork 0
/
mission.py
144 lines (126 loc) · 5.29 KB
/
mission.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
# -*- coding: UTF-8 -*-
# Copyright (C) 2009-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
# Import from itools
from itools.core import merge_dicts, freeze
from itools.datatypes import Date, DateTime, Decimal, Integer
from itools.datatypes import String, Unicode
from itools.gettext import MSG
# Import from ikaaro
from ikaaro.comments import comment_datatype
from ikaaro.folder import Folder
from ikaaro.folder_views import Folder_BrowseContent
# Import from crm
from base import CRMFolder
from base_views import Comments_View
from mission_views import Mission_Add, Mission_AddForm, Mission_EditForm
from mission_views import Mission_View, Mission_ViewContacts
from mission_views import Mission_EditContacts, Mission_AddContacts
from mission_views import Mission_ViewContact
from datatypes import MissionStatus
from utils import generate_code
class Mission(CRMFolder):
""" A mission is a folder containing:
- metadata (including comments)
- documents related to comments
"""
class_id = 'mission'
class_version = '20100927'
class_icon16 = 'crm/icons/16x16/mission.png'
class_icon48 = 'crm/icons/48x48/mission.png'
class_title = MSG(u'Mission')
class_schema = freeze(merge_dicts(
CRMFolder.class_schema,
crm_m_contact=String(source='metadata', indexed=True, stored=True,
multiple=True),
crm_m_status=MissionStatus(source='metadata', indexed=True,
stored=True),
crm_m_assigned=String(source='metadata', default='', indexed=True,
stored=True),
crm_m_cc=String(source='metadata', multiple=True),
crm_m_amount=Decimal(source='metadata', stored=True),
crm_m_probability=Integer(source='metadata', stored=True),
crm_m_deadline=Date(source='metadata', stored=True),
crm_m_alert=DateTime(source='metadata', indexed=False, stored=True),
crm_m_nextaction=Unicode(source='metadata', indexed=False,
stored=True),
comment=comment_datatype(parameters_schema=merge_dicts(
comment_datatype.parameters_schema,
attachment=String))))
class_sprite16 = 'crm16-mission'
class_views = (['view', 'add_contacts', 'edit_contacts', 'edit_alerts']
+ CRMFolder.class_views_shortcuts)
# Views
add_contacts = Mission_AddContacts()
browse_content = Folder_BrowseContent(access=False)
edit_form = Mission_EditForm()
edit_contacts = Mission_EditContacts()
preview_content = None
view = Mission_View()
view_comments = Comments_View()
view_contacts = Mission_ViewContacts()
#############################################
# Ikaaro API
#############################################
def get_catalog_values(self):
document = super(Mission, self).get_catalog_values()
title = self.get_property('title')
description = self.get_property('description')
nextaction = self.get_property('crm_m_nextaction')
# Index all comments as 'text'
values = [title or u'',
description or u'',
nextaction or u'']
m_contacts = self.get_property('crm_m_contact')
contacts = self.parent.parent.get_resource('contacts')
for m_contact in m_contacts:
contact = contacts.get_resource(m_contact)
values.append(contact.get_property('crm_p_lastname'))
values.append(contact.get_property('crm_p_firstname'))
title = contact.get_property('title')
if title:
values.append(title)
# Comment
values.extend(self.get_property('comment'))
document['text'] = u' '.join(values)
return document
#############################################
# CRM API
#############################################
def get_last_comment(self):
comments = self.metadata.get_property('comment') or []
if comments:
return comments[-1]
return None
###################################
# Container #
###################################
class Missions(Folder):
""" Container of "mission" resources. """
class_id = 'missions'
class_title = MSG(u'Missions')
class_views = ['new_mission', 'browse_content']
class_document_types = [Mission]
# Views
add_form = Mission_AddForm()
browse_content = Folder_BrowseContent(access='is_allowed_to_edit')
new_mission = Mission_Add()
view_contact = Mission_ViewContact()
def add_mission(self, **kw):
names = self.get_names()
name = generate_code(names, 'm%06d')
return self.make_resource(name, Mission, **kw)