Migrate core admin, baskets
This commit is contained in:
parent
5dacc908f2
commit
df5f67b79d
7 changed files with 229 additions and 39 deletions
src/gisaf/models
|
@ -1,11 +1,10 @@
|
|||
import re
|
||||
from datetime import datetime
|
||||
from datetime import datetime, date
|
||||
|
||||
from sqlmodel import Field, SQLModel, MetaData, JSON, TEXT, Relationship, Column
|
||||
from pydantic import BaseModel
|
||||
from sqlmodel import Field, Relationship
|
||||
import pandas as pd
|
||||
|
||||
# from graphene import ObjectType, Int, String, DateTime, List
|
||||
|
||||
from gisaf.models.models_base import Model
|
||||
from gisaf.models.survey import Surveyor, Equipment
|
||||
from gisaf.models.project import Project
|
||||
|
@ -21,7 +20,7 @@ class BadSurveyFileName(Exception):
|
|||
pass
|
||||
|
||||
|
||||
def get_file_import_date(record):
|
||||
def get_file_import_date(record) -> date:
|
||||
"""
|
||||
Utility function that returns the date of survey from the file name,
|
||||
if it matches the convention for CSV survey files.
|
||||
|
@ -34,9 +33,9 @@ def get_file_import_date(record):
|
|||
'(format should be: "PPP-DESCRIPTION-YYYY-MM-DD", '
|
||||
'PPP being the project name, DESCRITION is optional and discarded)'
|
||||
)
|
||||
return datetime.date(day=int(fname_search.group(4)),
|
||||
month=int(fname_search.group(3)),
|
||||
year=int(fname_search.group(2)))
|
||||
return date(day=int(fname_search.group(4)),
|
||||
month=int(fname_search.group(3)),
|
||||
year=int(fname_search.group(2)))
|
||||
|
||||
|
||||
class FileImport(Model):
|
||||
|
@ -44,7 +43,7 @@ class FileImport(Model):
|
|||
Files to import or imported in the DB.
|
||||
Give either url or path.
|
||||
"""
|
||||
__tablename__ = 'file_import'
|
||||
__tablename__: str = 'file_import' # type: ignore
|
||||
__table_args__ = gisaf_admin.table_args
|
||||
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
|
@ -79,9 +78,10 @@ class FileImport(Model):
|
|||
def selectinload(cls):
|
||||
return [cls.project, cls.surveyor, cls.equipment]
|
||||
|
||||
def set_import_time(self):
|
||||
self.time = datetime.now()
|
||||
db.session.commit()
|
||||
## XXX: was used in Flask
|
||||
# def set_import_time(self):
|
||||
# self.time = datetime.now()
|
||||
# db.session.commit()
|
||||
|
||||
@classmethod
|
||||
async def get_df(cls, *args, **kwargs):
|
||||
|
@ -116,7 +116,7 @@ class FeatureImportData(Model):
|
|||
"""
|
||||
Keep track of imported data, typically from shapefiles
|
||||
"""
|
||||
__tablename__ = 'feature_import_data'
|
||||
__tablename__: str = 'feature_import_data' # type: ignore
|
||||
__table_args__ = gisaf_admin.table_args
|
||||
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
|
@ -127,3 +127,36 @@ class FeatureImportData(Model):
|
|||
origin: str
|
||||
file_path: str
|
||||
file_md5: str
|
||||
|
||||
|
||||
class BasketFile(BaseModel):
|
||||
id: int
|
||||
dir: int
|
||||
name: int
|
||||
url: int
|
||||
md5: int
|
||||
time: datetime
|
||||
comment: int
|
||||
status: int
|
||||
store: int
|
||||
project: int
|
||||
surveyor: int
|
||||
equipment: int
|
||||
import_result: int
|
||||
|
||||
|
||||
class BasketNameOnly(BaseModel):
|
||||
name: str
|
||||
|
||||
|
||||
class Basket(BasketNameOnly):
|
||||
files: list[BasketFile]
|
||||
columns: list[str]
|
||||
uploadFields: list[str]
|
||||
projects: list[str]
|
||||
|
||||
|
||||
class BasketImportResult(BaseModel):
|
||||
time: datetime
|
||||
message: str
|
||||
details: str
|
Loading…
Add table
Add a link
Reference in a new issue