def taxa(request, scientific_name=None): getdict = dict(request.GET.items()) # call items() to avoid lists kwargs = {} for k, v in getdict.items(): kwargs[str(k)] = v try: species = botany.query_species(**kwargs) except models.Character.DoesNotExist: return rc.NOT_FOUND if not scientific_name: # Only return character values for single item lookup, keep the # result list simple listing = [_simple_taxon(s) for s in species.all()] return jsonify({ 'items': listing, 'label': 'scientific_name', 'identifier': 'scientific_name' }) elif species.exists(): try: taxon = species.filter(scientific_name=scientific_name)[0] except IndexError: # A taxon wasn't returned from the database. return rc.NOT_FOUND # Return full taxon with characters for single item query return jsonify(_taxon_with_chars(taxon)) return jsonify({})
def test_query_species(self): queried = botany.query_species(scientific_name='Felis cat').all() self.assert_(len(queried) == 1) self.try_query([self.fox], color='red') self.try_query([self.cat, self.rabbit], color='gray') self.try_query([], color='chartreuse') self.try_query([self.fox, self.cat], pile='carnivores') self.try_query([self.cat, self.rabbit], pile='pets') self.try_query([self.fox], pile='carnivores', color='red') self.try_query([], pile='carnivores', color='chartreuse') self.try_query([self.fox, self.cat, self.rabbit], pilegroup='pilegroup1') self.try_query([], pilegroup='pilegroup2') self.try_query([self.cat], pilegroup='pilegroup1', color='orange') self.try_query([], pilegroup='pilegroup2', color='orange') self.try_query([self.fox, self.cat], pile='carnivores', pilegroup='pilegroup1') self.try_query([], pile='carnivores', pilegroup='pilegroup2') self.try_query([self.cat], genus='Felis') self.try_query([self.fox], family='Canidae') self.try_query([], genus='Kooky')
def taxa(request, scientific_name=None): getdict = dict(request.GET.items()) # call items() to avoid lists kwargs = {} for k, v in getdict.items(): kwargs[str(k)] = v try: species = botany.query_species(**kwargs) except models.Character.DoesNotExist: return rc.NOT_FOUND if not scientific_name: # Only return character values for single item lookup, keep the # result list simple listing = [_simple_taxon(s) for s in species.all()] return jsonify({'items': listing, 'label': 'scientific_name', 'identifier': 'scientific_name'}) elif species.exists(): try: taxon = species.filter(scientific_name=scientific_name)[0] except IndexError: # A taxon wasn't returned from the database. return rc.NOT_FOUND # Return full taxon with characters for single item query return jsonify(_taxon_with_chars(taxon)) return jsonify({})
def taxa_count(request): kwargs = {} for k, v in list(request.GET.items()): kwargs[str(k)] = v try: species = botany.query_species(**kwargs) except models.Character.DoesNotExist: return rc.NOT_FOUND matched = species.count() return jsonify({'matched': matched, 'excluded': models.Taxon.objects.count() - matched})
def taxa_count(request): kwargs = {} for k, v in request.GET.items(): kwargs[str(k)] = v try: species = botany.query_species(**kwargs) except models.Character.DoesNotExist: return rc.NOT_FOUND matched = species.count() return jsonify({'matched': matched, 'excluded': models.Taxon.objects.count() - matched})
def try_query(self, result, *args, **kw): result_set = set(result) real_result_set = set(botany.query_species(*args, **kw)) self.assertEqual(result_set, real_result_set)