class Country(db.Model): __tablename__ = "country" id = db.Column(db.Integer, primary_key=True, autoincrement=True) country_code = db.Column(db.Integer, nullable=False) panel_provider_id = db.relationship('location_group', backref='id', lazy='dynamic')
class Location(db.Model): __tablename__ = "location" id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(120), index=True, unique=True) external_id = db.relationship('location', secondary=LocationGroup, backref=db.backref('location_group', lazy=True), lazy='subquery') secret_code = db.Column(db.String(120), index=True, unique=True)
class Color(db.Model): __tablename__ = 'color' id = db.Column(db.Integer, primary_key=True, nullable=False, autoincrement=True) nume = db.Column(db.String(20)) def __init__(self, nume): self.nume = nume
class BlacklistToken(db.Model): """ Token Model for storing JWT tokens """ __tablename__ = "blacklist_tokens" id = db.Column(db.Integer, primary_key=True, autoincrement=True) token = db.Column(db.String(500), unique=True, nullable=False) blacklisted_on = db.Column(db.DateTime, nullable=False) def __init__(self, token): self.token = token self.blacklisted_on = datetime.datetime.now()
class Simca(db.Model): tablename = 'simca' id = db.Column(db.Integer, primary_key=True, autoincrement=True, nullable=False) color_id = db.Column(db.Integer, db.ForeignKey('color.id')) simcac = db.relationship('Color', foreign_keys=[color_id], backref='simcacant') cant1 = db.Column(db.Float) cant2 = db.Column(db.Float)
class Post(db.Model): """ Blog Post Model """ __tablename__ = 'post' id = db.Column(db.Integer, db.Sequence('seq_%s' % __tablename__.lower()), primary_key=True) title = db.Column(db.String(150)) slug = db.Column(db.String(100), unique=True) body = db.Column(db.Text) status = db.Column(db.SmallInteger) created_timestamp = db.Column(db.DateTime, default=now(), nullable=False) modified_timestamp = db.Column(db.DateTime, default=now(), onupdate=now()) tags = db.relationship('Tag', secondary=post_tags, backref=db.backref('posts', lazy='dynamic')) def __init__(self, *args, **kwargs): super(Post, self).__init__(*args, **kwargs) # Call parent constructor. self.generate_slug() def generate_slug(self): self.slug = '' if self.title: self.slug = slugify(self.title) def __repr__(self): return '<Post: %s>' % self.title
class Tag(db.Model): """ Tag Model """ __tablename__ = 'tag' id = db.Column(db.Integer, db.Sequence('seq_%s' % __tablename__.lower()), primary_key=True) name = db.Column(db.String(64), unique=True, nullable=False) slug = db.Column(db.String(64), unique=True, nullable=False) def __init__(self, *args, **kwargs): super(Tag, self).__init__(*args, **kwargs) self.slug = slugify(self.name) def __repr__(self): return '<Tag %s>' % self.name
class User(db.Model): __tablename__ = "users" id = db.Column(db.Integer, primary_key=True, autoincrement=True) email = db.Column(db.String(255), unique=True, nullable=False) password = db.Column(db.String(255), nullable=False) registered_on = db.Column(db.DateTime, nullable=False) admin = db.Column(db.Boolean, nullable=False, default=False) language = db.Column(db.String(5), nullable=False, default="en_US") phone = db.Column(db.String(10), nullable=True) city = db.Column(db.String(255), nullable=True) def __init__(self, email, password, language, phone=None, city=None, admin=False): self.email = email self.password = User.generate_password_hash(password) self.registered_on = datetime.datetime.now() self.admin = admin self.language = language self.phone = phone, self.city = city @staticmethod def generate_password_hash(password): return bcrypt.generate_password_hash(password, 10).decode('utf-8') def encode_auth_token(self, user_id): """ Generates Auth Token """ try: payload = { 'exp': datetime.datetime.utcnow() + datetime.timedelta(days=0, minutes=10), 'iat': datetime.datetime.utcnow(), 'sub': user_id } return jwt.encode(payload, app.config.get('SECRET_KEY'), algorithm='HS256') except Exception as e: return e @staticmethod def decode_auth_token(auth_token): """ Decodes the auth token """ payload = jwt.decode(auth_token, app.config.get('SECRET_KEY')) return payload['sub']
class DSPRaw(db.Model): """ Create a DSP raw table """ __tablename__ = 'dsp_raw' id = db.Column(db.Integer, primary_key=True) date = db.Column(db.DateTime, nullable=False) campaign_id = db.Column(db.Integer, nullable=False) campaign = db.Column(db.String(75), nullable=False) impressions = db.Column(db.Float, nullable=False) clicks = db.Column(db.Integer, nullable=False) cost = db.Column(db.Float, nullable=False) created_at = db.Column(db.DateTime, nullable=False, server_default=func.now()) updated_at = db.Column(db.DateTime, nullable=False, server_default=func.now(), onupdate=func.now())
class Carton(db.Model): __tablename__ = 'carton' id = db.Column(db.Integer, primary_key=True, nullable=False, autoincrement=True) client = db.Column(db.String(20)) oras = db.Column(db.String(20)) dimensiune = db.Column(db.String(10)) stampila = db.Column(db.String(10)) stanta = db.Column(db.String(10)) notite = db.Column(db.Text) culoare1_id = db.Column(db.Integer, db.ForeignKey('color.id')) culoare1 = db.relationship('Color', foreign_keys=[culoare1_id], lazy=True, backref='cul1') culoare2_id = db.Column(db.Integer, db.ForeignKey('color.id')) culoare2 = db.relationship('Color', foreign_keys=[culoare2_id], lazy=True, backref='cul2')
class User(UserMixin, db.Model): """ Create an User table """ # Ensures table will be named in plural and not in singular # as is the name of the model __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(60), index=True, unique=True) username = db.Column(db.String(60), index=True, unique=True) first_name = db.Column(db.String(60), index=True) last_name = db.Column(db.String(60), index=True) password_hash = db.Column(db.String(128)) is_admin = db.Column(db.Boolean, default=False) @property def password(self): """ Prevent pasword from being accessed """ raise AttributeError('password is not a readable attribute.') @password.setter def password(self, password): """ Set password to a hashed password """ self.password_hash = generate_password_hash(password) def verify_password(self, password): """ Check if hashed password matches actual password """ return check_password_hash(self.password_hash, password) def __repr__(self): return '<User: {}>'.format(self.username)
from webapp.app import db from webapp.util import slugify, now ###### post_tags = db.Table( 'post_tags', db.Column('tag_id', db.Integer, db.ForeignKey('tag.id')), db.Column('post_id', db.Integer, db.ForeignKey('post.id'))) class Post(db.Model): """ Blog Post Model """ __tablename__ = 'post' id = db.Column(db.Integer, db.Sequence('seq_%s' % __tablename__.lower()), primary_key=True) title = db.Column(db.String(150)) slug = db.Column(db.String(100), unique=True) body = db.Column(db.Text) status = db.Column(db.SmallInteger) created_timestamp = db.Column(db.DateTime, default=now(), nullable=False) modified_timestamp = db.Column(db.DateTime, default=now(), onupdate=now()) tags = db.relationship('Tag', secondary=post_tags, backref=db.backref('posts', lazy='dynamic')) def __init__(self, *args, **kwargs):
class PanelProvider(db.Model): __tablename__ = "panel_provider" id = db.Column(db.Integer, primary_key=True, autoincrement=True) code = db.Column(db.Integer, unique=True)
class Location(db.Model): __tablename__ = "location" id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(120), index=True, unique=True) external_id = db.relationship('location', secondary=LocationGroup, backref=db.backref('location_group', lazy=True), lazy='subquery') secret_code = db.Column(db.String(120), index=True, unique=True) LocationGroup = db.Table( 'location_group', db.Column('id', db.Integer, primary_key=True, autoincrement=True), db.Column('name', db.String(120), index=True, unique=True), db.Column('country_id', db.Integer, db.ForeignKey('country.id')), db.Column('panel_provider_id', db.Integer, db.ForeignKey('panel_provider.id'))) TargetGroup = db.Table( 'location_group', db.Column('id', db.Integer, primary_key=True, autoincrement=True), db.Column('name', db.String(120), index=True, unique=True), db.Column('external_id', db.Integer, db.ForeignKey('country.id')), db.Column('parent_id', db.Integer, db.ForeignKey('panel_provider.id')), db.Column('secret_code', db.Integer, db.ForeignKey('location.secret_code')), db.Column('panel_provider_id', db.Integer, db.ForeignKey('panel_provider.id')))
class Classification(db.Model): """ Create a classification model """ __tablename__ = 'classifications' id = db.Column(db.Integer, primary_key=True) pattern = db.Column(db.String(256), index=True) brand = db.Column(db.String(25), nullable=True) sub_brand = db.Column(db.String(25), nullable=True) dsp = db.Column(db.String(25), nullable=True) use_campaign_id = db.Column(db.Boolean, nullable=False, default=False) use_campaign = db.Column(db.Boolean, nullable=False, default=False) use_placement_id = db.Column(db.Boolean, nullable=False, default=False) use_placement = db.Column(db.Boolean, nullable=False, default=False) created_at = db.Column(db.DateTime, nullable=False, server_default=func.now()) updated_at = db.Column(db.DateTime, nullable=False, server_default=func.now(), onupdate=func.now())
class Report(db.Model): """ Create a Report table """ __tablename__ = 'report' id = db.Column(db.Integer, primary_key=True) date = db.Column(db.DateTime, nullable=False) brand = db.Column(db.String(25), nullable=False) sub_brand = db.Column(db.String(25), nullable=False) ad_campaign_id = db.Column(db.Integer, nullable=False) ad_campaign = db.Column(db.String(75), nullable=False) dsp = db.Column(db.String(25), nullable=False) dsp_campaign_id = db.Column(db.Integer, nullable=False) dsp_campaign = db.Column(db.String(75), nullable=False) ad_impressions = db.Column(db.Float, nullable=False) ad_clicks = db.Column(db.Integer, nullable=False) ad_reach = db.Column(db.Float, nullable=False) dsp_impressions = db.Column(db.Float, nullable=False) dsp_clicks = db.Column(db.Integer, nullable=False) dsp_cost = db.Column(db.Float, nullable=False) created_at = db.Column(db.DateTime, nullable=False, server_default=func.now()) updated_at = db.Column(db.DateTime, nullable=False, server_default=func.now(), onupdate=func.now()) @property def serialize(self): """Return object data in serializeable format""" return { "date": self.date.isoformat(), "brand": self.brand, "sub_brand": self.sub_brand, "ad_campaign_id": self.ad_campaign_id, "ad_campaign": self.ad_campaign, "dsp": self.dsp, "dsp_campaign_id": self.dsp_campaign_id, "dsp_campaign": self.dsp_campaign, "ad_impressions": self.ad_impressions, "ad_clicks": self.ad_clicks, "ad_reach": self.ad_reach, "dsp_impressions": self.dsp_impressions, "dsp_clicks": self.dsp_clicks, "dsp_cost": self.dsp_cost, "created_at": self.created_at.isoformat(), "updated_at": self.updated_at.isoformat() }
class DCM(db.Model): """ Create a DCM classified table """ __tablename__ = 'dcm_classified' id = db.Column(db.Integer, primary_key=True) date = db.Column(db.DateTime, nullable=False) campaign_id = db.Column(db.Integer, nullable=False) campaign = db.Column(db.String(75), nullable=False) placement_id = db.Column(db.Integer, nullable=False) placement = db.Column(db.String(75), nullable=False) impressions = db.Column(db.Float, nullable=False) clicks = db.Column(db.Integer, nullable=False) reach = db.Column(db.Float, nullable=False) brand = db.Column(db.String(25), nullable=False) sub_brand = db.Column(db.String(25), nullable=False) dsp = db.Column(db.String(25), nullable=False) created_at = db.Column(db.DateTime, nullable=False, server_default=func.now()) updated_at = db.Column(db.DateTime, nullable=False, server_default=func.now(), onupdate=func.now())