update file to use new pylint settings, added types and using docstrings in goolge format with partial openapi spec
This commit is contained in:
90
path.py
90
path.py
@@ -1,61 +1,89 @@
|
||||
from shared import PA, ICON
|
||||
""" file containing all classes/functions to handle Path from the database """
|
||||
|
||||
from flask import url_for
|
||||
from flask_wtf import FlaskForm
|
||||
from main import db, app, ma
|
||||
from sqlalchemy import Sequence
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from shared import PA, ICON
|
||||
from main import db
|
||||
|
||||
# pylint: disable=no-member
|
||||
|
||||
################################################################################
|
||||
# Class describing File in the database, and via sqlalchemy, connected to the DB as well
|
||||
# This has to match one-for-one the DB table
|
||||
################################################################################
|
||||
class PathType(db.Model):
|
||||
"""Class describing the type of Paths in the database
|
||||
|
||||
Attributes:
|
||||
id (int): database id of row in PathType table / primary key
|
||||
name (str): name of path type (e.g. import, storage, bin)
|
||||
"""
|
||||
|
||||
__tablename__ = "path_type"
|
||||
id = db.Column(db.Integer, db.Sequence('path_type_id_seq'), primary_key=True )
|
||||
name = db.Column(db.String, unique=True, nullable=False )
|
||||
id:int = db.Column(db.Integer, db.Sequence("path_type_id_seq"), primary_key=True )
|
||||
name:str = db.Column(db.String, unique=True, nullable=False )
|
||||
|
||||
def __repr__(self):
|
||||
return "<id: {}, name={}>".format(self.id, self.name )
|
||||
return f"<id: {self.id}, name={self.name}>"
|
||||
|
||||
################################################################################
|
||||
# Class describing Path & in the database via sqlalchemy
|
||||
################################################################################
|
||||
class Path(db.Model):
|
||||
"""Class describing a Path in the database
|
||||
|
||||
Attributes:
|
||||
id (int): database id of row in Path table / primary key
|
||||
type_id (int): id of row in PathType table / foreign key
|
||||
type (PathType): sqlalchemy relationship of PathType using type_id
|
||||
path_prefix (str): The actual dir on the filesystem that defines this Path
|
||||
num_files (int): number of files in this Path
|
||||
"""
|
||||
__tablename__ = "path"
|
||||
id = db.Column(db.Integer, db.Sequence('path_id_seq'), primary_key=True )
|
||||
type_id = db.Column(db.Integer, db.ForeignKey("path_type.id"))
|
||||
type = db.relationship("PathType")
|
||||
path_prefix = db.Column(db.String, unique=True, nullable=False )
|
||||
num_files = db.Column(db.Integer)
|
||||
id:int = db.Column(db.Integer, db.Sequence("path_id_seq"), primary_key=True )
|
||||
type_id:int = db.Column(db.Integer, db.ForeignKey("path_type.id"))
|
||||
type:PathType = db.relationship("PathType")
|
||||
path_prefix:str = db.Column(db.String, unique=True, nullable=False )
|
||||
num_files:int = db.Column(db.Integer)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<id: {self.id}, path_prefix: {self.path_prefix}, num_files={self.num_files}, type={self.type}>"
|
||||
|
||||
|
||||
################################################################################
|
||||
# Class describing PathDeatil (quick connvenence class for MovePathDetails())
|
||||
# Class describing PathDetail (quick connvenence class for MovePathDetails())
|
||||
################################################################################
|
||||
class PathDetail(PA):
|
||||
def __init__(self,type,path):
|
||||
self.type=type
|
||||
self.path=path
|
||||
self.icon_url=url_for('internal', filename='icons.svg') + '#' + ICON[self.type]
|
||||
return
|
||||
"""Class describing details of a Path [internal class used in MovePathDetais()]"""
|
||||
|
||||
def __init__(self,ptype,path):
|
||||
"""Initialisation function for PathDetail class
|
||||
|
||||
Args:
|
||||
id (int): database id of row in PathDetail table / primary key
|
||||
ptype (int): database id of row in PathType table / foreign key
|
||||
"""
|
||||
|
||||
self.type:int=ptype
|
||||
self.path:str=path
|
||||
# construct icon_url based on type of storage path (icons.svg contains icons for each)
|
||||
self.icon_url:str=url_for("internal", filename="icons.svg") + "#" + ICON[self.type]
|
||||
|
||||
################################################################################
|
||||
# helper function to find oath details for move destinations - used in html
|
||||
# helper function to find path details for move destinations - used in html
|
||||
# for move DBox to show potential storage paths to move files into
|
||||
################################################################################
|
||||
def MovePathDetails():
|
||||
"""helper function to find path details for move destinations
|
||||
|
||||
used in html/javascript for move Dialog Box to show potential storage paths to move files into
|
||||
|
||||
Args:
|
||||
None
|
||||
|
||||
Returns:
|
||||
ret (List[PathDetail]): a list of Path Details for where files can be moved
|
||||
|
||||
"""
|
||||
ret=[]
|
||||
sps=Path.query.join(PathType).filter(PathType.name=='Storage').all()
|
||||
sps=Path.query.join(PathType).filter(PathType.name=="Storage").all()
|
||||
for p in sps:
|
||||
obj = PathDetail( type='Storage', path=p.path_prefix.replace('static/Storage/','') )
|
||||
obj = PathDetail( ptype="Storage", path=p.path_prefix.replace("static/Storage/","") )
|
||||
ret.append( obj )
|
||||
ips=Path.query.join(PathType).filter(PathType.name=='Import').all()
|
||||
ips=Path.query.join(PathType).filter(PathType.name=="Import").all()
|
||||
for p in ips:
|
||||
obj = PathDetail( type='Import', path=p.path_prefix.replace('static/Import/','') )
|
||||
obj = PathDetail( ptype="Import", path=p.path_prefix.replace("static/Import/","") )
|
||||
ret.append( obj )
|
||||
return ret
|
||||
|
||||
Reference in New Issue
Block a user