def update(self, row):
        """
        Update the Picasa info page.

        :param: a Species instance
        """
        self._current_row = row
        token_meta = meta.get_default(utils.utf8(PICASA_TOKEN_KEY))
        if not token_meta:
            msg = _('Could not login to PicasaWeb account.')
            self.on_error(msg, species=row)
            return
        token = token_meta.value
	self.gd_client.SetClientLoginToken(token)
	tag = Species.str(row, markup=False, authors=False)
        self.set_busy()
        worker = populate_iconview(self.gd_client, self.iconview, tag)
        def on_done(*args):
            if not _exc_queue.empty():
                exc = _exc_queue.get()
                msg = 'Could not retrieve the photos.\n\n'
                if isinstance(exc, gdata.photos.service.GooglePhotosException):
                    msg += exc.message
                else:
                    msg += str(exc)
                gobject.idle_add(self.on_error, msg, row)
                return
            self.set_busy(False)
            model = self.iconview.get_model()
            if len(model) == 0:
                gobject.idle_add(self.status_box.set_text, _('No images'))
                gobject.idle_add(self.show_status_box)
            else:
                gobject.idle_add(self.hide_status_box)
        worker.connect('done', on_done, False)
Example #2
0
    def test_export_with_vernacular(self):
        "exporting one genus which is not an accepted name."

        ## precondition
        sola = Family(family='Solanaceae')
        brug = Genus(family=sola, genus=u'Brugmansia')
        arbo = Species(genus=brug, sp=u'arborea')
        vern = VernacularName(species=arbo,
                              language=u"es", name=u"Floripondio")
        self.session.add_all([sola, brug, arbo, vern])
        self.session.commit()

        ## action
        exporter = JSONExporter(MockView())
        exporter.view.selection = None
        exporter.selection_based_on = 'sbo_taxa'
        exporter.include_private = False
        exporter.filename = self.temp_path
        exporter.run()

        ## check
        result = json.load(open(self.temp_path))
        vern_from_json = [i for i in result
                          if i['object'] == 'vernacular_name']
        self.assertEquals(len(vern_from_json), 1)
        self.assertEquals(vern_from_json[0]['language'], 'es')
Example #3
0
    def test_import_ignores_id_updating(self):
        "importing taxon disregards id value if present (updating taxon)."
        previously = Species.retrieve_or_create(self.session,
                                                {'ht-epithet': u"Calopogon",
                                                 'epithet': u"tuberosus"}).id
        json_string = '[{"rank": "Species", "epithet": "tuberosus", '\
            '"ht-rank": "Genus", "ht-epithet": "Calopogon", "hybrid": false, '\
            '"id": 8}]'
        with open(self.temp_path, "w") as f:
            f.write(json_string)
        importer = JSONImporter(MockImportView())
        importer.filename = self.temp_path
        importer.on_btnok_clicked(None)

        self.session.commit()
        afterwards = Species.retrieve_or_create(self.session,
                                                {'ht-epithet': u"Calopogon",
                                                 'epithet': u"tuberosus"}).id
        self.assertEquals(previously, afterwards)
Example #4
0
 def test_import_existing_updates(self):
     "importing existing taxon updates it"
     json_string = '[{"rank": "Species", "epithet": "tuberosus", "ht-rank"'\
         ': "Genus", "ht-epithet": "Calopogon", "hybrid": false, "author"'\
         ': "Britton et al."}]'
     with open(self.temp_path, "w") as f:
         f.write(json_string)
     previously = Species.retrieve_or_create(
         self.session, {'ht-epithet': u"Calopogon",
                        'epithet': u"tuberosus"})
     self.assertEquals(previously.sp_author, None)
     importer = JSONImporter(MockImportView())
     importer.filename = self.temp_path
     importer.on_btnok_clicked(None)
     self.session.commit()
     afterwards = Species.retrieve_or_create(
         self.session, {'ht-epithet': u"Calopogon",
                        'epithet': u"tuberosus"})
     self.assertEquals(afterwards.sp_author, u"Britton et al.")
Example #5
0
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)
Example #6
0
 def test_export_none_is_empty(self):
     """
     Test exporting a None column exports a ''
     """
     species = Species(genus_id=1, sp='sp')
     self.assertTrue(species is not None)
     from tempfile import mkdtemp
     temp_path = mkdtemp()
     exporter = CSVExporter()
     exporter.start(temp_path)
     f = open(os.path.join(temp_path, 'species.txt'))
     reader = csv.DictReader(f, dialect=csv.excel)
     row = reader.next()
     self.assert_(row['cv_group'] == '')
Example #7
0
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)
Example #8
0
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,
    )
Example #9
0
 def setUp(self, *args):
     super(MakoFormatterTests, self).setUp()
     fctr = gctr = sctr = actr = pctr = 0
     for f in xrange(2):
         fctr += 1
         family = Family(id=fctr, epithet=u'fam%s' % fctr)
         self.session.add(family)
         for g in range(2):
             gctr += 1
             genus = Genus(id=gctr, family=family, epithet=u'gen%s' % gctr)
             self.session.add(genus)
             for s in range(2):
                 sctr += 1
                 sp = Species(id=sctr, genus=genus, epithet=u'sp%s' % sctr)
                 # TODO: why doesn't this geography, species
                 # distribution stuff seem to work
                 geo = Geography(id=sctr, name=u'Mexico%s' % sctr)
                 dist = SpeciesDistribution(geography_id=sctr)
                 sp.distribution.append(dist)
                 vn = VernacularName(id=sctr,
                                     species=sp,
                                     name=u'name%s' % sctr)
                 self.session.add_all([sp, geo, dist, vn])
                 for a in range(2):
                     actr += 1
                     acc = Accession(id=actr, species=sp, code=u'%s' % actr)
                     self.session.add(acc)
                     for p in range(2):
                         pctr += 1
                         loc = Location(id=pctr,
                                        code=u'%s' % pctr,
                                        name=u'site%s' % pctr)
                         plant = Plant(id=pctr,
                                       accession=acc,
                                       location=loc,
                                       code=u'%s' % pctr,
                                       quantity=1)
                         #debug('fctr: %s, gctr: %s, actr: %s, pctr: %s' \
                         #      % (fctr, gctr, actr, pctr))
                         self.session.add_all([loc, plant])
     self.session.commit()
Example #10
0
 def test_infopage(self):
     raise SkipTest('Not Implemented')
     from bauble.plugins.plants import Family, Genus, Species
     email = ''
     passwd = ''
     album = 'Plants'
     if email:
         token = picasa.get_auth_token(email, passwd)
         picasa.update_meta(email=email, album=album, token=token)
     f = Family(family=u'Orchidaceae')
     g = Genus(family=f, genus=u'Maxillaria')
     sp = Species(genus=g, sp=u'elatior')
     self.session.add_all([f, g, sp])
     self.session.commit()
     self.dialog = gtk.Dialog()
     self.dialog.set_size_request(250, 700)
     page = picasa.PicasaInfoPage()
     page.update(sp)
     self.dialog.vbox.pack_start(page)
     self.dialog.show_all()
     self.dialog.run()
Example #11
0
    def update(self, row):
        """
        Update the Picasa info page.

        :param: a Species instance
        """
        self._current_row = row
        token_meta = meta.get_default(utils.utf8(PICASA_TOKEN_KEY))
        if not token_meta:
            msg = _('Could not login to PicasaWeb account.')
            self.on_error(msg, species=row)
            return
        token = token_meta.value
        self.gd_client.SetClientLoginToken(token)
        tag = Species.str(row, markup=False, authors=False)
        self.set_busy()
        worker = populate_iconview(self.gd_client, self.iconview, tag)

        def on_done(*args):
            if not _exc_queue.empty():
                exc = _exc_queue.get()
                msg = 'Could not retrieve the photos.\n\n'
                if isinstance(exc, gdata.photos.service.GooglePhotosException):
                    msg += exc.message
                else:
                    msg += str(exc)
                gobject.idle_add(self.on_error, msg, row)
                return
            self.set_busy(False)
            model = self.iconview.get_model()
            if len(model) == 0:
                gobject.idle_add(self.status_box.set_text, _('No images'))
                gobject.idle_add(self.show_status_box)
            else:
                gobject.idle_add(self.hide_status_box)

        worker.connect('done', on_done, False)
Example #12
0
 def setUp(self):
     super(ReportTests, self).setUp()
     fctr = gctr = sctr = actr = pctr = 0
     for f in xrange(2):
         fctr += 1
         family = Family(id=fctr, epithet=u'fam%s' % fctr)
         self.session.add(family)
         for g in range(2):
             gctr += 1
             genus = Genus(id=gctr, family=family, epithet=u'gen%s' % gctr)
             self.session.add(genus)
             for s in range(2):
                 sctr += 1
                 sp = Species(id=sctr, genus=genus, epithet=u'sp%s' % sctr)
                 vn = VernacularName(id=sctr,
                                     species=sp,
                                     name=u'name%s' % sctr)
                 self.session.add_all([sp, vn])
                 for a in range(2):
                     actr += 1
                     acc = Accession(id=actr, species=sp, code=u'%s' % actr)
                     self.session.add(acc)
                     for p in range(2):
                         pctr += 1
                         loc = Location(id=pctr,
                                        code=u'%s' % pctr,
                                        name=u'site%s' % pctr)
                         plant = Plant(id=pctr,
                                       accession=acc,
                                       location=loc,
                                       code=u'%s' % pctr,
                                       quantity=1)
                         #debug('fctr: %s, gctr: %s, actr: %s, pctr: %s' \
                         #      % (fctr, gctr, actr, pctr))
                         self.session.add_all([loc, plant])
     self.session.commit()