Skip to content

Commit ecfb8d2

Browse files
author
Thomas Hanke
committed
fixed bug
1 parent fce775c commit ecfb8d2

2 files changed

Lines changed: 30 additions & 26 deletions

File tree

app.py

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@
1313

1414
from pydantic import BaseSettings, BaseModel, AnyUrl, Field
1515

16-
from fastapi import Request, FastAPI, Body
16+
from fastapi import Request, FastAPI, Body, HTTPException
1717
from fastapi.staticfiles import StaticFiles
1818
from fastapi.templating import Jinja2Templates
1919
from fastapi.responses import HTMLResponse
2020

2121
import logging
22+
import yaml
2223
from rdflib import URIRef
2324

2425
import maptomethod
2526
import forms
2627

28+
2729
class Settings(BaseSettings):
2830
app_name: str = "MaptoMethod"
2931
admin_email: str = os.environ.get("ADMIN_MAIL") or "csvtocsvw@matolab.org"
@@ -123,24 +125,24 @@ async def create_mapper(request: Request):
123125
mapping_object_class_uris = start_form.advanced.method_object_super_class_uris.data
124126
request.session['mapping_object_class_uris']=mapping_object_class_uris
125127

126-
# try:
127-
with maptomethod.Mapper(
128-
data_url=data_url,
129-
method_url=method_url,
130-
mapping_predicate_uri = URIRef(mapping_predicate_uri),
131-
data_subject_super_class_uris = [ URIRef(uri) for uri in mapping_subject_class_uris],
132-
method_object_super_class_uris = [ URIRef(uri) for uri in mapping_object_class_uris]
133-
) as mapper:
134-
info_choices = [(id, value['text']) for
135-
id, value in mapper.subjects.items()]
136-
info_choices.insert(0, (None, 'None'))
137-
select_forms = forms.get_select_entries(
138-
mapper.objects.keys(),
139-
info_choices
140-
)
128+
try:
129+
with maptomethod.Mapper(
130+
data_url=data_url,
131+
method_url=method_url,
132+
mapping_predicate_uri = URIRef(mapping_predicate_uri),
133+
data_subject_super_class_uris = [ URIRef(uri) for uri in mapping_subject_class_uris],
134+
method_object_super_class_uris = [ URIRef(uri) for uri in mapping_object_class_uris]
135+
) as mapper:
136+
info_choices = [(id, value['text']) for
137+
id, value in mapper.subjects.items()]
138+
info_choices.insert(0, (None, 'None'))
139+
select_forms = forms.get_select_entries(
140+
mapper.objects.keys(),
141+
info_choices
142+
)
141143
flash(request,str(mapper), 'info')
142-
# except Exception as err:
143-
# flash(request,str(err),'error')
144+
except Exception as err:
145+
flash(request,str(err),'error')
144146
mapping_form=await forms.MappingFormList.from_formdata(request)
145147
mapping_form.assignments.entries=select_forms
146148
return templates.TemplateResponse("index.html",
@@ -248,19 +250,21 @@ def mapping(request: MappingRequest = Body(
248250
},
249251
}
250252
)):
251-
result = maptomethod.Mapper(
252-
request.data_url,
253-
request.method_url,
254-
maplist=request.map_list.items()
255-
).to_pretty_yaml()
253+
try:
254+
result = maptomethod.Mapper(
255+
request.data_url,
256+
request.method_url,
257+
maplist=request.map_list.items()
258+
).to_pretty_yaml()
259+
except Exception as err:
260+
print(err)
261+
raise HTTPException(status_code=500, detail=str(err))
256262
return result
257263

258264
@app.get("/info", response_model=Settings)
259265
async def info() -> dict:
260266
return settings
261267

262-
import yaml
263-
264268
if __name__ == "__main__":
265269
port = int(os.environ.get("PORT", 5000))
266270
app_mode=os.environ.get("APP_MODE") or 'production'

maptomethod.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def to_yaml(self) -> dict:
220220
return results
221221
def to_pretty_yaml(self) -> str:
222222
result=self.to_yaml()
223-
result['filedata'] = dump(result['filedata'], Dumper=Dumper)
223+
result['filedata'] = dump(result['filedata'], Dumper=Dumper, allow_unicode=True)
224224
return result
225225

226226

0 commit comments

Comments
 (0)