[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 |
---|
[2688] | 16 | from quintagroup.gdocs.spreadsheet.interfaces import IGSpreadsheetDataProvider |
---|
[2646] | 17 | from quintagroup.gdocs.spreadsheet.config import PROJECTNAME |
---|
| 18 | |
---|
| 19 | GSpreadsheetSchema = 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 | |
---|
| 82 | GSpreadsheetSchema['title'].storage = atapi.AnnotationStorage() |
---|
| 83 | GSpreadsheetSchema['description'].storage = atapi.AnnotationStorage() |
---|
| 84 | |
---|
| 85 | schemata.finalizeATCTSchema(GSpreadsheetSchema, moveDiscussion=False) |
---|
| 86 | |
---|
| 87 | class GSpreadsheet(base.ATCTContent): |
---|
[2668] | 88 | """ Lets you select google spreadsheet id, worksheet id, choose keys of columns and define them title """ |
---|
[2646] | 89 | implements(IGSpreadsheet) |
---|
| 90 | |
---|
| 91 | meta_type = "GSpreadsheet" |
---|
| 92 | schema = GSpreadsheetSchema |
---|
| 93 | |
---|
| 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 | |
---|
[2688] | 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 | |
---|
[2646] | 114 | atapi.registerType(GSpreadsheet, PROJECTNAME) |
---|