Changeset 2668 in products


Ignore:
Timestamp:
Jul 13, 2010 6:49:11 PM (14 years ago)
Author:
liebster
Message:

Added field for define title of column

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

Legend:

Unmodified
Added
Removed
  • quintagroup.gdocs.spreadsheet/trunk/quintagroup/gdocs/spreadsheet/browser/viewworksheetview.py

    r2667 r2668  
    5252        """ 
    5353        """ 
     54        table = '' 
    5455        feed = self.getFeed(ssh_id, wsh_id, startrow_idx) 
    5556        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]) 
    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 = '' 
     57            # akc is a list of keys of all columns. The context is GSpreadsheet content type 
     58            akc = self.context.all_keys_columns 
     59            # key_title_columns is list of tuples with two elements (column_key, column_title or column_key) 
     60            key_title_columns = [(e['column_key'], e['column_title'] or e['column_key']) 
     61                for e in self.context.order_columns if e['column_key'] in akc] 
     62            if key_title_columns: 
     63                # Prepare table 
     64                table = "<table id=\"sshwsh\">" 
     65                table += "<tr>" 
     66                table += ''.join(["<th>%s</th>" % el[1] for el in key_title_columns]) 
     67                table += "</tr>" 
     68                for i, entry in enumerate(feed.entry): 
     69                    if i >= startrow_idx: 
     70                        td_row = "<tr>" 
     71                        for key in zip(*key_title_columns)[0]: 
     72                            td_row += "<td>%s</td>" \ 
     73                                % (not (entry.custom[key].text == 'None') and entry.custom[key].text or '') 
     74                        td_row += "</tr>\n" 
     75                        table += td_row 
     76                table += "</table>" 
    7577        return table 
    7678 
     
    8486        try: 
    8587            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 [] 
     88            self.context.all_keys_columns = len(feed.entry) and feed.entry[0].custom.keys() or [] 
    8789        except Exception: 
    8890            logException('GetListFeed function call: ' 
  • quintagroup.gdocs.spreadsheet/trunk/quintagroup/gdocs/spreadsheet/content/gspreadsheet.py

    r2667 r2668  
    1010from Products.DataGridField import DataGridField, DataGridWidget 
    1111from Products.DataGridField.SelectColumn import SelectColumn 
     12from Products.DataGridField.Column import Column 
    1213 
    1314from quintagroup.gdocs.spreadsheet import spreadsheetMessageFactory as _ 
     
    5253 
    5354    DataGridField( 
    54         name='title_column', 
     55        name='order_columns', 
    5556        searchable = True, 
    5657        languageIndependent=True, 
    5758        storage=atapi.AnnotationStorage(), 
    58         columns=("select_title",), 
     59        columns=("column_key", "column_title"), 
    5960        widget = DataGridWidget( 
    6061            label = _( 
    61                 u'label_title_column', 
    62                 default=u'Titles of columns'), 
     62                u'label_order_column', 
     63                default=u'Ordering columns'), 
    6364            description=_( 
    64                 u'help_title_column', 
    65                 default=u"Choose titles of columns"), 
     65                u'help_order_column', 
     66                default=u"Choose keys of columns and enter them titles"), 
    6667            columns={ 
    67                 'select_title' : SelectColumn("Titles of columns", vocabulary="getTitleColumnVocabulary"), 
     68                'column_key' : SelectColumn("Key of column", vocabulary="getKeyColumnVocabulary"), 
     69                'column_title' : Column("Title of column"), 
    6870            }, 
    6971        ), 
     
    8385 
    8486class GSpreadsheet(base.ATCTContent): 
    85     """ Lets you select google spreadsheet worksheet id and choose title of columns """ 
     87    """ Lets you select google spreadsheet id, worksheet id, choose keys of columns and define them title """ 
    8688    implements(IGSpreadsheet) 
    8789 
     
    8991    schema = GSpreadsheetSchema 
    9092 
    91     order_columns = [] 
     93    all_keys_columns = [] 
    9294    title = atapi.ATFieldProperty('title') 
    9395    description = atapi.ATFieldProperty('description') 
    9496    spreadsheet_id = atapi.ATFieldProperty('spreadsheet_id') 
    9597    worksheet_id = atapi.ATFieldProperty('worksheet_id') 
    96     title_column = atapi.ATFieldProperty('title_column') 
     98    order_columns = atapi.ATFieldProperty('order_columns') 
    9799 
    98100    # -*- Your ATSchema to Python Property Bridges Here ... -*- 
    99101 
    100     def getTitleColumnVocabulary(self): 
    101         """ Get a list of titles of columns """ 
     102    def getKeyColumnVocabulary(self): 
     103        """ Get a list of keys of columns """ 
    102104        return atapi.DisplayList( 
    103             ([('%s'%i, t) for i,t in enumerate(self.order_columns)]) 
     105            ([(t, t) for t in self.all_keys_columns]) 
    104106        ) 
    105107 
Note: See TracChangeset for help on using the changeset viewer.