Esempio n. 1
0
class User(db.Model):
    __tablename__ = 'users'

    id = db.Column(db.Integer(), primary_key=True)
    username = db.Column(db.Unicode())
    password = db.Column(db.String())
    email = db.Column(db.String(128), unique=True)
Esempio n. 2
0
class Role(db.Model, RoleMixin):
    id = db.Column(db.Integer(), primary_key = True)
    name = db.Column(db.String(80), unique = True)
    description = db.Column(db.String(255))

    def __str__(self):
        return self.name
Esempio n. 3
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key = True)
    first_name = db.Column(db.String(255))
    last_name = db.Column(db.String(255))
    email = db.Column(db.String(255), unique = True, nullable = False)
    password = db.Column(db.String(255), nullable = False)
    active = db.Column(db.Boolean(), nullable = False)
    roles = db.relationship('Role', secondary = roles_users, backref = 'users')

    def __str__(self):
        return self.first_name + " " + self.last_name + " <" + self.email + ">"
Esempio n. 4
0
class User(db.Model):
    __tablename__ = 'users'

    id = db.Column(db.Integer(), primary_key=True)
    password = db.Column(db.String())
    email = db.Column(db.String(128), nullable=False, unique=True)
    first_name = db.Column(db.Unicode(30))
    last_name = db.Column(db.Unicode(30))
    facebook_id = db.Column(db.Unicode(256))

    def password_match(self, input_password):
        return pbkdf2_sha256.verify(input_password, self.password)
Esempio n. 5
0
class Post(db.Model):
    id_post = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(80))
    content = db.Column(db.String(255))
    logo = db.Column(db.String(255), default=None, nullable=True)

    create_date = db.Column(db.DateTime, default=datetime.date.today())
    update_date = db.Column(db.DateTime, default=datetime.date.today())

    tag_id = db.Column(db.Integer, db.ForeignKey('tag.id_tag'))
    blog_id = db.Column(db.Integer, db.ForeignKey('blog.id_blog'))

    status = db.Column(db.Boolean, default=True)

    _tablename_ = 'post'
Esempio n. 6
0
class Megazine(db.Model):
    # __tablename__ = 'megazine'

    id = db.Column(db.Integer, primary_key=True)
    id_pub = db.Column(db.String(150), unique=True)
    id_author = db.Column(db.String(150), db.ForeignKey('user.id_pub'))
    title = db.Column(db.String(40))
    about = db.Column(db.String(100))
    timestamp = db.Column(db.DateTime, default=datetime.now())

    def __init__(self, id_author, title, about):
        self.id_pub = 'megazine-' + str(uuid1())
        self.id_author = id_author
        self.title = title
        self.about = about

    @classmethod
    def find_by_id(cls, id_pub):
        return cls.query.filter_by(id_pub=id_pub).first()

    @classmethod
    def find_by_author(cls, id_author):
        return cls.query.filter_by(id_author=id_author).first()

    # simpan
    def save_to_db(self):
        db.session.add(self)
        db.session.commit()

    # hapus
    def delete_to_db(self):
        db.session.delete(self)
        db.session.commit()

    def json(self):
        return {
            'id_pub': self.id_pub,
            'id_author': self.id_author,
            'title': self.title,
            'about': self.about,
            'timestamp': str(self.timestamp)
        }

    # di gunakan untuk debug
    def __repr__(self):
        return ('title {}'.format(self.title))
Esempio n. 7
0
class Message(db.Model):
    __tablename__ = 'chat_messages'

    id = db.Column(db.Integer(), primary_key=True)
    text = db.Column(db.Unicode())
    created_date = db.Column(db.DateTime())
    room_id = db.Column(db.Integer(), db.ForeignKey('chat_rooms.id'))
    user_name = db.Column(db.String(), db.ForeignKey('users.username'))
Esempio n. 8
0
class DemoModel(db.Model):
    """This is a demo model that should be removed in production.

    Note:
        This is only a demo model provided by the template library
        Magee Flask-RESTful. It should only be used for testing and 
        demo. Please make sure to remove the model in production mode.
        For more information on how to use Flask-SQLAlchemy, visit
        https://flask-sqlalchemy.palletsprojects.com/en/2.x/

    Attributes:
        id (Integer): the object's id
        value (String): a string belongs to the entry

    """
    __tablename__ = 'demo'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    value = db.Column(db.String(255))

    def __init__(self, value):
        # Clean the data
        value = str(value).strip()

        # Store the data in the object
        self.value = value

    def save(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()

    def json(self):
        return {'id': self.id, 'value': self.value}

    def __repr__(self):
        return f'<Demo(id={self.id}, value="{self.value}")>'

    @classmethod
    def find_by_id(cls, _id):
        return cls.query.filter_by(id=_id).first()

    @classmethod
    def find_by_value(cls, value):
        return cls.query.filter_by(value=value).all()

    @classmethod
    def search(cls, _id=None, value=None):
        queries = []
        if _id:
            queries.append(DemoModel.id == _id)
        if value:
            queries.append(DemoModel.value == value)
        return [cls.query.filter(*queries).all()]
Esempio n. 9
0
class UserModel(db.Model):
    """The model related to users.

    To satisfy more requirements, add more fields to the model.
    Make sure to register them in the constructor.

    Note:
        Changing the name of the field `id` is not recommended since JWT
        will, by default, look for the attribute `id` in the model. For
        more information if the name of the field is changed, consult 
        https://pythonhosted.org/Flask-JWT/ 
        for the topic `identity_handler(callback)`

    Attributes:
        id (Integer): user's id
        username (String): user's username
        password_hash (LargeBinary): user's hashed password

    """
    __tablename__ = 'user'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(32))
    password_hash = db.Column(db.LargeBinary(60))

    def __init__(self, username, password):
        # Clean the data
        username = str(username).strip()
        password = str(password).strip()

        if not is_valid_username(username):
            raise ErrorMessagePromise('INVALID_USERNAME')

        if not is_valid_password(password):
            raise ErrorMessagePromise('INVALID_PASSWORD')

        # Hash the password
        password_hash = hash_data(password)

        # Store the data in the object
        self.username = username
        self.password_hash = password_hash

    def save(self):
        db.session.add(self)
        db.session.commit()

    @classmethod
    def find_by_username(cls, username):
        return cls.query.filter_by(username=username).first()

    @classmethod
    def find_by_id(cls, _id):
        return cls.query.filter_by(id=_id).first()
Esempio n. 10
0
class Author(db.Model):
    id_author = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(120), unique=True)
    name = db.Column(db.String(80))
    password = db.Column(db.String(255))
    website = db.Column(db.String(255), nullable=True)
    profile = db.Column(db.String(255), default=None, nullable=True)

    create_date = db.Column(db.DateTime, default=datetime.date.today())
    update_date = db.Column(db.DateTime, default=datetime.date.today())

    status = db.Column(db.Boolean, default=True)

    _tablename_ = 'author'

    def __init__(self, name=None, email=None, password=None):
        self.name = name
        self.email = email
        self.password = password
        self.create_date = datetime.datetime.now()
        self.update_date = datetime.datetime.now()
Esempio n. 11
0
class Blog(db.Model):
	id_blog = db.Column(db.Integer, primary_key = True)
	title = db.Column(db.String(80))
	email = db.Column(db.String(255), default = '*****@*****.**', unique = True) 
	password = db.Column(db.String(255))
	description = db.Column(db.String(255), default = None, nullable = True) 
	logo = db.Column(db.String(255), default = None, nullable = True)
	website = db.Column(db.String(255))
	about = db.Column(db.String(255))
	author = db.Column(db.String(80))
	create_date = db.Column(db.DateTime, default=datetime.datetime.now())
	update_date = db.Column(db.DateTime, default=datetime.datetime.now())
	
	genre = db.Column(db.String(255))

	status = db.Column(db.Boolean, default=True)	

	_tablename_='blog'
Esempio n. 12
0
class Tag(db.Model):
    id_tag = db.Column(db.Integer, primary_key=True)

    name = db.Column(db.String(80))

    #blog_id = db.Column(db.Integer, db.ForeignKey('blog.id_blog'))
    post_set = db.relationship('Post', backref='tag', lazy='dynamic')

    create_date = db.Column(db.DateTime, default=datetime.date.today())
    update_date = db.Column(db.DateTime, default=datetime.date.today())

    status = db.Column(db.Boolean, default=True)

    _tablename_ = 'tag'
Esempio n. 13
0
class UserModel(db.Model):
    __tablename__ = 'user'

    id = db.Column(db.Integer, primary_key=True)
    id_pub = db.Column(db.String(150), unique=True)
    first_name = db.Column(db.String(20), nullable=False)
    last_name = db.Column(db.String(20), nullable=False)
    password = db.Column(db.String(150), nullable=False)
    email = db.Column(db.String(40), unique=True, nullable=False)
    mobile_phone = db.Column(db.Integer, nullable=False)
    gender = db.Column(db.String(10), default=('L', 'P'), nullable=False)
    about = db.Column(db.String(150))
    interest = db.Column(db.String(150))
    semester = db.Column(db.String(2),
                         default=('1', '2', '3', '4'),
                         nullable=False)
    admin = db.Column(db.Boolean, default=False)
    mentor = db.Column(db.Boolean, default=False)
    articles = db.relationship('Article', backref='user', lazy=True)
    events = db.relationship('Event', backref='user', lazy=True)
    megazines = db.relationship('Megazine', backref='user', lazy=True)
    date_register = db.Column(db.DateTime, default=datetime.now())

    def __init__(self, first_name, last_name, password, email, mobile_phone,
                 gender, about, interest, semester):
        self.id_pub = "member-" + str(uuid1())
        self.first_name = first_name
        self.last_name = last_name
        self.password = password
        self.email = email
        self.mobile_phone = mobile_phone
        self.gender = gender
        self.about = about
        self.interest = interest
        self.semester = semester

    @classmethod
    def find_by_id(cls, id_pub):
        return cls.query.filter_by(id_pub=id_pub).first()

    @classmethod
    def find_by_email(cls, email):
        return cls.query.filter_by(email=email).first()

    @classmethod
    def find_by_phone(cls, mobile_phone):
        return cls.query.filter_by(mobile_phone=mobile_phone).first()

    # simpan
    def save_to_db(self):
        db.session.add(self)
        db.session.commit()

    # hapus
    def delete_to_db(self):
        db.session.delete(self)
        db.session.commit()

    def json(self):
        return {
            'id_pub': self.id_pub,
            'first_name': self.first_name,
            'last_name': self.last_name,
            'email': self.email,
            'mobile_phone': self.mobile_phone,
            'admin': self.admin,
            'gender': self.gender,
            'about': self.about,
            'interest': self.interest,
            'date_register': str(self.date_register),
            'semester': self.semester
        }

    # di gunakan untuk debug
    def __repr__(self):
        return ('name {} {}'.format(self.first_name, self.last_name))