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

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

CleanUp? code

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,
89    choose keys of columns and define them title
90    """
91    implements(IGSpreadsheet)
92
93    meta_type = "GSpreadsheet"
94    schema = GSpreadsheetSchema
95
96    title = atapi.ATFieldProperty('title')
97    description = atapi.ATFieldProperty('description')
98    spreadsheet_id = atapi.ATFieldProperty('spreadsheet_id')
99    worksheet_id = atapi.ATFieldProperty('worksheet_id')
100    order_columns = atapi.ATFieldProperty('order_columns')
101
102    # -*- Your ATSchema to Python Property Bridges Here ... -*-
103
104    def getKeyColumnVocabulary(self):
105        """ Get a list of keys of columns """
106        return atapi.DisplayList(
107            ([(t, t) for t in self.all_keys_columns])
108        )
109
110    @property
111    def all_keys_columns(self):
112        if self.spreadsheet_id and self.worksheet_id:
113            return IGSpreadsheetDataProvider(self).getWorksheetColumnsInfo()
114        return []
115
116atapi.registerType(GSpreadsheet, PROJECTNAME)
Note: See TracBrowser for help on using the repository browser.