Skip to content

Commit

Permalink
Merge pull request #30 from ExCiteS/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Julia Altenbuchner committed May 9, 2017
2 parents d25e182 + b970d28 commit b98b585
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion geokey_sapelli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_PARTS = (2, 0, 0)
VERSION_PARTS = (2, 0, 1)
__version__ = '.'.join(map(str, VERSION_PARTS))


Expand Down
25 changes: 15 additions & 10 deletions geokey_sapelli/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ def import_from_csv(self, user, csv_file, form_category_id=None):
model_id = int(re.match(
r"modelID=(?P<model_id_str>[0-9]+)",
[fn for fn in reader.fieldnames if fn.startswith('modelID=')][0])
.group('model_id_str'))
.group('model_id_str'))
model_schema_number = int(re.match(
r"modelSchemaNumber=(?P<model_schema_number_str>[0-9]+)",
[fn for fn in reader.fieldnames if fn.startswith('modelSchemaNumber=')][0])
.group('model_schema_number_str'))
.group('model_schema_number_str'))
except BaseException:
pass

Expand All @@ -173,16 +173,19 @@ def import_from_csv(self, user, csv_file, form_category_id=None):
try:
form = self.forms.get(sapelli_model_schema_number=model_schema_number)
except SapelliForm.DoesNotExist:
raise SapelliCSVException('No Form with modelSchemaNumber %s found in Project "%s".' % (model_schema_number, self.geokey_project.name))
raise SapelliCSVException('No Form with modelSchemaNumber %s found in Project "%s".' % (
model_schema_number, self.geokey_project.name))
# Check if form matches form_category_id given in request:
if (form_category_id is not None) and form_category_id != form.category.id:
raise SapelliCSVException('The data in the CSV file was not created using selected form "%s".' % form.sapelli_id)
raise SapelliCSVException(
'The data in the CSV file was not created using selected form "%s".' % form.sapelli_id)
elif (form_category_id is not None):
# No Form identification found in CSV header row, use form_category_id given in request...
try:
form = self.forms.get(pk=form_category_id)
except SapelliForm.DoesNotExist:
raise SapelliCSVException('No Form with category_id %s found in Project "%s".' % (form_category_id, self.geokey_project.name))
raise SapelliCSVException(
'No Form with category_id %s found in Project "%s".' % (form_category_id, self.geokey_project.name))
else:
# No Form identification found in CSV header row, nor in request...
raise SapelliCSVException('No Form identification found in CSV header row, please select appropriate form.')
Expand Down Expand Up @@ -241,11 +244,12 @@ def import_from_csv(self, user, csv_file, form_category_id=None):
if sapelli_field.truefalse:
value = 0 if value == 'false' else 1

if sapelli_field.items.count() > 0:
leaf = sapelli_field.items.get(number=value)
value = leaf.lookup_value.id
if value:
if sapelli_field.items.count() > 0:
leaf = sapelli_field.items.get(number=value)
value = leaf.lookup_value.id

feature['properties'][key] = value
feature['properties'][key] = value

from geokey.contributions.serializers import ContributionSerializer

Expand Down Expand Up @@ -477,7 +481,8 @@ def create(cls, user, sapelli_project, days_valid=1):
token=generate_token(),
scope='read')
except (AttributeError, Application.DoesNotExist) as e:
raise SapelliException('geokey-sapelli is not properly configured as an application on the server: ' + str(e))
raise SapelliException(
'geokey-sapelli is not properly configured as an application on the server: ' + str(e))
qr_link = cls(access_token=a_t, sapelli_project=sapelli_project)
qr_link.save()
return qr_link
Expand Down

0 comments on commit b98b585

Please sign in to comment.