Esempio n. 1
0
class Card(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String)
    baujahr = db.Column(db.String)
    maschinennummer = db.Column(db.Integer)
    standort = db.Column(db.String)
    author_id = db.Column(db.Integer, db.ForeignKey(
        'users.id'))  # foreign key (table name for the User model is "users")
    author = db.relationship(
        "User"
    )  # not a real field, just shows a relationship with the User model
    machine_id = db.Column(
        db.Integer, db.ForeignKey("machines.id")
    )  #One-to-many relationship zwischen vielen Cards und einer Machine
    machine = db.relationship("Machine")
    created = db.Column(db.DateTime, default=datetime.utcnow)

    @classmethod
    def create(cls, name, baujahr, maschinennummer, standort, author):
        card = cls(name=name,
                   baujahr=baujahr,
                   maschinennummer=maschinennummer,
                   standort=standort,
                   author=author)
        db.add(card)
        db.commit()

        return card
class Comment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.String)

    author_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    author = db.relationship('User')

    topic_id = db.Column(db.Integer, db.ForeignKey('topics.id'))
    topic = db.relationship('Topic')

    created = db.Column(db.DateTime, default=datetime.utcnow)

    @classmethod
    def create(cls, text, author, topic):
        comment = cls(text=text, author=author, topic=topic)
        db.add(comment)
        db.commit()

        if topic.author.email_address:
            send_email(receiver_email=topic.author.email_address,
                       subject="New comment for your topic!",
                       text="Your topic {} has a new comment.".format(
                           topic.title))

        return comment
Esempio n. 3
0
class Comment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.String)

    author_id = db.Column(db.Integer,
                          db.ForeignKey('users.id'))  # User foreign key
    author = db.relationship("User")  # User relationship

    topic_id = db.Column(db.Integer,
                         db.ForeignKey('topics.id'))  # Topic foreign key
    topic = db.relationship("Topic")  # Topic relationship

    created = db.Column(db.DateTime, default=datetime.utcnow)

    @classmethod
    def create(cls, text, author, topic):
        comment = cls(text=text, author=author, topic=topic)
        db.add(comment)
        db.commit()

        # only send of topic author has her/his email in the database
        if topic.author.email_address:
            send_email(receiver_email=topic.author.email_address,
                       subject="New comment for your topic!",
                       text="Your topic {} has a new comment.".format(
                           topic.title))

        return comment

    @classmethod
    def read_all(cls, topic):
        comments = db.query(Comment).filter_by(topic=topic).all()

        return comments
Esempio n. 4
0
class Comment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.String)

    author_id = db.Column(db.Integer,
                          db.ForeignKey('users.id'))  # User foreign key
    author = db.relationship("User")  # User relationship

    topic_id = db.Column(db.Integer,
                         db.ForeignKey('topics.id'))  # Topic foreign key
    topic = db.relationship("Topic")  # Topic relationship

    created = db.Column(db.DateTime, default=datetime.utcnow)
Esempio n. 5
0
class Topic(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String)
    text = db.Column(db.String)
    author_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    author = db.relationship("User")
    created = db.Column(db.DateTime, default=datetime.utcnow())
Esempio n. 6
0
class Topic(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String)
    text = db.Column(db.String)
    author_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    author = db.relationship("User")
    created = db.Column(db.DateTime, default=datetime.now())

    @classmethod
    def create(cls, title, text, author):
        topic = cls(title=title, text=text, author=author)

        db.add(topic)
        db.commit()

        return topic

    @classmethod
    def read(cls, topic_id):
        topic = db.query(Topic).get(int(topic_id))

        return topic

    @classmethod
    def update(cls, topic_id, title, text):
        topic = db.query(Topic).get(int(topic_id))

        topic.title = title
        topic.text = text

        db.add(topic)
        db.commit()

        return topic
Esempio n. 7
0
class Comment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.String)

    author_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    author = db.relationship('User')

    topic_id = db.Column(db.Integer, db.ForeignKey('topics.id'))
    topic = db.relationship('Topic')

    created = db.Column(db.DateTime, default=datetime.utcnow)

    @classmethod
    def create(cls, text, author, topic):
        comment = cls(text=text, author=author, topic=topic)
        db.add(comment)
        db.commit()

        return comment
Esempio n. 8
0
class Comment(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    text = db.Column(db.String)

    author_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    author = db.relationship("User")

    topic_id = db.Column(db.Integer, db.ForeignKey('topics.id'))
    topic = db.relationship("Topic")

    created = db.Column(db.DateTime, default=datetime.now())

    @classmethod
    def create(cls, text, author, topic):
        comment = cls(text=text, author=author, topic=topic)
        db.add(comment)
        db.commit()

        if topic.author.email:
            send_email(receiver_email=topic.author.email,
                       subject="New comment for your topic!",
                       text="Your topic {} has a new comment.".format(
                           topic.title))

        return comment

    @classmethod
    def read_all(cls, topic):
        comments = db.query(Comment).filter_by(topic=topic).all()

        return comments

    @classmethod
    def get_comment(cls, comment_id):
        comment = db.query(Comment).get(int(comment_id))

        return comment
Esempio n. 9
0
class Topic(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String)
    text = db.Column(db.String)
    author_id = db.Column(db.Integer, db.ForeignKey("users.id"))
    author = db.relationship("User")
    created_at = db.Column(db.DateTime, default=datetime.utcnow())

    @classmethod
    def create(cls, title, text, author):
        topic = cls(title=title, text=text, author=author)
        db.add(topic)
        db.commit()

        return topic
class ProfileData(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    firstname = db.Column(db.String)
    lastname = db.Column(db.String)
    birthday = db.Column(db.DateTime)
    owner_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    owner = db.relationship("User")

    # age = db.Column(db.Integer)

    @classmethod
    def create(cls, firstname, lastname, owner):
        profile_data = cls(firstname=firstname, lastname=lastname, owner=owner)
        db.add(profile_data)
        db.commit()

        return profile_data
Esempio n. 11
0
class Topic(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String)
    text = db.Column(db.String)
    author_id = db.Column(db.Integer, db.ForeignKey(
        'users.id'))  # foreign key (table name for the User model is "users")
    author = db.relationship(
        "User"
    )  # not a real field, just shows a relationship with the User model
    created = db.Column(db.DateTime, default=datetime.utcnow)

    @classmethod
    def create(cls, title, text, author):
        topic = cls(title=title, text=text, author=author)
        db.add(topic)
        db.commit()

        return topic
Esempio n. 12
0
class Image(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    image_url = db.Column(db.String)
    author_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    author = db.relationship("User")
    created = db.Column(db.DateTime, default=datetime.utcnow)

    def insert(self):
        db.add(self)
        db.commit()

    @property
    def to_dict(self):
        return {
            "id": self.id,
            "image_url": self.image_url,
            "author": self.author,
            "created": self.created.strftime('%Y-%m-%d'),
        }
Esempio n. 13
0
class Task(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.String)
    day = db.Column(db.String)
    task_date = db.Column(db.String)
    full_date = db.Column(db.String)
    author_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    author = db.relationship("User")
    created = db.Column(db.DateTime, default=datetime.utcnow)

    @classmethod
    def read(cls, task_id):
        task = db.query(Task).get(int(task_id))

        return task

    @classmethod
    def read(cls, task_id):
        task = db.query(Task).get(int(task_id))

        return task