Admins basket details
This commit is contained in:
parent
c1f229f805
commit
b00bf1f9f9
3 changed files with 94 additions and 47 deletions
|
@ -9,14 +9,16 @@ from typing import ClassVar
|
|||
# from aiohttp.multipart import MultipartReader
|
||||
# from aiohttp.web import HTTPUnauthorized, HTTPForbidden
|
||||
|
||||
from sqlmodel import select
|
||||
|
||||
from gisaf.config import conf
|
||||
from gisaf.models.admin import FileImport
|
||||
from gisaf.models.authentication import User
|
||||
# from gisaf.models.graphql import AdminBasketFile, BasketImportResult
|
||||
from gisaf.models.survey import Surveyor, Accuracy, Equipment, AccuracyEquimentSurveyorMapping
|
||||
from gisaf.models.project import Project
|
||||
from gisaf.importers import RawSurveyImporter, GeoDataImporter, LineWorkImporter, ImportError
|
||||
from gisaf.utils import ToMigrate
|
||||
from gisaf.database import db_session
|
||||
from gisaf.importers import RawSurveyImporter, GeoDataImporter, LineWorkImporter, ImportError
|
||||
from gisaf.models.admin import FileImport, AdminBasketFile, BasketImportResult
|
||||
from gisaf.models.authentication import User
|
||||
from gisaf.models.survey import Surveyor, Equipment
|
||||
from gisaf.models.project import Project
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -58,41 +60,46 @@ class Basket:
|
|||
else:
|
||||
return False
|
||||
|
||||
async def get_files(self, convert_path=False):
|
||||
"""
|
||||
Get a dataframe of FileImport items in the basket.
|
||||
"""
|
||||
where = FileImport.basket==self.name
|
||||
## First, get the list of files in the base_dir, then associate with the FileImport instance
|
||||
df = await FileImport.get_df(
|
||||
where=where,
|
||||
with_related=True
|
||||
#with_only_columns=['id', 'path', 'time', 'status', 'table'],
|
||||
)
|
||||
df.rename(columns={
|
||||
'gisaf_admin_project_name': 'project',
|
||||
'gisaf_survey_surveyor_name': 'surveyor',
|
||||
'gisaf_survey_equipment_name': 'equipment',
|
||||
}, inplace=True)
|
||||
## Sanity check
|
||||
df.dropna(subset=['name'], inplace=True)
|
||||
df['dir'] = df.dir.fillna('.')
|
||||
df.reset_index(drop=True, inplace=True)
|
||||
async def get_files(self) -> list[FileImport]:
|
||||
async with db_session() as session:
|
||||
data = await session.exec(select(FileImport).where(FileImport.basket==self.name))
|
||||
return data.all()
|
||||
|
||||
## TODO: After the old admin is completely off and all is clean and nice, remove below and just:
|
||||
# return df
|
||||
# async def get_files_df(self, convert_path=False):
|
||||
# """
|
||||
# Get a dataframe of FileImport items in the basket.
|
||||
# """
|
||||
# where = FileImport.basket==self.name
|
||||
# ## First, get the list of files in the base_dir, then associate with the FileImport instance
|
||||
# df = await FileImport.get_df(
|
||||
# where=where,
|
||||
# with_related=True
|
||||
# #with_only_columns=['id', 'path', 'time', 'status', 'table'],
|
||||
# )
|
||||
# df.rename(columns={
|
||||
# 'gisaf_admin_project_name': 'project',
|
||||
# 'gisaf_survey_surveyor_name': 'surveyor',
|
||||
# 'gisaf_survey_equipment_name': 'equipment',
|
||||
# }, inplace=True)
|
||||
# ## Sanity check
|
||||
# df.dropna(subset=['name'], inplace=True)
|
||||
# df['dir'] = df.dir.fillna('.')
|
||||
# df.reset_index(drop=True, inplace=True)
|
||||
|
||||
## Until the compatibility with old admin is required and we're sure nothing is destroyed:
|
||||
## Get files on the file system
|
||||
if len(df) == 0:
|
||||
return df
|
||||
if convert_path:
|
||||
df['path'] = df.apply(lambda fi: Path(fi['dir'])/fi['name'], axis=1)
|
||||
#if check_fs:
|
||||
# files = set(self.base_dir.glob('**/*'))
|
||||
# df['exists'] = df.apply(lambda fi: self.base_dir/fi['dir']/fi['name'] in files, axis=1)
|
||||
else:
|
||||
return df
|
||||
# ## TODO: After the old admin is completely off and all is clean and nice, remove below and just:
|
||||
# # return df
|
||||
|
||||
# ## Until the compatibility with old admin is required and we're sure nothing is destroyed:
|
||||
# ## Get files on the file system
|
||||
# if len(df) == 0:
|
||||
# return df
|
||||
# if convert_path:
|
||||
# df['path'] = df.apply(lambda fi: Path(fi['dir'])/fi['name'], axis=1)
|
||||
# #if check_fs:
|
||||
# # files = set(self.base_dir.glob('**/*'))
|
||||
# # df['exists'] = df.apply(lambda fi: self.base_dir/fi['dir']/fi['name'] in files, axis=1)
|
||||
# else:
|
||||
# return df
|
||||
|
||||
async def get_file(self, id):
|
||||
df = await FileImport.get_df(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue