Ver código fonte

Renommé la classe Content en Post, quelques ajouts en plus

master
Darks 1 mês atrás
pai
commit
420117f95c
Acessado por: Darks <l.gatin@neuf.fr> ID da chave GPG: F61F10FA138E797C
4 arquivos alterados com 47 adições e 24 exclusões
  1. 0
    20
      app/models/contents.py
  2. 42
    0
      app/models/post.py
  3. 3
    4
      app/models/users.py
  4. 2
    0
      config.py

+ 0
- 20
app/models/contents.py Ver arquivo

@@ -1,20 +0,0 @@
from datetime import datetime
from app import db
from app.models.users import *


class Content(db.Model):
__tablename__ = 'content'
id = db.Column(db.Integer, primary_key=True)
type = db.Column(db.String(20))
__mapper_args__ = {
'polymorphic_identity': __tablename__,
'polymorphic_on': type
}
# Standalone properties
data = db.Column(db.Text(convert_unicode=True))
date_created = db.Column(db.DateTime, default=datetime.now)
date_modified = db.Column(db.DateTime, default=datetime.now)
# Relationships
author_id = db.Column(db.ForeignKey('user.id'))
author = db.relationship("User", back_populates="contents")

+ 42
- 0
app/models/post.py Ver arquivo

@@ -0,0 +1,42 @@
from datetime import datetime
from app import db
from app.models.users import *


class Post(db.Model):
__tablename__ = 'post'
id = db.Column(db.Integer, primary_key=True)
type = db.Column(db.String(20))
__mapper_args__ = {
'polymorphic_identity': __tablename__,
'polymorphic_on': type
}
# Standalone properties
text = db.Column(db.Text(convert_unicode=True))
date_created = db.Column(db.DateTime, default=datetime.now)
date_modified = db.Column(db.DateTime, default=datetime.now)
# Relationships
author_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

def __init__(self, author, text):
""" Create a Post """
self.text = text
if type(author) == Member:
author = author.id
self.author_id = author

def update(self, text):
""" Update a post. Check whether the request sender has the right to do
this! """
self.text = text
self.date_modified = datetime.now()

def change_ownership(self, new_author):
""" Change ownership of a post. Check whether the request sender has the
right to do this! """
if type(new_author) == Member:
new_author = new_author.id
self.author_id = new_author

def __repr__(self):
return f'<Post: #{self.id}>'

+ 3
- 4
app/models/users.py Ver arquivo

@@ -2,7 +2,7 @@ from datetime import date
from app import db
from flask import flash
from flask_login import UserMixin
from app.models.contents import Content
from app.models.post import Post
from app.models.privs import SpecialPrivilege, Group, GroupMember, \
GroupPrivilege
from app.models.trophies import Trophy, TrophyMember
@@ -14,7 +14,7 @@ import re
import math
import app

# User: Website user that performs actions on the content
# User: Website user that performs actions on the post
class User(UserMixin, db.Model):
__tablename__ = 'user'

@@ -25,7 +25,7 @@ class User(UserMixin, db.Model):
type = db.Column(db.String(30))

# TODO: add good relation
contents = db.relationship('Content', back_populates="author")
posts = db.relationship('Post', backref="author", lazy=False)

__mapper_args__ = {
'polymorphic_identity': __tablename__,
@@ -94,7 +94,6 @@ class Member(User, db.Model):
# Relations
trophies = db.relationship('Trophy', secondary=TrophyMember,
back_populates='owners')
# tests = db.relationship('Test', back_populates='author')

def __init__(self, name, email, password):
"""Register a new user."""

+ 2
- 0
config.py Ver arquivo

@@ -21,3 +21,5 @@ class V5Config(object):
USER_NAME_MAXLEN = 32
# Minimum password length for new users and new passwords
PASSWORD_MINLEN = 10
# Maximum topic name length
TOPIC_NAME_MAXLEN = 32

Carregando…
Cancelar
Salvar