Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Still to fix:
Invalid template name in 'extends' tag: ''. Got this from the 'request.current_app_base_template' variable.

#84
  • Loading branch information
odscjames committed Feb 17, 2023
1 parent 29ad83d commit ac0ad90
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
11 changes: 9 additions & 2 deletions cove_ofds/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import cove_ofds.jsonschema_validation_errors
from libcoveweb2.models import SuppliedDataFile
from libcoveweb2.process import ProcessDataTask
from libcoveweb2.process import ProcessDataTask, ProcessDataTaskException

# from libcove.lib.converters import convert_json, convert_spreadsheet
from libcoveweb2.utils import get_file_type as _get_file_type
Expand Down Expand Up @@ -202,7 +202,14 @@ def process(self, process_data: dict) -> dict:

# Convert
converter = GeoJSONToJSONConverter()
converter.process_data(nodes_data, spans_data)
try:
converter.process_data(nodes_data, spans_data)
except Exception as e:
raise ProcessDataTaskException(
'libcoveweb2/error.html'
,{'msg':'We could not convert the input files you uploaded to JSON.'},
e
)

# Save
with open(self.data_filename, "w") as fp:
Expand Down
14 changes: 11 additions & 3 deletions cove_ofds/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from decimal import Decimal

from django.conf import settings
from django.http import HttpResponseRedirect
from django.http import HttpResponseRedirect, HttpResponseServerError
from django.template import loader
from django.shortcuts import render

from cove_ofds.forms import NewGeoJSONUploadForm
Expand All @@ -26,6 +27,8 @@
explore_data_context,
)

from libcoveweb2.process import ProcessDataTaskException

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -83,7 +86,7 @@ def new_geojson(request):
):
form.add_error(field, "This does not appear to be a JSON file")
if not [
e
e
for e in settings.ALLOWED_GEOJSON_EXTENSIONS
if str(request.FILES[field].name).lower().endswith(e)
]:
Expand Down Expand Up @@ -136,7 +139,12 @@ def explore_ofds(request, pk):
# Process bit that should be a task in a worker
process_data = {}
for task in PROCESS_TASKS:
process_data = task.process(process_data)
try:
process_data = task.process(process_data)
except ProcessDataTaskException as e:
context.update(e.template_vars)
t = loader.get_template(e.template_name)
return HttpResponseServerError(t.render(context))

# read results
for task in PROCESS_TASKS:
Expand Down
8 changes: 8 additions & 0 deletions libcoveweb2/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ def process(self, process_data: dict) -> dict:

def get_context(self):
return {}



class ProcessDataTaskException(Exception):
def __init__(self, template_name: str, template_vars: dict, original_exception: Exception):
self.template_name = template_name
self.template_vars = template_vars
self.original_exception = original_exception

0 comments on commit ac0ad90

Please sign in to comment.