-
Notifications
You must be signed in to change notification settings - Fork 0
/
company.py
101 lines (86 loc) · 3.63 KB
/
company.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
# -*- coding: UTF-8 -*-
# Copyright (C) 2009-2010 Nicolas Deram <[email protected]>
# Copyright (C) 2010-2011 Hervé Cauwelier <[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
from itools.datatypes import PathDataType, String, Unicode
from itools.gettext import MSG
# Import from ikaaro
from ikaaro.folder import Folder
from ikaaro.folder_views import Folder_BrowseContent
# Import from crm
from base import CRMFolder
from base_views import CRMFolder_AddImage
from company_views import Company_AddForm, Company_EditForm
from company_views import Company_View
from utils import generate_code
class Company(CRMFolder):
""" A Company is a folder with metadata containing files related to it such
as logo, images, ...
"""
class_id = 'company'
class_version = '20100916'
class_icon16 = 'crm/icons/16x16/company.png'
class_icon48 = 'crm/icons/48x48/company.png'
class_schema = freeze(merge_dicts(
CRMFolder.class_schema,
crm_c_address_1=Unicode(source='metadata', stored=True),
crm_c_address_2=Unicode(source='metadata', stored=True),
crm_c_zipcode=String(source='metadata', stored=True),
crm_c_town=Unicode(source='metadata', stored=True),
crm_c_country=Unicode(source='metadata', stored=True),
crm_c_phone=Unicode(source='metadata', stored=True),
crm_c_fax=Unicode(source='metadata', stored=True),
crm_c_website=Unicode(source='metadata', stored=True),
crm_c_activity=Unicode(source='metadata', stored=True),
crm_c_logo=PathDataType(source='metadata', default='.',
stored=True)))
class_sprite16 = 'crm16-company'
class_title = MSG(u'Company')
class_views = ['view'] + CRMFolder.class_views_shortcuts
# Views
browse_content = Folder_BrowseContent(access='is_allowed_to_edit')
edit = Company_EditForm()
view = Company_View()
#############################################
# Ikaaro API
#############################################
def get_catalog_values(self):
document = super(Company, self).get_catalog_values()
title = self.get_title()
description = self.get_property('description')
values = [title or u'', description or u'']
document['text'] = u' '.join(values)
return document
###################################
# Container #
###################################
class Companies(Folder):
""" Container of "company" resources. """
class_id = 'companies'
class_title = MSG(u'Companies')
class_version = '20100304'
class_views = ['new_company', 'browse_content']
class_document_types = [Company]
# Views
browse_content = Folder_BrowseContent(access='is_allowed_to_edit')
new_company = Company_AddForm()
add_logo = CRMFolder_AddImage()
def add_company(self, **values):
names = self.get_names()
name = generate_code(names, 'c%06d')
return self.make_resource(name, Company, **values)