Example #1
0
 def _convert_value(self, row):
     assert isinstance(row, dict) or hasattr(row, 'items')
     self._create_columns(row.keys())
     data = {}
     for k, v in row.items():
         if v is None:
             v = ''
         data[normalize_header(k)] = unicode(v)
     return data
Example #2
0
 def _convert_value(self, row):
     assert isinstance(row, dict) or hasattr(row, 'items')
     self._create_columns(row.keys())
     data = {}
     for k, v in row.items():
         if v is None:
             v = ''
         data[normalize_header(k)] = unicode(v)
     return data
Example #3
0
 def headers(self):
     """ Return the name of all headers currently defined for the
     table. """
     if self._headers is None:
         query = CellQuery()
         query.max_row = '1'
         feed = self._service.GetCellsFeed(self._ss.id, self.id,
                                           query=query)
         self._headers = feed.entry
     return [normalize_header(h.cell.text) for h in self._headers]
Example #4
0
 def update(self, row, keys=[]):
     changed = 0
     data = self._convert_value(row)
     keys = [normalize_header(k) for k in keys]
     filters = {k: data.get(k) for k in keys}
     for entry in self._find_entries(**filters):
         row = self._entry_data(entry)
         row.update(data)
         self._service.UpdateRow(entry, row)
         changed += 1
     return changed
Example #5
0
 def headers(self):
     """ Return the name of all headers currently defined for the
     table. """
     if self._headers is None:
         query = CellQuery()
         query.max_row = '1'
         feed = self._service.GetCellsFeed(self._ss.id,
                                           self.id,
                                           query=query)
         self._headers = feed.entry
     return [normalize_header(h.cell.text) for h in self._headers]
Example #6
0
 def update(self, row, keys=[]):
     changed = 0
     data = self._convert_value(row)
     keys = [normalize_header(k) for k in keys]
     filters = {k: data.get(k) for k in keys}
     for entry in self._find_entries(**filters):
         row = self._entry_data(entry)
         row.update(data)
         self._service.UpdateRow(entry, row)
         changed += 1
     return changed
Example #7
0
 def _find_entries(self, _query=None, **kwargs):
     query = None
     if _query is not None:
         query = ListQuery()
         query.sq = _query
     elif len(kwargs.keys()):
         text = []
         for k, v in kwargs.items():
             k = normalize_header(k)
             v = json.dumps(unicode(v))
             text.append("%s = %s" % (k, v))
         query = ListQuery()
         query.sq = ' and '.join(text)
     feed = self._service.GetListFeed(self._ss.id, wksht_id=self.id,
                                      query=query)
     return feed.entry
Example #8
0
 def _find_entries(self, _query=None, **kwargs):
     query = None
     if _query is not None:
         query = ListQuery()
         query.sq = _query
     elif len(kwargs.keys()):
         text = []
         for k, v in kwargs.items():
             k = normalize_header(k)
             v = json.dumps(unicode(v))
             text.append("%s = %s" % (k, v))
         query = ListQuery()
         query.sq = ' and '.join(text)
     feed = self._service.GetListFeed(self._ss.id,
                                      wksht_id=self.id,
                                      query=query)
     return feed.entry
Example #9
0
 def _create_columns(self, columns):
     columns = {normalize_header(c): c for c in columns}
     # existing = set(self.headers)
     for column in set(columns.keys()).difference(self.headers):
         self._add_column(columns[column], column)
     self._headers = None
Example #10
0
 def _create_columns(self, columns):
     columns = {normalize_header(c): c for c in columns}
     # existing = set(self.headers)
     for column in set(columns.keys()).difference(self.headers):
         self._add_column(columns[column], column)
     self._headers = None