Changeset 2667 in products for quintagroup.gdocs.spreadsheet
- Timestamp:
- Jul 13, 2010 3:47:05 PM (14 years ago)
- Location:
- quintagroup.gdocs.spreadsheet/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.gdocs.spreadsheet/trunk/quintagroup/gdocs/spreadsheet/__init__.py
r2665 r2667 1 1 """Main product initializer 2 2 """ 3 import sys 3 4 import logging 4 5 -
quintagroup.gdocs.spreadsheet/trunk/quintagroup/gdocs/spreadsheet/browser/viewworksheetview.py
r2666 r2667 10 10 from gdata.spreadsheet.service import SpreadsheetsService 11 11 from gdata.spreadsheet.service import DocumentQuery as shDocumentQuery 12 from gdata.spreadsheet import SpreadsheetsListFeed 12 13 13 14 from quintagroup.gdocs.spreadsheet import spreadsheetMessageFactory as _ 14 15 from quintagroup.gdocs.spreadsheet import logException, logger 15 from quintagroup.gdocs.spreadsheet.config import ORDER_COLUMNS16 16 17 17 … … 49 49 50 50 @memoize_contextless 51 def renderWorksheet(self, ssh_id="", 52 wsh_id='', startrow_idx=0): 51 def renderWorksheet(self, ssh_id="", wsh_id='', startrow_idx=0): 53 52 """ 54 53 """ 54 feed = self.getFeed(ssh_id, wsh_id, startrow_idx) 55 if isinstance(feed, SpreadsheetsListFeed): 56 indx_keys = filter(None, [elem['select_title'] for elem in self.context.title_column]) 57 titles_columns = filter(None, [self.context.order_columns[int(i)] for i in indx_keys]) 55 58 59 # Prepare table 60 table = "<table id=\"sshwsh\">" 61 table += "<tr>" 62 table += ''.join(["<th>%s</th>" % key for key in titles_columns]) 63 table += "</tr>" 64 for i, entry in enumerate(feed.entry): 65 if i+1 > startrow_idx: 66 td_row = "<tr>" 67 for key in titles_columns: 68 td_row += "<td>%s</td>" \ 69 % (not (entry.custom[key].text == 'None') and entry.custom[key].text or '') 70 td_row += "</tr>\n" 71 table += td_row 72 table += "</table>" 73 else: 74 table = '' 75 return table 76 77 def getFeed(self, ssh_id="", wsh_id='', startrow_idx=0): 78 """ Get SpreadsheetsListFeed 79 """ 56 80 # Authorization on spreadsheets.google.com 57 81 gauth = queryUtility(IGAuthUtility) 58 82 self.sh_client = SpreadsheetsService(email=gauth.email, password=gauth.password) 59 sh_client = self.sh_client 60 sh_client.ProgrammaticLogin() 61 83 self.sh_client.ProgrammaticLogin() 62 84 try: 63 feed = sh_client.GetListFeed(ssh_id, wksht_id=wsh_id, query=self.query) 85 feed = self.sh_client.GetListFeed(ssh_id, wksht_id=wsh_id, query=self.query) 86 self.context.order_columns = len(feed.entry) and feed.entry[0].custom.keys() or [] 64 87 except Exception: 65 88 logException('GetListFeed function call: ' 66 'key=%s, wksht_id=%s' % (ssh_id, wsh_id)) 67 return "" 68 69 # Prepare table 70 table = "<table id=\"sshwsh\">" 71 table += "<tr>" 72 table += ''.join(["<th>%s</th>" % key for key in ORDER_COLUMNS]) 73 table += "</tr>" 74 75 for i, entry in enumerate(feed.entry): 76 if i+1 > startrow_idx: 77 td_row = "<tr>" 78 for key in ORDER_COLUMNS: 79 td_row += "<td>%s</td>" \ 80 % (not (entry.custom[key].text == 'None') and entry.custom[key].text or '') 81 td_row += "</tr>\n" 82 table += td_row 83 84 table += "</table>" 85 return table 89 'key=%s, wksht_id=%s' % (ssh_id, wsh_id), self.context) 90 feed = None 91 return feed -
quintagroup.gdocs.spreadsheet/trunk/quintagroup/gdocs/spreadsheet/content/gspreadsheet.py
r2661 r2667 7 7 from Products.ATContentTypes.content import base 8 8 from Products.ATContentTypes.content import schemata 9 10 from Products.DataGridField import DataGridField, DataGridWidget 11 from Products.DataGridField.SelectColumn import SelectColumn 9 12 10 13 from quintagroup.gdocs.spreadsheet import spreadsheetMessageFactory as _ … … 48 51 ), 49 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 50 72 # -*- Your Archetypes field definitions here ... -*- 51 73 … … 61 83 62 84 class GSpreadsheet(base.ATCTContent): 63 """ Lets you select google spreadsheet and worksheet id"""85 """ Lets you select google spreadsheet worksheet id and choose title of columns """ 64 86 implements(IGSpreadsheet) 65 87 … … 67 89 schema = GSpreadsheetSchema 68 90 91 order_columns = [] 69 92 title = atapi.ATFieldProperty('title') 70 93 description = atapi.ATFieldProperty('description') 71 94 spreadsheet_id = atapi.ATFieldProperty('spreadsheet_id') 72 95 worksheet_id = atapi.ATFieldProperty('worksheet_id') 96 title_column = atapi.ATFieldProperty('title_column') 73 97 74 98 # -*- Your ATSchema to Python Property Bridges Here ... -*- 75 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 76 106 atapi.registerType(GSpreadsheet, PROJECTNAME) -
quintagroup.gdocs.spreadsheet/trunk/setup.py
r2651 r2667 58 58 'gdata', 59 59 'quintagroup.gauth', 60 'Products.DataGridField', 60 61 # -*- Extra requirements: -*- 61 62 ], … … 67 68 [z3c.autoinclude.plugin] 68 69 target = plone 70 71 [distutils.setup_keywords] 72 paster_plugins = setuptools.dist:assert_string_list 73 74 [egg_info.writers] 75 paster_plugins.txt = setuptools.command.egg_info:write_arg 69 76 """, 77 #paster_plugins = ["ZopeSkel"], 70 78 )
Note: See TracChangeset
for help on using the changeset viewer.