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