source: products/quintagroup.gdocs.spreadsheet/trunk/quintagroup/gdocs/spreadsheet/content/gspreadsheet.py @ 2668

Last change on this file since 2668 was 2668, checked in by liebster, 14 years ago

Added field for define title of column

File size: 3.5 KB
Line 
1"""Definition of the GSpreadsheet content type
2"""
3
4from zope.interface import implements, directlyProvides
5
6from Products.Archetypes import atapi
7from Products.ATContentTypes.content import base
8from Products.ATContentTypes.content import schemata
9
10from Products.DataGridField import DataGridField, DataGridWidget
11from Products.DataGridField.SelectColumn import SelectColumn
12from Products.DataGridField.Column import Column
13
14from quintagroup.gdocs.spreadsheet import spreadsheetMessageFactory as _
15from quintagroup.gdocs.spreadsheet.interfaces import IGSpreadsheet
16from quintagroup.gdocs.spreadsheet.config import PROJECTNAME
17
18GSpreadsheetSchema = schemata.ATContentTypeSchema.copy() + atapi.Schema((
19
20    atapi.StringField(
21        name = 'spreadsheet_id',
22        default='',
23        required = True,
24        languageIndependent=True,
25        storage=atapi.AnnotationStorage(),
26        widget = atapi.StringWidget(
27            label = _(
28                u'label_spreadsheet_id',
29                default=u'Spreadsheet ID'),
30            description=_(
31                u'help_spreadsheet_id',
32                default=u"Please input spreadsheet ID."),
33            size = 40,
34        ),
35    ),
36
37    atapi.StringField(
38        name = 'worksheet_id',
39        default='',
40        required = True,
41        languageIndependent=True,
42        storage=atapi.AnnotationStorage(),
43        widget = atapi.StringWidget(
44            label = _(
45                u'label_worksheet_id',
46                default=u'Worksheet ID'),
47            description=_(
48                u'help_worksheet_id',
49                default=u"Please input worksheet ID."),
50            size = 40,
51        ),
52    ),
53
54    DataGridField(
55        name='order_columns',
56        searchable = True,
57        languageIndependent=True,
58        storage=atapi.AnnotationStorage(),
59        columns=("column_key", "column_title"),
60        widget = DataGridWidget(
61            label = _(
62                u'label_order_column',
63                default=u'Ordering columns'),
64            description=_(
65                u'help_order_column',
66                default=u"Choose keys of columns and enter them titles"),
67            columns={
68                'column_key' : SelectColumn("Key of column", vocabulary="getKeyColumnVocabulary"),
69                'column_title' : Column("Title of column"),
70            },
71        ),
72    ),
73
74    # -*- Your Archetypes field definitions here ... -*-
75
76))
77
78# Set storage on fields copied from ATContentTypeSchema, making sure
79# they work well with the python bridge properties.
80
81GSpreadsheetSchema['title'].storage = atapi.AnnotationStorage()
82GSpreadsheetSchema['description'].storage = atapi.AnnotationStorage()
83
84schemata.finalizeATCTSchema(GSpreadsheetSchema, moveDiscussion=False)
85
86class GSpreadsheet(base.ATCTContent):
87    """ Lets you select google spreadsheet id, worksheet id, choose keys of columns and define them title """
88    implements(IGSpreadsheet)
89
90    meta_type = "GSpreadsheet"
91    schema = GSpreadsheetSchema
92
93    all_keys_columns = []
94    title = atapi.ATFieldProperty('title')
95    description = atapi.ATFieldProperty('description')
96    spreadsheet_id = atapi.ATFieldProperty('spreadsheet_id')
97    worksheet_id = atapi.ATFieldProperty('worksheet_id')
98    order_columns = atapi.ATFieldProperty('order_columns')
99
100    # -*- Your ATSchema to Python Property Bridges Here ... -*-
101
102    def getKeyColumnVocabulary(self):
103        """ Get a list of keys of columns """
104        return atapi.DisplayList(
105            ([(t, t) for t in self.all_keys_columns])
106        )
107
108atapi.registerType(GSpreadsheet, PROJECTNAME)
Note: See TracBrowser for help on using the repository browser.