included db import reference to config

This commit is contained in:
Peter Yefi 2023-01-17 20:10:20 -05:00
parent 588eef7f9d
commit 582c18ef0c
2 changed files with 8 additions and 7 deletions

View File

@ -12,7 +12,6 @@ from persistence.models import UserRoles
from hub_logger import logger
from imports.geometry_factory import GeometryFactory
from pathlib import Path
from imports.db_factory import DBFactory
import os
from hub_api.config import Config
@ -74,12 +73,12 @@ class CityInfo(Resource, Config):
return Response(json.dumps(response), status=200)
class City(Resource):
class City(Resource, Config):
def __init__(self):
pass
super().__init__()
@role_required([UserRoles.Admin.value, UserRoles.Hub_Reader.value])
@role_required([UserRoles.Admin.value])
def post(self):
allowed_ext = {'gml', '3dm', 'xml', 'obj', 'rhino'}
try:
@ -96,9 +95,8 @@ class City(Resource):
file_path = (Path(__file__).parent.parent / 'data/uploaded_city/{}'.format(city_file.filename)).resolve()
city_file.save(file_path)
city = GeometryFactory(city_file_type, file_path).city
db_factory = DBFactory(city=city, db_name='hub_prod', app_env='PROD',
dotenv_path="{}/.env".format(os.path.expanduser('~')))
saved_city = db_factory.persist_city(1)
saved_city = self.import_db_factory.persist_city(g.user['id'], city)
if os.path.exists(file_path):
os.remove(file_path)
if type(saved_city) is not dict:

View File

@ -4,6 +4,7 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2023 Project Peter Yefi peteryefi@gmail.com
"""
from exports.db_factory import DBFactory as CityExportFactory
from imports.db_factory import DBFactory
import os
import pickle
@ -13,6 +14,8 @@ class Config:
def __init__(self):
self.factory = CityExportFactory(db_name='hub_prod', app_env='PROD',
dotenv_path="{}/.env".format(os.path.expanduser('~')))
self.import_db_factory = DBFactory(db_name='hub_prod', app_env='PROD',
dotenv_path="{}/.env".format(os.path.expanduser('~')))
def get_city(self, city_id):
city_obj = self.factory.get_city(city_id)