def species_to_fix(ssn, binomial, author, create=False): if binomial.find(' ') == -1: return None binomial = utils.to_unicode(binomial) author = utils.to_unicode(author) gen_epithet, sp_epithet = binomial.split(' ', 1) return Species.retrieve_or_create( ssn, {'object': 'taxon', 'rank': 'species', 'ht-epithet': gen_epithet, 'epithet': sp_epithet, 'ht-rank': 'genus', 'author': author}, create=create)
def on_frame2_next(self, *args): "execute all that is selected in liststore2 and move to frame 3" self.on_frame_next(*args) tb = self.view.widgets.textbuffer3 tag_bold = tb.create_tag(None, weight=pango.WEIGHT_BOLD) tag_red = tb.create_tag(None, weight=pango.WEIGHT_BOLD, foreground=pango.Color("red")) tb.set_text("") for row in self.tick_off_list: if row[TO_PROCESS] is False: tb.insert_at_cursor("skipping %s\n" % (row[OLD_BINOMIAL] or row[NEW_BINOMIAL])) continue if row[OLD_BINOMIAL] == "": tb.insert_with_tags(tb.get_end_iter(), "new taxon %s" % row[NEW_BINOMIAL], tag_bold) obj = species_to_fix(self.session, row[NEW_BINOMIAL], row[AUTHORSHIP], create=True) else: if row[TAXON_STATUS] == "Synonym": accepted = species_to_fix( self.session, row[ACCEPTED_BINOMIAL], row[ACCEPTED_AUTHORSHIP], create=True ) else: accepted = None obj = species_to_fix(self.session, row[OLD_BINOMIAL], row[AUTHORSHIP], create=False) if obj is None: tb.insert_with_tags(tb.get_end_iter(), "bad taxon %s" % row[OLD_BINOMIAL], tag_bold, tag_red) continue tb.insert_with_tags(tb.get_end_iter(), "update taxon %s" % row[OLD_BINOMIAL], tag_bold) gen_epithet, sp_epithet = utils.to_unicode(row[NEW_BINOMIAL]).split(" ", 1) obj.genus.genus = gen_epithet obj.sp = sp_epithet if accepted: obj.accepted = accepted tb.insert_with_tags(tb.get_end_iter(), " %s\n" % row[AUTHORSHIP], tag_bold)
def default_completion_cell_data_func(column, renderer, model, treeiter, data=None): ''' the default completion cell data function for GenericEditorView.attach_completions ''' v = model[treeiter][0] renderer.set_property('markup', utils.to_unicode(v))
def species_to_fix(ssn, binomial, author, create=False): if binomial.find(" ") == -1: return None binomial = utils.to_unicode(binomial) author = utils.to_unicode(author) gen_epithet, sp_epithet = binomial.split(" ", 1) return Species.retrieve_or_create( ssn, { "object": "taxon", "rank": "species", "ht-epithet": gen_epithet, "epithet": sp_epithet, "ht-rank": "genus", "author": author, }, create=create, )
def next(self): row = self.reader.next() t = {} for k, v in row.iteritems(): if v == '': t[k] = None else: t[k] = utils.to_unicode(v, self.encoding) return t
def on_frame2_next(self, *args): 'execute all that is selected in liststore2 and move to frame 3' self.on_frame_next(*args) tb = self.view.widgets.textbuffer3 tag_bold = tb.create_tag(None, weight=pango.WEIGHT_BOLD) tag_red = tb.create_tag(None, weight=pango.WEIGHT_BOLD, foreground=pango.Color('red')) tb.set_text('') for row in self.tick_off_list: if row[TO_PROCESS] is False: tb.insert_at_cursor("skipping %s\n" % (row[OLD_BINOMIAL] or row[NEW_BINOMIAL])) continue if row[OLD_BINOMIAL] == '': tb.insert_with_tags(tb.get_end_iter(), "new taxon %s" % row[NEW_BINOMIAL], tag_bold) obj = species_to_fix(self.session, row[NEW_BINOMIAL], row[AUTHORSHIP], create=True) else: if row[TAXON_STATUS] == 'Synonym': accepted = species_to_fix(self.session, row[ACCEPTED_BINOMIAL], row[ACCEPTED_AUTHORSHIP], create=True) else: accepted = None obj = species_to_fix(self.session, row[OLD_BINOMIAL], row[AUTHORSHIP], create=False) if obj is None: tb.insert_with_tags(tb.get_end_iter(), "bad taxon %s" % row[OLD_BINOMIAL], tag_bold, tag_red) continue tb.insert_with_tags(tb.get_end_iter(), "update taxon %s" % row[OLD_BINOMIAL], tag_bold) gen_epithet, sp_epithet = utils.to_unicode( row[NEW_BINOMIAL]).split(' ', 1) obj.genus.genus = gen_epithet obj.sp = sp_epithet if accepted: obj.accepted = accepted tb.insert_with_tags(tb.get_end_iter(), " %s\n" % row[AUTHORSHIP], tag_bold)
def writerow(self, row): """ Write a row. If row is a dict then row.values() is written and therefore care should be taken to ensure that row.values() returns a consisten order. """ if isinstance(row, dict): row = row.values() t = [] for s in row: if s == None: t.append(None) else: t.append(utils.to_unicode(s, self.encoding)) self.writer.writerow(t)
def writerow(self, row): """ Write a row. If row is a dict then row.values() is written and therefore care should be taken to ensure that row.values() returns a consisten order. """ if isinstance(row, dict): row = row.values() t = [] for s in row: if s is None: t.append(None) else: t.append(utils.to_unicode(s, self.encoding)) self.writer.writerow(t)
def to_python(self, value): if value in (u'', '', None): return None return utils.to_unicode(value, self.encoding)
def to_python(self, value): if not value.strip(): return '' return utils.to_unicode(value, self.encoding)