Skip to content

Commit

Permalink
fix importing bug
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosp420 committed Sep 14, 2016
1 parent 9f1ad08 commit 0a8928a
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions voseq/public_interface/management/commands/_migrate_db.py
Expand Up @@ -72,13 +72,18 @@ def parse_image_info(self, item):
imgs = []
if got_flickr and item['flickr_id']:
item['flickr_id'] = self.get_as_tuple(item['flickr_id'], got_flickr)
print(item['flickr_id'], item['voucher_image'], item['thumbnail'])

for i in range(0, len(item['voucher_image']), 1):
for idx, i in enumerate(item['voucher_image']):
try:
thumbnail = item['thumbnail'][idx]
except IndexError:
thumbnail = ""
imgs.append({
'voucher_id': item['code'],
'voucher_image': item['voucher_image'][i],
'thumbnail': item['thumbnail'][i],
'flickr_id': item['flickr_id'][i],
'voucher_image': item['voucher_image'][idx],
'thumbnail': thumbnail,
'flickr_id': item['flickr_id'][idx],
})
return True, imgs
else:
Expand Down Expand Up @@ -263,7 +268,7 @@ def parse_table_taxonsets(self, xml_string):

def parse_table_vouchers(self, xml_string):
our_data = False
this_table = self.tables_prefix + "vouchers"
this_table = "{}vouchers".format(self.tables_prefix)

root = ET.fromstring(xml_string)
for i in root.iter('table_data'):
Expand Down Expand Up @@ -333,6 +338,8 @@ def parse_table_vouchers(self, xml_string):
except AttributeError:
item['author'] = None
item['created'] = row.find("./field/[@name='timestamp']").text
if not item['date_collection']:
item['date_collection'] = ""
self.table_vouchers_items.append(item)

def import_table_genes(self):
Expand Down Expand Up @@ -619,9 +626,8 @@ def save_table_taxonsets_to_db(self):

def test_if_photo_in_flickr(self, item):
value = item['voucher_image']
if value is not None:
value = value.replace('|', '').strip()
if value.startswith('https://www.flickr'):
if value:
if "flickr" in value:
return True
return False

Expand Down Expand Up @@ -743,11 +749,13 @@ def parse_collection_date(self, mydate, field):
except TypeError:
date_obj = None

if self.verbosity > 1 and not date_obj:
print("WARNING:: Could not parse {} properly.".format(field))
elif date_obj:
if date_obj:
return date_obj.strftime("%Y-%m-%d")
return date_obj
elif self.verbosity > 1 and not date_obj:
print("WARNING:: Could not parse {} properly.".format(field))
return ""
else:
return ""

def parse_date(self, mydate, field):
try:
Expand Down

0 comments on commit 0a8928a

Please sign in to comment.