Skip to content

Commit

Permalink
#62 correct handling 'root' was implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
karavanjo committed Apr 11, 2016
1 parent 3da5a52 commit e3df8be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
18 changes: 9 additions & 9 deletions nextgisbio/models/cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()

Expand Down
14 changes: 7 additions & 7 deletions nextgisbio/views/cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit e3df8be

Please sign in to comment.