70 lines
1.3 KiB
Python
70 lines
1.3 KiB
Python
from abc import ABCMeta, abstractclassmethod
|
|
|
|
|
|
class BaseModel:
|
|
def _init(self, model, **params):
|
|
for k, v in params.items():
|
|
pp = model.__dict__.get(k)
|
|
if pp is not None:
|
|
self.__dict__[k] = v
|
|
|
|
def __init__(self, **params):
|
|
self._row = None
|
|
self._init(type(self), **params)
|
|
|
|
_column = None
|
|
offset_rows = 0
|
|
offset_cols = 0
|
|
|
|
@property
|
|
def row(self):
|
|
return self._row
|
|
|
|
@row.setter
|
|
def row(self, idx):
|
|
self._row = idx
|
|
|
|
@classmethod
|
|
def get_column(cls):
|
|
return cls._column
|
|
|
|
@classmethod
|
|
def get(cls):
|
|
return "GET"
|
|
|
|
@classmethod
|
|
def get_by_id(cls, id):
|
|
return "GET " + str(id)
|
|
|
|
def create(self):
|
|
self.Meta.database.create(self)
|
|
|
|
def update(self):
|
|
self.Meta.database.update(self)
|
|
|
|
def delete(self):
|
|
self.Meta.database.delete(self)
|
|
|
|
class Meta:
|
|
database = None
|
|
|
|
|
|
class Field:
|
|
def __init__(self, caption, column):
|
|
self._caption = caption
|
|
self._column = column
|
|
|
|
@property
|
|
def caption(self):
|
|
return self._caption
|
|
|
|
@property
|
|
def column(self):
|
|
return self._column
|
|
|
|
def __repr__(self):
|
|
return self._caption
|
|
|
|
def __str__(self):
|
|
return self._caption
|