class Product(db.Entity): """Товар""" category = Required('Category') title = Required(str) description = Optional(str) unit = Required(str) price = Required(float) #alt_categories = Set('Category') #anmount = int # кол-во товара магазина history = Set('ProductHistory') caritems = Optional('CartItems')
class Person(db.Entity, UpdateableMixin): firstname = Required(str, 255) lastname = Required(str, 255) email = Required(str, 64, unique=True) phone = Optional(str, 32) created = Optional(datetime, default=datetime.now) updated = Optional(datetime, default=datetime.now) event_members = Set('EventMembers') def __str__(self): return f'{self.firstname} {self.lastname}'
class Table6(Helper, _db.Entity): table2 = Required('Table2') table3 = Required('Table3') description = Required(str, unique=True) table6 = Optional('Table5') date_opened = Optional(dtt.datetime) date_closed = Optional(dtt.datetime) table4s = Set('Table4') table7s = Set('Table7') table8 = Required('Table8') table10 = Optional('Table10')
class User(db.Entity): telegram_id = Required(str) spotify_id = Optional(str) spotify_access_token = Optional(str) spotify_refresh_token = Optional(str) # modify_playback_state = Required(bool, default=False) # allowed_scopes = Required(List(str)) @property def spotify(self) -> Spotify: return Spotify(self)
class Work(db.Entity): createdBy = Required('User') created = Required(str) name = Required(str) iframe = Optional(str) embed = Optional(str) picture = Optional(str) github = Optional(str) code = Optional(str) description = Required(str) medium = Set('Medium')
class Entry(db.Entity): title = Required(str) description = Required(str) location = Required(str) state = Required('State') category = Required('Category') website = Optional(str) photo = Optional(str) lng = Required(float) lat = Required(float) created_by = Optional('User')
class Variable(db.Entity): _table_ = 'variable' id = PrimaryKey(int, auto=True) metadata = Required(Json, index=True) data = Required(Json, index=True) create_at = Required(datetime.datetime, default=datetime.datetime.utcnow(), index=True) update_at = Required(datetime.datetime, default=datetime.datetime.utcnow(), index=True) delete_at = Optional(datetime.datetime, nullable=True) user = Required(str) info = Optional(Json) env = Required(Env) @classmethod @db_session def update_variable(cls, env_id, metadata, data, user): obj = get(n for n in Variable if n.env.id == env_id and n.env.delete_at == None and n.delete_at == None) if obj: obj.user = user obj.update_at = datetime.datetime.utcnow() obj.metadata = metadata obj.data = data else: Variable(user=user, metadata=metadata, data=data, env=env_id) @classmethod @db_session def delete_variable_by_env_id(cls, env_id, user): obj = get(n for n in Variable if n.env.id == env_id and n.env.delete_at == None) if obj: obj.user = user obj.delete_at = datetime.datetime.utcnow() @classmethod @db_session def get_metadata_variable_by_env_id(cls, env_id): obj = get(n for n in Variable if n.env.id == env_id and n.env.delete_at == None and n.delete_at == None) if obj: return obj.metadata else: raise IsNotExist(title='环境里没有设置项目变量', detail=f'环境id为{env_id}的环境下没有找到项目变量') @classmethod @db_session def get_data_variable_by_env_id(cls, env_id): obj = get(n for n in Variable if n.env.id == env_id and n.env.delete_at == None and n.delete_at == None) if obj: return obj.data else: raise IsNotExist(title='环境里没有设置项目变量', detail=f'环境id为{env_id}的环境下没有找到项目变量')
class User(db.Entity): # id = PrimaryKey(int, auto=True) name = Required(str, 32) password = Required(str, 8) gender = Optional(bool, default=True) birthday = Optional(date, nullable=True) phone = Optional(str, 11, nullable=True) photo = Optional(buffer, nullable=True) register = Required(datetime, sql_default='CURRENT_TIMESTAMP') _table_ = 'user'
class Product(db.Entity): category = Optional('Category') # alt_categories = Set("Category") unit = Required(str) price = Required(float) description = Optional(str) title = Required(str) # amount = int history = Set('ProductHistory') cartitem = Optional('CartItem') orderitem = Set('OrderItem')
class Category(db.Entity): """Категория товара""" title = Required(str, 50) description = Optional(LongStr) parent = Optional('Category', reverse='categories') #ссылка на саму себ media = Set('Media') products = Set('Product') categories = Set('Category', reverse='parent') def __str__(self): return self.title
class UserSite(db.Entity): """用户保存网站信息""" id = PrimaryKey(int, auto=True) name = Required(str) url = Required(str) icon = Optional(str) user = Required(User) cate = Optional(Category) order = Required(int, default=20) create_time = Required(datetime, default=datetime.utcnow) status = Required(int, default=UserSiteStatus.normal) delete_time = Optional(datetime)
class ParsedData(db.Entity): chatId = Required(int) didattica = Optional(str) info = Optional(str) prof = Optional(str) note = Optional(str) voti = Optional(str) assenze = Optional(str) agenda = Optional(str) domani = Optional(str) lezioni = Optional(str) circolari = Optional(str)
class Data(db.Entity): chatId = Required(int) didattica = Optional(Json) info = Optional(Json) prof = Optional(Json) note = Optional(Json) voti = Optional(Json) assenze = Optional(Json) agenda = Optional(Json) domani = Optional(Json) lezioni = Optional(Json) circolari = Optional(Json)
class Room(HasLocation, HasTags, PicklableEntity, db.Entity, metaclass=HasMixins): """Room entity.""" title = Required(str, max_len=128) x = Optional(int) y = Optional(int) z = Optional(int) barcode = Required(str, max_len=32, unique=True, index=True)
class Forecast(database.Entity): forecastMetadata = Required(ForecastMetadata) time = Required(datetime.datetime, sql_type='TIMESTAMP WITH TIME ZONE', default=datetime.datetime.now(datetime.timezone.utc)) PrimaryKey(forecastMetadata, time) # TODO remove percentil10 and 90 since we won't use them percentil10 = Optional(int) percentil50 = Optional(int) percentil90 = Optional(int)
class BillEntry(DB.Entity): """A single row in the bill.""" #TODO primary key with the Bill and the content instead of an ID? id = PrimaryKey(int, auto=True) bill = Required(Bill) product = Optional(str) quantity = Optional(int) unit_cost = Optional(Decimal, precision=10, scale=2) def get_total(self): """Return the total cost of this row.""" return self.quantity * self.unit_cost
class Lobby(db.Entity): lobby_id = PrimaryKey(int, auto=True) lobby_name = Required(str, unique=True) lobby_max_players = Optional(int, default=10) # <=10 lobby_min_players = Optional(int, default=5) # >=5 lobby_creator = Required(int) # user_id of the creator lobby_user = Set( User ) # many to many relation with Lobby-User, we use '' because Player is declarated after this call lobby_players = Set( 'Player' ) # one to many relation with Lobby-Player, we use '' because Player is declarated after this call
class Product(db.Entity): """Товар""" category = Optional('Category') title = Required(str) description = Optional(str) unit = Required(str) price = Required(float) # alt_category = Set('Category') # amount = int # количество товара в магазине сейчас history = Set('ProductHistory') cart_item = Optional('CartItem') order_item = Optional('OrderItem')
class Topic(db.Entity): def __repr__(self): return 'Topic: ' + self.title author = Required(User) date_created = Required(datetime) date_last_reply = Optional(datetime, nullable=True) posts = Set('Post') topic_type = Optional(str, nullable=True) title = Required(str) url = Required(str) topic_id = Required(str)
class Landmark(db.Entity): name = Required(str) description = Required(str) image = Required(str) ticket_price = Optional(float) start_time = Required(str) finish_time = Required(str) address = Required(str) lat = Optional(float) lng = Optional(float) cityname = Required(str) user = Required('User')
class Character(db.Entity): """ ORM object for storing characters. """ login = Required(str, unique=True) name = Optional(str) appearance = Optional(str) story = Optional(str) user = Required(lambda: User) status = Required(int)
class Game(database.Entity): id = PrimaryKey(int, auto=True) teams = Set(Team) host = Required(Player, reverse="games_hosted") location = Optional(str) date = Optional(date) accepted_players = Set(Player, reverse="accepted_games") cancelled = Optional(bool) final_score = Optional(str)
class Account(db.Entity): _table_ = ("finance", "accounts") id = PrimaryKey(int, auto=True) budget_id = Required("Budget") # maps to budget name = Required(str) parent_id = Optional(int) # maps to self created_at = Optional(int) # foreign references from_records = Set("Record", reverse="from_account_id") to_records = Set("Record", reverse="to_account_id")
class User(db.Entity): id = PrimaryKey(int, auto=True) # name = Set('Role') name = Required(str, unique=True, max_len=30) pwd = Required(str, max_len=100) email = Optional(str, max_len=50) state = Required(State) role = Optional(int) create_time = Required(datetime, default=datetime.now) update_time = Optional(datetime) def before_update(self): self.update_time = datetime.now()
class Bill(DB.Entity): """A bill.""" id = PrimaryKey(int, auto=True) client = Optional(Client) date = Optional(date) entries = Set('BillEntry') def get_total(self): """Return the total cost of this bill.""" total = 0 for entry in self.entries: total += entry.get_total() return total
class Record(db.Entity): _table_ = ("finance", "records") id = PrimaryKey(int, auto=True) hash = Required(str) budget_id = Required("Budget") # maps to budget from_account_id = Optional("Account") # maps to account to_account_id = Optional("Account") # maps to account amount = Required(int) # dollar value in cents description = Required(str) transaction_time = Required(int) record_source_id = Required("RecordSource") # maps to RecordSource created_at = Optional(int)
class Question(db.Entity): id = PrimaryKey(UUID, default=uuid4, auto=True) number = Optional(int, index=True) text = Required(str) multi_choice = Optional(StrArray) marks = Required(int) answer = Optional(str) metadata = Required(Json, default={}) created_at = Required(dt, default=lambda: dt.utcnow(), index=True) updated_at = Required(dt, default=lambda: dt.utcnow()) exam = Required(Exam) submissions = Set('Submission') composite_key(exam, number)
class Article(db.Entity): _table_ = '%s_article' % schema if DEBUG else (schema, 'article') id = PrimaryKey(int, auto=True) date = Required(datetime) scopus_id = Required(str, unique=True) title = Required(str) volume = Optional(str) issue = Optional(str) pages = Optional(str) doi = Optional(str) cited = Required(int) authors = Set('ArticleAuthor') journal = Required('Journal')
class Purchase(db.Entity): id = PrimaryKey(int, auto=True) name = Required(str) added = Required(datetime, default=datetime.now()) price = Optional(float) bought = Required(bool, default=False) done = Optional(datetime) def to_json(self): view = self.to_dict() view['added'] = str(self.added) view['done'] = str(self.done) return view
class FormalMessage(DatabaseConfig.db.Entity): """Initialize Pony ORM model for Formal Message Table""" log_entry = Required(LogEntry) id = PrimaryKey(int, auto=True) date_time = Required(datetime) message_from = Required(str) message_to = Required(str) subject = Optional(str) message = Optional(LongStr) message_received_from = Optional('Message_Transmission', reverse='formal_message_received_from') message_sent_to = Optional('Message_Transmission', reverse='formal_message_sent_to')