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

Last change on this file since 2688 was 2688, checked in by mylan, 14 years ago

Updated GSpreadsheet content type for using IGSpreadsheetDataProvider adapter for getting all_keys_columns

File size: 3.8 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.interfaces import IGSpreadsheetDataProvider
17from quintagroup.gdocs.spreadsheet.config import PROJECTNAME
18
19GSpreadsheetSchema = schemata.ATContentTypeSchema.copy() + atapi.Schema((
20
21    atapi.StringField(
22        name = 'spreadsheet_id',
23        default='',
24        required = True,
25        languageIndependent=True,
26        storage=atapi.AnnotationStorage(),
27        widget = atapi.StringWidget(
28            label = _(
29                u'label_spreadsheet_id',
30                default=u'Spreadsheet ID'),
31            description=_(
32                u'help_spreadsheet_id',
33                default=u"Please input spreadsheet ID."),
34            size = 40,
35        ),
36    ),
37
38    atapi.StringField(
39        name = 'worksheet_id',
40        default='',
41        required = True,
42        languageIndependent=True,
43        storage=atapi.AnnotationStorage(),
44        widget = atapi.StringWidget(
45            label = _(
46                u'label_worksheet_id',
47                default=u'Worksheet ID'),
48            description=_(
49                u'help_worksheet_id',
50                default=u"Please input worksheet ID."),
51            size = 40,
52        ),
53    ),
54
55    DataGridField(
56        name='order_columns',
57        searchable = True,
58        languageIndependent=True,
59        storage=atapi.AnnotationStorage(),
60        columns=("column_key", "column_title"),
61        widget = DataGridWidget(
62            label = _(
63                u'label_order_column',
64                default=u'Ordering columns'),
65            description=_(
66                u'help_order_column',
67                default=u"Choose keys of columns and enter them titles"),
68            columns={
69                'column_key' : SelectColumn("Key of column", vocabulary="getKeyColumnVocabulary"),
70                'column_title' : Column("Title of column"),
71            },
72        ),
73    ),
74
75    # -*- Your Archetypes field definitions here ... -*-
76
77))
78
79# Set storage on fields copied from ATContentTypeSchema, making sure
80# they work well with the python bridge properties.
81
82GSpreadsheetSchema['title'].storage = atapi.AnnotationStorage()
83GSpreadsheetSchema['description'].storage = atapi.AnnotationStorage()
84
85schemata.finalizeATCTSchema(GSpreadsheetSchema, moveDiscussion=False)
86
87class GSpreadsheet(base.ATCTContent):
88    """ Lets you select google spreadsheet id, worksheet id, choose keys of columns and define them title """
89    implements(IGSpreadsheet)
90
91    meta_type = "GSpreadsheet"
92    schema = GSpreadsheetSchema
93
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
108    @property
109    def all_keys_columns(self):
110        if self.spreadsheet_id and self.worksheet_id:
111            return IGSpreadsheetDataProvider(self).getWorksheetColumnsInfo(maxr='1', minr='1')
112        return []
113
114atapi.registerType(GSpreadsheet, PROJECTNAME)
Note: See TracBrowser for help on using the repository browser.