コード例 #1
0
class Character(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(150))
    description = db.Column(db.String(200))
    comics_appeared_in = db.Column(db.Integer)
    super_power = db.Column(db.String(150))
    date_created = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)
    user_id = db.Column(db.String, db.ForeignKey('user.token'), nullable=False)

    def __init__(self, name, description, comics_appeared_in, super_power,
                 user_id):
        self.name = name
        self.description = description
        self.comics_appeared_in = comics_appeared_in
        self.super_power = super_power
        self.user_id = user_id

    def __repr__(self):
        return f'The following Character has been added: {self.name} which belongs to {self.user_id}'

    def to_dict(self):
        return {
            "id": self.id,
            "name": self.name,
            "description": self.description,
            "comics_appeared_in": self.comics_appeared_in,
            "super_power": self.super_power
        }
コード例 #2
0
class User(db.Model, UserMixin):
    id = db.Column(db.String, primary_key = True )
    first_name = db.Column(db.String(150), nullable = True, default = '')
    last_name = db.Column(db.String(150), nullable = True, default = '')
    email = db.Column(db.String(150), nullable = False)
    password = db.Column(db.String, nullable = True, default = '')
    g_auth_verify = db.Column(db.Boolean, default = False)
    token = db.Column(db.String, default = '', unique = True)                         #used for api token, to give to user for specific amount of time, needs a unique flag
    data_created = db.Column(db.DateTime, nullable = False, default = datetime.utcnow)
    marvel = db.relationship('Marvel', backref = 'owner', lazy = True)

    def __init__(self, email,first_name = '', last_name = '', id = '', password = '', token = '', g_auth_verify = False):
        self.id = self.set_id()
        self.first_name = first_name
        self.last_name = last_name
        self.password = self.set_password(password)
        self.email = email
        self.token = self.set_token(24)
        self.g_auth_verify = g_auth_verify

    def set_token(self,length):
        return secrets.token_hex(length)
    
    def set_id(self):
        return str(uuid.uuid4())

    def set_password(self,password):
        self.pw_hash = generate_password_hash(password)
        return self.pw_hash
    
    def __repr__(self):
        return f'User {self.email} has been added to the database'
コード例 #3
0
ファイル: models.py プロジェクト: robert1611/Marvel-RD
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(150), nullable=False, default='')
    password = db.Column(db.String, nullable=True, default='')
    g_auth_verify = db.Column(db.Boolean, default=False)
    token = db.Column(db.String, default='')
    date_created = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)
    #character = db.Column(db.Integer, db.ForeignKey('marvel.id'), nullable = False)
    character = db.Column(db.Integer, nullable=True)

    # email has to be specified, everything else can be empty
    # haven't entered token g_auth yet

    def __init__(self, username, password='', g_auth_verify=False):

        self.id = self.set_id()
        self.username = username
        self.password = self.set_password(password)
        self.token = self.set_token(24)
        self.g_auth_verify = g_auth_verify

    def set_token(self, length):
        return secrets.token_hex(length)

    def set_id(self):
        return str(uuid.uuid4())

    def set_password(self, password):
        self.pw_hash = generate_password_hash(password)
        return self.pw_hash

    def __repr__(self):
        return f'User {self.username} has been added to the database'
コード例 #4
0
ファイル: models.py プロジェクト: robert1611/Marvel-RD
class Marvel(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(150))
    description = db.Column(db.String(150))
    comics_appeared_in = db.Column(db.Integer)
    super_power = db.Column(db.String(150))
    date_created = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)
    owner = db.Column(db.String, db.ForeignKey('user.token'), nullable=False)
    character = db.Column(db.String(150))

    def __init__(self, name, description, comics_appeared_in, super_power,
                 owner, character):

        self.name = name
        self.description = description
        self.comics_appeared_in = comics_appeared_in
        self.super_power = super_power
        self.owner = owner
        self.character = character

    def set_id(self):
        return str(uuid.uuid4())

    def __repr__(self):
        return f'The following Marvel has been added {self.name}'

    def __str__(self):
        return f"{self.name}\n\nDescription:\n{self.description}\n\nSuperpowers:\n{self.super_power}"

    def to_dict(self):
        return {
            "id": self.id,
            "name": self.name,
            "description": self.description,
            "comics_appeared_in": self.comics_appeared_in,
            "super_power": self.super_power,
            "date_created": self.date_created,
            "character": self.character
        }
コード例 #5
0
class User(db.Model, UserMixin):
    id = db.Column(db.String, primary_key=True)
    first_name = db.Column(db.String(150), nullable=True, default='')
    last_name = db.Column(db.String(150), nullable=True, default='')
    email = db.Column(db.String(150), nullable=False)
    password = db.Column(db.String, nullable=True, default='')
    g_auth_verify = db.Column(db.Boolean, default=False)
    token = db.Column(db.String, default='', unique=True)
    date_created = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)
    character = db.relationship('Character', backref='owner', lazy=True)

    def __init__(self,
                 email,
                 first_name='',
                 last_name='',
                 id='',
                 password='',
                 token='',
                 g_auth_verify=False):
        self.id = self.set_id()
        self.first_name = first_name
        self.last_name = last_name
        self.password = self.set_password(password)
        self.email = email
        self.token = self.set_token(24)
        self.g_auth_verify = g_auth_verify

    def set_id(self):
        return str(uuid.uuid4())

    def set_password(self, password):
        self.pw_hash = generate_password_hash(password)
        return self.pw_hash

    def __repr__(self):
        return f'User {self.email} has been added to the database'
コード例 #6
0
class Character(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    current_alias = db.Column(db.String(150), nullable=False)
    real_name = db.Column(db.String(150), nullable=True, default='')
    origin = db.Column(db.String(150), nullable=True, default='')
    universe = db.Column(db.String(150), nullable=True, default='')
    power = db.Column(db.String(150), nullable=True, default='')
    comics_appeared_in = db.Column(db.Integer, nullable=True, default=0)
    date_created = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)
    user_id = db.Column(db.String, db.ForeignKey('user.token'), nullable=False)

    def __init__(self, current_alias, real_name, origin, universe, power,
                 comics_appeared_in, user_id):
        self.current_alias = current_alias
        self.real_name = real_name
        self.origin = origin
        self.universe = universe
        self.power = power
        self.comics_appeared_in = comics_appeared_in
        self.user_id = user_id

    def __repr__(self):
        return self.current_alias

    def to_dict(self):
        return {
            "id": self.id,
            "current_alias": self.current_alias,
            "real_name": self.real_name,
            "origin": self.origin,
            "universe": self.universe,
            "power": self.power,
            "comics_appeared_in": self.comics_appeared_in,
            "date_created": self.date_created,
        }