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

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

CleanUp? code

File size: 3.8 KB
RevLine 
[2646]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
[2667]10from Products.DataGridField import DataGridField, DataGridWidget
11from Products.DataGridField.SelectColumn import SelectColumn
[2668]12from Products.DataGridField.Column import Column
[2667]13
[2646]14from quintagroup.gdocs.spreadsheet import spreadsheetMessageFactory as _
15from quintagroup.gdocs.spreadsheet.interfaces import IGSpreadsheet
[2688]16from quintagroup.gdocs.spreadsheet.interfaces import IGSpreadsheetDataProvider
[2646]17from quintagroup.gdocs.spreadsheet.config import PROJECTNAME
18
19GSpreadsheetSchema = schemata.ATContentTypeSchema.copy() + atapi.Schema((
20
[2649]21    atapi.StringField(
[2661]22        name = 'spreadsheet_id',
[2649]23        default='',
24        required = True,
[2659]25        languageIndependent=True,
[2649]26        storage=atapi.AnnotationStorage(),
27        widget = atapi.StringWidget(
28            label = _(
[2661]29                u'label_spreadsheet_id',
30                default=u'Spreadsheet ID'),
[2649]31            description=_(
[2661]32                u'help_spreadsheet_id',
33                default=u"Please input spreadsheet ID."),
[2649]34            size = 40,
35        ),
36    ),
37
[2661]38    atapi.StringField(
39        name = 'worksheet_id',
[2649]40        default='',
41        required = True,
[2659]42        languageIndependent=True,
[2649]43        storage=atapi.AnnotationStorage(),
[2661]44        widget = atapi.StringWidget(
[2649]45            label = _(
[2661]46                u'label_worksheet_id',
47                default=u'Worksheet ID'),
[2649]48            description=_(
[2661]49                u'help_worksheet_id',
50                default=u"Please input worksheet ID."),
51            size = 40,
[2649]52        ),
53    ),
54
[2667]55    DataGridField(
[2668]56        name='order_columns',
[2667]57        searchable = True,
58        languageIndependent=True,
59        storage=atapi.AnnotationStorage(),
[2668]60        columns=("column_key", "column_title"),
[2667]61        widget = DataGridWidget(
62            label = _(
[2668]63                u'label_order_column',
64                default=u'Ordering columns'),
[2667]65            description=_(
[2668]66                u'help_order_column',
67                default=u"Choose keys of columns and enter them titles"),
[2667]68            columns={
[2668]69                'column_key' : SelectColumn("Key of column", vocabulary="getKeyColumnVocabulary"),
70                'column_title' : Column("Title of column"),
[2667]71            },
72        ),
73    ),
74
[2646]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):
[2756]88    """Lets you select google spreadsheet id, worksheet id,
89    choose keys of columns and define them title
90    """
[2646]91    implements(IGSpreadsheet)
92
93    meta_type = "GSpreadsheet"
94    schema = GSpreadsheetSchema
95
96    title = atapi.ATFieldProperty('title')
97    description = atapi.ATFieldProperty('description')
[2661]98    spreadsheet_id = atapi.ATFieldProperty('spreadsheet_id')
99    worksheet_id = atapi.ATFieldProperty('worksheet_id')
[2668]100    order_columns = atapi.ATFieldProperty('order_columns')
[2646]101
102    # -*- Your ATSchema to Python Property Bridges Here ... -*-
103
[2668]104    def getKeyColumnVocabulary(self):
105        """ Get a list of keys of columns """
[2667]106        return atapi.DisplayList(
[2668]107            ([(t, t) for t in self.all_keys_columns])
[2667]108        )
109
[2688]110    @property
111    def all_keys_columns(self):
112        if self.spreadsheet_id and self.worksheet_id:
[2698]113            return IGSpreadsheetDataProvider(self).getWorksheetColumnsInfo()
[2688]114        return []
115
[2646]116atapi.registerType(GSpreadsheet, PROJECTNAME)
Note: See TracBrowser for help on using the repository browser.