source: products/quintagroup.ploneformgen.readonlystringfield/trunk/quintagroup/ploneformgen/readonlystringfield/field.py @ 826

Last change on this file since 826 was 826, checked in by mylan, 15 years ago

Fix i18n:attributes deprecation warning for Plone-2.5 (#337)

  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
1from AccessControl import ClassSecurityInfo
2
3from Products.CMFCore.permissions import View
4from Products.CMFCore.Expression import getExprContext
5from Products.Archetypes.atapi import Schema
6from Products.Archetypes.Field import StringField
7from Products.Archetypes.Widget import StringWidget
8from Products.ATContentTypes.content.base import registerATCT
9
10from Products.TALESField import TALESString
11from Products.PloneFormGen.content.fields import FGStringField
12from Products.PloneFormGen.content.fieldsBase import finalizeFieldSchema
13
14from quintagroup.ploneformgen.readonlystringfield.widget import ReadonlyStringWidget
15from quintagroup.ploneformgen.readonlystringfield.config import PROJECTNAME
16
17class FGReadonlyStringField(FGStringField):
18    """ A string entry field """
19
20    security  = ClassSecurityInfo()
21
22    schema = FGStringField.schema.copy() + Schema((
23        TALESString('editMode',
24            searchable=0,
25            required=0,
26            validators=('talesvalidator',),
27            default='',
28            widget=StringWidget(label="Edit Mode Expression",
29                description="""
30                    A TALES expression that will be evaluated when the form is displayed
31                    to know whether or not to make field editable.
32                    Leave empty if you need read only field in any case. Your expression
33                    should evaluate as a string.
34                    PLEASE NOTE: errors in the evaluation of this expression will cause
35                    an error on form display.
36                """,
37                size=70,
38                i18n_domain = "quintagroup.ploneformgen.readonlystringfield",
39                label_msgid = "label_editmode_text",
40                description_msgid = "help_editmode_text",
41                ),
42            ),
43    ))
44
45    # hide references & discussion
46    finalizeFieldSchema(schema, folderish=True, moveDiscussion=False)
47
48    # Standard content type setup
49    portal_type = meta_type = 'FormReadonlyStringField'
50    archetype_name = 'Readonly String Field'
51    content_icon = 'StringField.gif'
52    typeDescription= 'A readonly string field'
53
54    def __init__(self, oid, **kwargs):
55        """ initialize class """
56
57        super(FGReadonlyStringField, self).__init__(oid, **kwargs)
58
59        # set a preconfigured field as an instance attribute
60        self.fgField = StringField('fg_string_field',
61            searchable=0,
62            required=0,
63            write_permission = View,
64            validators=('isNotTooLong',),
65            widget=ReadonlyStringWidget(),
66            )
67
68    def fgPrimeDefaults(self, request, contextObject=None):
69        super(FGReadonlyStringField, self).fgPrimeDefaults(request,
70            contextObject=contextObject)
71        editable = self.isEditable(contextObject)
72        if editable:
73            request.set('%s_editable' % self.fgField.__name__, '1')
74
75    def isEditable(self, context=None):
76        if self.getRawEditMode():
77            if context:
78                value = self.getEditMode(
79                    expression_context=getExprContext(self, context))
80            else:
81                value = self.getEditMode()
82            return value
83        return False
84
85registerATCT(FGReadonlyStringField, PROJECTNAME)
Note: See TracBrowser for help on using the repository browser.