File: PropertySheets.py

package info (click to toggle)
zope-zpatterns 0.4.3p2-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 476 kB
  • ctags: 814
  • sloc: python: 2,817; ansic: 310; makefile: 52; sh: 39
file content (128 lines) | stat: -rw-r--r-- 2,963 bytes parent folder | download | duplicates (4)
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
import OFS.PropertySheets
from ComputedAttribute import ComputedAttribute
from Globals import default__class_init__, Dictionary
from ZClasses.Property import klass_sequence, ClassCaretaker, ZCommonSheet

class VirtualSheets(OFS.PropertySheets.PropertySheets):

    """Ensure that virtual propertysheets are included in sheets"""

    def __propsets__(self):
        propsets = self._get_defaults()+self.aq_inner.aq_parent._v_currentSheets
        r=[]
        for id in klass_sequence(self.__class__,'__propset_attrs__').keys():
            r.append(getattr(self,id))
        return propsets+tuple(r)

    def get(self,name,default=None):
        for propset in self._get_defaults():
            if propset.id==name or propset.xml_namespace()==name:
                return propset.__of__(self)

        client = self.aq_inner.aq_parent
        s = client._delegateToSheetProviders(name,name,'_PropertySheetFor')

        if s is not None: return s.__of__(self)
        return default


    def __bobo_traverse__(self, REQUEST, name=None):
        for propset in self._get_defaults():
            if propset.id==name:
                return propset.__of__(self)

        client = self.aq_inner.aq_parent
        s = client._delegateToSheetProviders(name,'','_PropertySheetFor')
        
        if s is not None: return s.__of__(self)
        return getattr(self, name)



    def manage_addPropertySheet(self, id, ns):
        """ """
        if self.aq_inner.aq_parent._addPropertySheet(id,ns):
            return 'OK'

    def manage_delPropertySheet(self, name='', xmlns=''):
        """ """
        self.aq_inner.aq_parent._delPropertySheet(name,xmlns)
        return 'OK'

    __ac_permissions__ = (
        ("Manage properties",
            ('manage_addPropertySheet','manage_delPropertySheet')
        ),
    )

    _implements_the_notional_subclassable_propertysheet_class_interface=1

    def propertyLabel(self,id):
        return id   # Hack to make sheets UI work
        
default__class_init__(VirtualSheets)



















# ZClass propertysheet helpers

class DefaultCaretaker(ClassCaretaker):
    # Map attributes to 'class_default_for_' variables
    
    def __getattr__(self,name):
        return ClassCaretaker.__getattr__(self,'class_default_for_'+name)

    def __setattr__(self,name,value):
        ClassCaretaker.__setattr__(self,'class_default_for_'+name,value)

    def __delattr__(self,name):
        ClassCaretaker.__delattr__(self,'class_default_for_'+name)


class DataSkinSheet(ZCommonSheet):
    """Property sheet that creates class defaults for properties"""

    meta_type="DataSkin Attribute Property Sheet"

    def v_self(self):
        klass=self.aq_inner.aq_parent.aq_parent.aq_parent._zclass_
        return DefaultCaretaker(klass)


















def SheetAttribute(name='',xmlns=''):
	def getsheet(self,name=name,xmlns=xmlns):
		return self.PropertySheet(name=name,xmlns=xmlns)
	return ComputedAttribute(getsheet)