-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfreightcompany.py
55 lines (46 loc) · 2.17 KB
/
freightcompany.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
###########################################################################
# Copyright (C) 2003 by kosh
#
# Copyright: See COPYING file that comes with this distribution
#
###########################################################################
#For Security control and init
from AccessControl import ClassSecurityInfo
import Globals
from userobject import UserObject
import utility
class FreightCompany(UserObject):
"The FreightCompany object holds freightclass objects"
security = ClassSecurityInfo()
meta_type = "FreightCompany"
freightCompanyName = ''
security.declareProtected('View management screens', 'edit')
def edit(self, *args, **kw):
"Inline edit short object"
freightItems = self.objectItems('FreightClass')
freightItems.sort()
editFreightItems = [freightclass.editOutput() for name, freightclass in freightItems]
format = '<p>%s</p>%s'
return format % (self.freightCompanyName, self.createTable(editFreightItems))
security.declarePrivate('getFreightCompanyListing')
def getFreightCompanyListing(self):
"return the freight company and the class listing as a dict with the value as the floating point number"
listing = {}
format = "%s - %s"
for freightClass in self.objectValues('FreightClass'):
listing[format % (self.freightCompanyName,freightClass.freightClass)] = freightClass.price.float()
return listing
security.declarePrivate('syncFreightClasses')
def syncFreightClasses(self, seq=None):
"sync the FreightClass objects that we have with what is in the list"
if seq is not None:
cleanNames = [utility.cleanRegisteredId(name) for name in seq]
self.delObjects([name for name in self.objectIds('FreightClass') if name not in cleanNames])
for clean, name in zip(cleanNames, seq):
if clean is not None and not self.hasObject(clean):
self.addRegisteredObject(clean, 'FreightClass')
getattr(self, clean).freightClass = name
Globals.InitializeClass(FreightCompany)
import register
register.registerClass(FreightCompany)