diff --git a/nextgisbio/models/cards.py b/nextgisbio/models/cards.py index c0f7ae85..05835a2c 100644 --- a/nextgisbio/models/cards.py +++ b/nextgisbio/models/cards.py @@ -76,12 +76,7 @@ def as_join_list(taxon_list=None, header=True): ''' dbsession = DBSession() - if taxon_list: # выдать карточки-потомки определенных таксонов - species = Taxon.species_by_taxon(taxon_list) - species_id = [t['id'] for t in species] - else: # выдать все карточки - species = dbsession.query(Taxon).all() - species_id = [t.id for t in species if t.is_last_taxon()] + qs = ''' SELECT cards.id, @@ -150,9 +145,14 @@ def as_join_list(taxon_list=None, header=True): inforesources ON cards.inforesources = inforesources.id LEFT OUTER JOIN coord_type ON cards.coord_type = coord_type.id - WHERE - cards.species IN (%s) - ''' % ", ".join([str(num) for num in species_id]) + ''' + + if taxon_list: + species = Taxon.species_by_taxon(taxon_list) + species_id = [t['id'] for t in species] + qs_where = ' WHERE cards.species IN (%s)' % ", ".join([str(num) for num in species_id]) + qs += qs_where + cards = dbsession.query(Cards).from_statement(qs).all() dbsession.close() diff --git a/nextgisbio/views/cards.py b/nextgisbio/views/cards.py index 9c52850c..2eca24cc 100644 --- a/nextgisbio/views/cards.py +++ b/nextgisbio/views/cards.py @@ -94,16 +94,16 @@ def cards_download(request): return Response() try: - #taxon_list -- список, аналогичный querystring в points_text + # taxon_list -- список, аналогичный querystring в points_text # (taxon_id1,taxon_id2) taxons = request.params['taxon_list'] - if taxons == 'root': - taxon_list = None - elif taxons != '': + if taxons != '': taxons = urllib.unquote(taxons) taxons = taxons.split(',') taxons = [t.split('_') for t in taxons] - taxon_list = [id for (t,id) in taxons] + taxon_list = [id for (t, id) in taxons] + if any('root' in s for s in taxon_list): + taxon_list = None else: taxon_list = None except KeyError: @@ -150,8 +150,8 @@ def cards_download(request): print "Creating Name field failed.\n" #Заполним данными - lon_idx, lat_idx = 37, 38 # номера полей lat,lon в cards - for row in cards[1:]: # пропустили загловки + lon_idx, lat_idx = 36, 37 # номера полей lat,lon в cards + for row in cards[1:]: # пропустили загловки row = [try_encode(v, 'cp1251') for v in row] x = row[lon_idx] y = row[lat_idx]