ipynbtools: remove the gisaf "proxy"

Move methods to module level
Fix DashboardPage model definitions
Fix RawSurveyModel (missing geom field)
Cleanup
This commit is contained in:
phil 2024-05-02 23:42:45 +02:00
parent 00a5ae2d4e
commit dedb01b712
6 changed files with 284 additions and 256 deletions

View file

@ -31,16 +31,16 @@ class DashboardPageSource(Model, table=True):
name: str
class DashboardPageCommon:
class DashboardPageCommon(Model):
"""
Base class for DashboardPage and DashboardPageSection, where some methods
are common, eg. attachments
"""
name: str
df: bytes
plot: bytes
df: bytes | None = None
plot: bytes | None = None
#plot: dict[str, Any] | None = Field(sa_type=JSON(none_as_null=True)) # type: ignore
attachment: str | None
attachment: str | None = None
html: str | None = None
def ensure_dir_exists(self):
@ -139,7 +139,7 @@ class DashboardPageMetaData(BaseModel):
viewable_role: str | None = None
class DashboardPage(Model, DashboardPageCommon, DashboardPageMetaData, table=True):
class DashboardPage(DashboardPageCommon, DashboardPageMetaData, table=True):
__tablename__ = 'dashboard_page' # type: ignore
__table_args__ = gisaf.table_args
@ -202,7 +202,7 @@ class DashboardPage(Model, DashboardPageCommon, DashboardPageMetaData, table=Tru
logger.debug('Notebook: no base_url in gisaf config')
class DashboardPageSection(Model, DashboardPageCommon, table=True):
class DashboardPageSection(DashboardPageCommon, table=True):
__tablename__ = 'dashboard_page_section' # type: ignore
__table_args__ = gisaf.table_args
@ -280,7 +280,7 @@ class Widget(Model, table=True):
subtitle: str
content: str
time: datetime
notebook: str
notebook: str | None = None
class Admin:
menu = 'Dashboard'

View file

@ -179,7 +179,6 @@ class Project(Model, table=True):
return result
# def download_raw_survey_data(self, session=None):
# from gisaf.models.raw_survey_models import RawSurvey
# from gisaf.registry import registry

View file

@ -1,24 +1,31 @@
from typing import ClassVar
from sqlmodel import Field, BigInteger
from typing import Annotated, ClassVar
from geoalchemy2 import Geometry, WKBElement
from sqlmodel import Field, BigInteger, Relationship
from gisaf.config import conf
from gisaf.models.models_base import Model
from gisaf.models.geo_models_base import GeoPointMModel, BaseSurveyModel
from gisaf.models.project import Project
from gisaf.models.category import Category
from gisaf.models.metadata import gisaf_survey
from gisaf.models.metadata import gisaf_survey, gisaf_admin
class RawSurveyModel(BaseSurveyModel, GeoPointMModel):
class RawSurveyModel(BaseSurveyModel, GeoPointMModel, table=True):
__table_args__ = gisaf_survey.table_args
__tablename__ = 'raw_survey'
hidden: ClassVar[bool] = True
geom: Annotated[str, WKBElement] = Field(
sa_type=Geometry('POINTZ', dimension=3, srid=conf.geo.raw_survey.srid))
id: int | None = Field(default=None, primary_key=True)
project_id: int | None = Field(foreign_key='project.id')
category: str = Field(foreign_key='category.name')
in_menu: bool = False
# Subclasses must include:
# project: Project = Relationship()
# category_info: Project = Relationship()
project_id: int | None = Field(foreign_key=gisaf_admin.table('project.id'))
category: str = Field(foreign_key=gisaf_survey.table('category.name'))
#in_menu: bool = False
project: Project = Relationship()
category_info: Category = Relationship()
## XXX: Unused - calls to get_gdf have to provide this
## if the CRS is not standard, maybe due to an update of shapely?
_crs = conf.geo.raw_survey.spatial_sys_ref
@classmethod
def selectinload(cls):