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

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

Added choose the titles of columns by contentype

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