2020-08-01 15:10:46 +02:00
|
|
|
from app import db
|
|
|
|
from app.models.post import Post
|
|
|
|
|
|
|
|
class Program(Post):
|
|
|
|
__tablename__ = 'program'
|
|
|
|
__mapper_args__ = {'polymorphic_identity': __tablename__}
|
|
|
|
|
|
|
|
# ID of underlying Post object
|
|
|
|
id = db.Column(db.Integer, db.ForeignKey('post.id'), primary_key=True)
|
|
|
|
|
|
|
|
# Program name
|
2022-05-19 21:34:23 +02:00
|
|
|
name = db.Column(db.Unicode(128))
|
2020-08-01 15:10:46 +02:00
|
|
|
|
|
|
|
# TODO: Category (games/utilities/lessons)
|
|
|
|
# TODO: Compatible calculator models
|
2022-06-12 19:11:46 +02:00
|
|
|
# TODO: Number of views, statistics, etc
|
2020-08-01 15:10:46 +02:00
|
|
|
|
2022-06-12 19:11:46 +02:00
|
|
|
# Thread with the program description (top comment) and comments
|
2020-08-01 15:10:46 +02:00
|
|
|
thread_id = db.Column(db.Integer,db.ForeignKey('thread.id'),nullable=False)
|
2020-08-05 22:52:56 +02:00
|
|
|
thread = db.relationship('Thread', foreign_keys=thread_id,
|
|
|
|
back_populates='owner_program')
|
2020-08-01 15:10:46 +02:00
|
|
|
|
2022-06-12 19:11:46 +02:00
|
|
|
# Implicit attributes:
|
|
|
|
# * tags (inherited from Post)
|
|
|
|
# * attachements (available at thread.top_comment.attachments)
|
2020-08-01 15:10:46 +02:00
|
|
|
|
|
|
|
def __init__(self, author, title, thread):
|
|
|
|
"""
|
|
|
|
Create a Program.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
author -- post author (User, though only Members can post)
|
|
|
|
title -- program title (unicode string)
|
|
|
|
thread -- discussion thread attached to the topic
|
|
|
|
"""
|
|
|
|
|
|
|
|
Post.__init__(self, author)
|
|
|
|
self.title = title
|
|
|
|
self.thread = thread
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def from_topic(topic):
|
|
|
|
p = Program(topic.author, topic.title, topic.thread)
|
|
|
|
topic.promotion = p
|
|
|
|
|
2021-07-07 21:23:35 +02:00
|
|
|
def delete(self):
|
|
|
|
db.session.delete(self)
|
|
|
|
|
2020-08-01 15:10:46 +02:00
|
|
|
def __repr__(self):
|
2022-05-19 21:34:23 +02:00
|
|
|
return f'<Program: #{self.id} "{self.name}">'
|