Changeset 2667 in products


Ignore:
Timestamp:
Jul 13, 2010 3:47:05 PM (9 years ago)
Author:
liebster
Message:

Added choose the titles of columns by contentype

Location:
quintagroup.gdocs.spreadsheet/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.gdocs.spreadsheet/trunk/quintagroup/gdocs/spreadsheet/__init__.py

    r2665 r2667  
    11"""Main product initializer 
    22""" 
     3import sys 
    34import logging 
    45 
  • quintagroup.gdocs.spreadsheet/trunk/quintagroup/gdocs/spreadsheet/browser/viewworksheetview.py

    r2666 r2667  
    1010from gdata.spreadsheet.service import SpreadsheetsService 
    1111from gdata.spreadsheet.service import DocumentQuery as shDocumentQuery 
     12from gdata.spreadsheet import SpreadsheetsListFeed 
    1213 
    1314from quintagroup.gdocs.spreadsheet import spreadsheetMessageFactory as _ 
    1415from quintagroup.gdocs.spreadsheet import logException, logger 
    15 from quintagroup.gdocs.spreadsheet.config import ORDER_COLUMNS 
    1616 
    1717 
     
    4949 
    5050    @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): 
    5352        """ 
    5453        """ 
     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]) 
    5558 
     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        """ 
    5680        # Authorization on spreadsheets.google.com 
    5781        gauth = queryUtility(IGAuthUtility) 
    5882        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() 
    6284        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 [] 
    6487        except Exception: 
    6588            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  
    77from Products.ATContentTypes.content import base 
    88from Products.ATContentTypes.content import schemata 
     9 
     10from Products.DataGridField import DataGridField, DataGridWidget 
     11from Products.DataGridField.SelectColumn import SelectColumn 
    912 
    1013from quintagroup.gdocs.spreadsheet import spreadsheetMessageFactory as _ 
     
    4851    ), 
    4952 
     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 
    5072    # -*- Your Archetypes field definitions here ... -*- 
    5173 
     
    6183 
    6284class 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 """ 
    6486    implements(IGSpreadsheet) 
    6587 
     
    6789    schema = GSpreadsheetSchema 
    6890 
     91    order_columns = [] 
    6992    title = atapi.ATFieldProperty('title') 
    7093    description = atapi.ATFieldProperty('description') 
    7194    spreadsheet_id = atapi.ATFieldProperty('spreadsheet_id') 
    7295    worksheet_id = atapi.ATFieldProperty('worksheet_id') 
     96    title_column = atapi.ATFieldProperty('title_column') 
    7397 
    7498    # -*- Your ATSchema to Python Property Bridges Here ... -*- 
    7599 
     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 
    76106atapi.registerType(GSpreadsheet, PROJECTNAME) 
  • quintagroup.gdocs.spreadsheet/trunk/setup.py

    r2651 r2667  
    5858                        'gdata', 
    5959                        'quintagroup.gauth', 
     60                        'Products.DataGridField', 
    6061                        # -*- Extra requirements: -*- 
    6162                        ], 
     
    6768      [z3c.autoinclude.plugin] 
    6869      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 
    6976      """, 
     77      #paster_plugins = ["ZopeSkel"], 
    7078      ) 
Note: See TracChangeset for help on using the changeset viewer.