Exemplo n.º 1
0
class Admiration(db.Model):
    """ Admiration Model """

    # table name
    __tablename__ = 'admirations'

    id = db.Column(db.BIGINT, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    admire_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=True)
    beat_id = db.Column(db.Integer, db.ForeignKey('medias.id'), nullable=True)
    created_at = db.Column(db.DateTime)
    modified_at = db.Column(db.DateTime)

    # relationship
    beat = db.relationship("Media",
                           backref=db.backref("medias", uselist=False))

    # class constructor
    def __init__(self, data):
        """ Class constructor """

        self.user_id = data.get('user_id')
        self.beat_id = data.get('beat_id', None)
        self.admire_id = data.get('admire_id', None)
        self.created_at = datetime.datetime.utcnow()
        self.modified_at = datetime.datetime.utcnow()

    def save(self):
        """ save a new admiration """

        db.session.add(self)
        db.session.commit()

    def delete(self):
        """ delete a admiration """
        db.session.delete(self)
        db.session.commit()

    @staticmethod
    def user_admire_song(beat_id, user_id):
        """ if exist beat_id admired by user  """

        return Admiration.query.filter_by(user_id=user_id,
                                          beat_id=beat_id).first()
Exemplo n.º 2
0
class User(db.Model):
    """ User Model """

    # table name
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)
    right = db.Column(db.Integer, default=0)
    name = db.Column(db.String(128))
    if_choice = db.Column(db.Integer, default=0)
    beats_id_liked_list = db.Column(db.ARRAY(db.Integer), default=[])
    beats_id_listened_list = db.Column(db.ARRAY(db.Integer), default=[])
    email = db.Column(db.String(125), unique=True, nullable=True)
    profile_id = db.Column(db.Integer, db.ForeignKey('profiles.id'))
    social = db.Column(db.String(128), nullable=True)
    social_id = db.Column(db.String(128), unique=True, nullable=True)
    fileStorage_key = db.Column(db.String(100), unique=True)
    user_type = db.Column(db.String(50), default=USER_AUDITOR_PRO)
    password = db.Column(db.String(255), nullable=True)
    created_at = db.Column(db.DateTime)
    modified_at = db.Column(db.DateTime)

    # All Users Relationship
    medias = db.relationship(Media, lazy='dynamic')
    carts = db.relationship(Carts, lazy='dynamic')
    services = db.relationship(Services, lazy='dynamic')
    options = db.relationship(Options, lazy='dynamic')
    all_admires = db.relationship('Admiration',
                                  foreign_keys=u_f,
                                  backref='user',
                                  lazy='dynamic',
                                  uselist=True)
    my_admirers = db.relationship('Admiration',
                                  foreign_keys=a_f,
                                  backref='admire',
                                  lazy='dynamic',
                                  uselist=True)
    purchase_history = db.relationship(PaymentHistory,
                                       foreign_keys=p_f,
                                       backref='buyer',
                                       lazy='dynamic',
                                       uselist=True)
    purchased_history = db.relationship(PaymentHistory,
                                        foreign_keys=_h,
                                        backref='artist',
                                        lazy='dynamic',
                                        uselist=True)
    booking_list = db.relationship('Reservations',
                                   foreign_keys=booking_f,
                                   backref='sender_reservation',
                                   lazy='dynamic')
    reservation_list = db.relationship('Reservations',
                                       foreign_keys=_f,
                                       backref='recipient_reservation',
                                       lazy='dynamic')
    profile = db.relationship("Profiles",
                              backref=db.backref("profiles", uselist=False))
    reset_password_key = db.relationship("KeyResetPassword",
                                         backref=db.backref(
                                             "key_reset_passwords",
                                             uselist=False))
    banking = db.relationship("BankingDetails",
                              backref=db.backref("banking_details",
                                                 uselist=False))
    payment = db.relationship(Payment,
                              backref=db.backref("payment", uselist=False))
    condition_globals = db.relationship("ConditionGlobals",
                                        backref=db.backref("condition_globals",
                                                           uselist=False))
    stars = db.relationship(Stars, backref=db.backref("stars", uselist=False))
    ContractBeat = db.relationship(ContractBeatMaking, lazy='dynamic')
    prestige_sends = db.relationship('Prestige',
                                     foreign_keys='Prestige.sender_id',
                                     backref='sender',
                                     lazy='dynamic')
    prestige_receipts = db.relationship('Prestige',
                                        foreign_keys='Prestige.recipient_id',
                                        backref='recipient',
                                        lazy='dynamic')

    # class constructor
    def __init__(self, data):
        """ Class constructor """

        self.name = data.get('name')
        self.profile_id = data.get('profile_id')
        self.email = data.get('email')
        self.social = data.get('social')
        self.user_type = data.get('user_type')
        self.social_id = data.get('social_id')
        self.password = None if data.get(
            'social', None) else self.generate_hash(data.get('password'))
        self.beats_id_liked_list = data.get("beats_id_liked_list", None)
        self.beats_id_listened_list = data.get("beats_id_listened_list", None)
        self.fileStorage_key = data.get('fileStorage_key')
        self.created_at = datetime.datetime.utcnow()
        self.modified_at = datetime.datetime.utcnow()

    def save(self):
        """ save a new user """

        db.session.add(self)
        db.session.commit()

    def update_password(self, password):
        """ reset a password """

        self.password = self.generate_hash(password)
        self.modified_at = datetime.datetime.utcnow()
        db.session.commit()

    def update(self, data):
        """

        Args:
            data:
        """
        self.name = data.get('name')
        self.email = data.get('email')
        self.right = data.get('right')
        self.user_type = data.get('user_type')
        self.if_choice = data.get('if_choice')
        self.beats_id_liked_list = data.get("beats_id_liked_list")
        self.beats_id_listened_list = data.get("beats_id_listened_list")
        self.modified_at = datetime.datetime.utcnow()
        db.session.commit()

    def delete(self):
        """ delete user """

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

    def check_hash(self, password):
        """

        Args:
            password:

        Returns:

        """
        return bcrypt.check_password_hash(self.password, password)

    @staticmethod
    def generate_hash(password):
        """ generate password hash """

        return bcrypt.generate_password_hash(password,
                                             rounds=10).decode("utf-8")

    @staticmethod
    def get_one_user(user_id):
        """ get on user by user id """

        return User.query.get(user_id)

    @staticmethod
    def get_user_by_email(email):
        """ get one user by email """

        return User.query.filter_by(email=email).first()

    @staticmethod
    def get_user_by_social_id(social_id):
        """ get user by social id """

        return User.query.filter_by(social_id=social_id).first()

    @staticmethod
    def all_beat_maker_in_three_last_month():
        """ get all BeatMaker at the six last month """

        last_6_month = datetime.datetime.now() + relativedelta(months=-6)
        return User.query.filter(User.created_at > last_6_month, User.user_type == USER_ARTIST_BEATMAKER) \
            .limit(10) \
            .all()
Exemplo n.º 3
0
class PaymentHistory(db.Model):
    """ Payment history Model """

    # table name
    __tablename__ = 'payment_history'

    id = db.Column(db.Integer, primary_key=True)
    artist_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    buyer_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=True)
    media_id = db.Column(db.Integer, db.ForeignKey('medias.id'), nullable=True)
    reference = db.Column(db.String(100))
    name = db.Column(db.String(100), nullable=False)
    lastname = db.Column(db.String(100), nullable=True)
    email = db.Column(db.String(100), nullable=False)
    address = db.Column(db.String(200), nullable=False)
    city = db.Column(db.String(100), nullable=False)
    postal_code = db.Column(db.Integer, nullable=False)
    phone = db.Column(db.String(200), nullable=True, default="")
    ip_address = db.Column(db.String(100))
    artist_amount = db.Column(db.Float(), nullable=True)
    type = db.Column(db.String(150))
    paid = db.Column(db.BOOLEAN, default=False)
    service_fee = db.Column(db.BOOLEAN, default=False)
    refund = db.Column(db.BOOLEAN, default=False)
    tva = db.Column(db.Float(), nullable=True)
    isl_amount = db.Column(db.Float(), nullable=True)
    total_amount = db.Column(db.Float(), nullable=True)
    licenses_name = db.Column(db.String(50), nullable=True)
    created_at = db.Column(db.DateTime)
    modified_at = db.Column(db.DateTime)
    media = db.relationship("Media",
                            backref=db.backref("media_payment_story",
                                               uselist=False))

    # class constructor
    def __init__(self, data):
        """ Class constructor """

        self.tva = data.get('tva')
        self.type = data.get('type')
        self.name = data.get('name')
        self.paid = data.get('paid')
        self.service_fee = data.get('service_fee')
        self.refund = data.get('refund')
        self.lastname = data.get('lastname')
        self.email = data.get('email')
        self.address = data.get('address')
        self.city = data.get('city')
        self.postal_code = data.get('postal_code')
        self.phone = data.get('phone')
        self.ip_address = data.get('ip_address')
        self.buyer_id = data.get('buyer_id')
        self.artist_id = data.get('artist_id')
        self.reference = data.get('reference')
        self.isl_amount = data.get('isl_amount')
        self.media_id = data.get('media_id')
        self.total_amount = data.get('total_amount')
        self.licenses_name = data.get('licenses_name')
        self.artist_amount = data.get('artist_amount')
        self.created_at = datetime.datetime.utcnow()
        self.modified_at = datetime.datetime.utcnow()

    def save(self):
        """save a new payment """

        db.session.add(self)
        db.session.commit()

    def update(self, data):
        """ update a payment """

        self.tva = data.get('tva')
        self.type = data.get('type')
        self.name = data.get('name')
        self.paid = data.get('paid')
        self.service_fee = data.get('service_fee')
        self.refund = data.get('refund')
        self.lastname = data.get('lastname')
        self.email = data.get('email')
        self.address = data.get('address')
        self.city = data.get('city')
        self.postal_code = data.get('postal_code')
        self.phone = data.get('phone')
        self.media_id = data.get('media_id')
        self.ip_address = data.get('ip_address')
        self.buyer_id = data.get('buyer_id')
        self.artist_id = data.get('artist_id')
        self.reference = data.get('reference')
        self.isl_amount = data.get('isl_amount')
        self.total_amount = data.get('total_amount')
        self.licenses_name = data.get('licenses_name')
        self.artist_amount = data.get('artist_amount')
        self.modified_at = datetime.datetime.utcnow()
        db.session.commit()

    def delete(self):
        """ delete a payment """

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

    @staticmethod
    def get_payment_history_by_id(payment_history_id):
        """ get a payment by id """

        return PaymentHistory.query.filter_by(id=payment_history_id).first()

    @staticmethod
    def get_payment_history_by_reference(reference):
        """ get a payment by reference """

        return PaymentHistory.query.filter_by(reference=reference).first()
Exemplo n.º 4
0
class Media(db.Model):
    """ Media Model """

    # table name
    __tablename__ = 'medias'

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(255), nullable=False)
    description = db.Column(db.String(255), nullable=True)
    photo = db.Column(db.String(255), nullable=True)
    basic_price = db.Column(db.Float(), nullable=True)
    silver_price = db.Column(db.Float(), nullable=True)
    gold_price = db.Column(db.Float(), nullable=True)
    platinum_price = db.Column(db.Float(), nullable=True)
    genre = db.Column(db.String(155), nullable=False)
    artist = db.Column(db.String(125), nullable=False)
    artist_tag = db.Column(db.String(255), nullable=True)
    stems = db.Column(db.String(255), nullable=True)
    wave = db.Column(db.String(255), nullable=True)
    mp3 = db.Column(db.String(255), nullable=True)
    share = db.Column(db.Integer, default=0)
    time = db.Column(db.String(10))
    listened = db.Column(db.Integer, default=0)
    bpm = db.Column(db.Float, default=0.0)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    created_at = db.Column(db.DateTime)
    modified_at = db.Column(db.DateTime)

    # Relationship
    prestige = db.relationship(Prestige,
                               lazy='dynamic',
                               cascade="all, delete, save-update")
    admirations = db.relationship(Admiration,
                                  cascade="all, delete, save-update",
                                  lazy='dynamic')

    # class constructor
    def __init__(self, data):
        """ Class constructor """

        self.user_id = data.get('user_id')
        self.title = data.get('title')
        self.listened = 0
        self.photo = data.get('photo')
        self.bpm = data.get('bpm', 0)
        self.time = data.get('time')
        self.mp3 = data.get('mp3')
        self.stems = data.get('stems')
        self.share = data.get('share')
        self.wave = data.get('wave')
        self.artist_tag = data.get('artist_tag')
        self.description = data.get('description') if data.get(
            'description') else data.get('Description')
        self.artist = data.get('artist', data.get('Artist'))
        self.basic_price = data.get('basic_price', None)
        self.silver_price = data.get('silver_price', None)
        self.gold_price = data.get('gold_price', None)
        self.platinum_price = data.get('platinum_price', None)
        self.genre = data.get('genre') if data.get('genre') else data.get(
            'Genre')
        self.created_at = datetime.datetime.utcnow()
        self.modified_at = datetime.datetime.utcnow()

    def save(self):
        """save a new media """

        db.session.add(self)
        db.session.commit()
        add_new_doc(self, MediaSchema(), index="beats", doc_type="songs")

    def update(self, data):
        """ update one media """

        self.title = data.get('title')
        self.bpm = data.get('bpm')
        self.description = data.get('description')
        self.artist = data.get('artist')
        self.photo = data.get('photo')
        self.genre = data.get('genre')
        self.basic_price = data.get('basic_price')
        self.silver_price = data.get('silver_price')
        self.gold_price = data.get('gold_price')
        self.platinum_price = data.get('platinum_price')
        self.time = data.get('time')
        self.mp3 = data.get('mp3')
        self.stems = data.get('stems')
        self.share = data.get('share')
        self.wave = data.get('wave')
        self.artist_tag = data.get('artist_tag')
        self.listened = data.get('listened')
        self.modified_at = datetime.datetime.utcnow()
        db.session.commit()
        update_doc(self, MediaSchema(), index="beats", doc_type="songs")

    def delete(self):
        """ delete one media """

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

    @staticmethod
    def get_song_by_id(song_id):
        """ get one song by id """

        return Media.query.filter_by(id=song_id).first()

    @staticmethod
    def isl_playlist_beats():
        """ Return 10 of beats isl playlist """

        try:
            _min = db.session.query(db.func.max(Media.listened)).scalar() / 2
            return Media.query \
                .filter(Media.listened < round(_min + (_min / 2)), Media.listened > round(_min - (_min / 2))) \
                .limit(20) \
                .all()
        except TypeError:
            return None
Exemplo n.º 5
0
class Options(db.Model):
    """ Options Model """

    __tablename__ = 'options'

    id = db.Column(db.BIGINT, primary_key=True)
    special_dates = db.Column(JSON, default={})
    name = db.Column(db.String(200), nullable=False)
    description = db.Column(db.Text(), nullable=True)
    artist_tagged = db.Column(db.String(200), nullable=False)
    price = db.Column(db.Float(), nullable=False, default=1.00)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    services_id_list = db.Column(db.ARRAY(db.Integer), default=[])
    materials_id = db.Column(db.Integer, db.ForeignKey('materials.id'))
    created_at = db.Column(db.DateTime)
    modified_at = db.Column(db.DateTime)
    material = db.relationship(
        "Materials",
        cascade="all, delete, save-update",
        backref=db.backref("materials_of_options", uselist=False)
    )

    # class constructor
    def __init__(self, data):
        """ Class constructor """

        self.name = data.get('name')
        self.price = data.get('price')
        self.user_id = data.get('user_id')
        self.description = data.get('description')
        self.materials_id = data.get('materials_id')
        self.artist_tagged = data.get('artist_tagged')
        self.special_dates = data.get('special_dates')
        self.services_id_list = data.get('services_id_list')
        self.created_at = datetime.datetime.utcnow()
        self.modified_at = datetime.datetime.utcnow()

    def save(self):
        """ save a Options """

        db.session.add(self)
        db.session.commit()
        add_new_doc(self, OptionsSchema(), index="options", doc_type="option")

    def update(self, data):
        """ update a Options """

        self.name = data.get('name')
        self.price = data.get('price')
        self.user_id = data.get('user_id')
        self.description = data.get('description')
        self.materials_id = data.get('materials_id')
        self.artist_tagged = data.get('artist_tagged')
        self.special_dates = data.get('special_dates')
        self.services_id_list = data.get('services_id_list')
        self.modified_at = datetime.datetime.utcnow()
        db.session.commit()
        update_doc(self, OptionsSchema(), index="options", doc_type="option")

    def delete(self):
        """ delete a user Options """

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

    @staticmethod
    def get_by_options_id(options_id=None):
        """ get one artist service """

        return Options.query.filter_by(service_id=options_id).first()
Exemplo n.º 6
0
class Services(db.Model):
    """ Services Model """

    # table name
    __tablename__ = 'services'

    id = db.Column(db.BIGINT, primary_key=True)
    special_dates = db.Column(JSON, default={})
    hidden = db.Column(db.Boolean, default=False)
    description = db.Column(db.Text(), nullable=True)
    title = db.Column(db.String(200), nullable=False)
    country = db.Column(db.String(200), nullable=False)
    events = db.Column(db.ARRAY(db.String), default=[])
    galleries = db.Column(db.ARRAY(db.String), default=[])
    thematics = db.Column(db.ARRAY(db.String), default=[])
    others_city = db.Column(db.ARRAY(db.String), default=[])
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    reference_city = db.Column(db.String(200), nullable=False)
    price = db.Column(db.Float(), nullable=False, default=1.00)
    travel_expenses = db.Column(JSON, nullable=False, default={})
    number_of_artists = db.Column(db.Integer(), nullable=False, default=1)
    unit_duration_of_the_service = db.Column(db.String(10), nullable=False)
    preparation_time = db.Column(db.Float(), nullable=False, default=1.00)
    unit_of_the_preparation_time = db.Column(db.String(10), nullable=False)
    refund_policy = db.Column(db.String(45),
                              nullable=False,
                              default='flexible')
    duration_of_the_service = db.Column(db.Float(),
                                        nullable=False,
                                        default=1.00)
    materials_id = db.Column(db.Integer,
                             db.ForeignKey('materials.id'),
                             nullable=False)
    created_at = db.Column(db.DateTime)
    modified_at = db.Column(db.DateTime)
    material = db.relationship("Materials",
                               cascade="all, delete, save-update",
                               backref=db.backref("materials_of_services",
                                                  uselist=False))

    # class constructor
    def __init__(self, data):
        """ Class constructor """

        self.title = data.get('title')
        self.price = data.get('price')
        self.country = data.get('country')
        self.events = data.get('events')
        self.user_id = data.get('user_id')
        self.hidden = data.get('hidden', False)
        self.galleries = data.get('galleries')
        self.thematics = data.get('thematics')
        self.description = data.get('description')
        self.others_city = data.get('others_city')
        self.special_dates = data.get('special_dates')
        self.materials_id = data.get('materials_id')
        self.reference_city = data.get('reference_city')
        self.travel_expenses = data.get('travel_expenses')
        self.preparation_time = data.get('preparation_time')
        self.number_of_artists = data.get('number_of_artists')
        self.refund_policy = data.get('refund_policy', 'flexible')
        self.duration_of_the_service = data.get('duration_of_the_service')
        self.unit_duration_of_the_service = data.get(
            'unit_duration_of_the_service')
        self.unit_of_the_preparation_time = data.get(
            'unit_of_the_preparation_time')
        self.created_at = datetime.datetime.utcnow()
        self.modified_at = datetime.datetime.utcnow()

    def save(self):
        """ save a Services """

        db.session.add(self)
        db.session.commit()
        add_new_doc(self,
                    ServiceSchema(),
                    index="services",
                    doc_type="prestations")

    def update(self, data):
        """ update a Services """

        self.title = data.get('title')
        self.hidden = data.get('hidden')
        self.country = data.get('country')
        self.description = data.get('description')
        self.events = data.get('events')
        self.galleries = data.get('galleries')
        self.thematics = data.get('thematics')
        self.others_city = data.get('others_city')
        self.user_id = data.get('user_id')
        self.reference_city = data.get('reference_city')
        self.special_dates = data.get('special_dates')
        self.price = data.get('price')
        self.refund_policy = data.get('refund_policy')
        self.materials_id = data.get('materials_id')
        self.travel_expenses = data.get('travel_expenses')
        self.number_of_artists = data.get('number_of_artists')
        self.duration_of_the_service = data.get('duration_of_the_service')
        self.unit_duration_of_the_service = data.get(
            'unit_duration_of_the_service')
        self.preparation_time = data.get('preparation_time')
        self.unit_of_the_preparation_time = data.get(
            'unit_of_the_preparation_time')
        self.modified_at = datetime.datetime.utcnow()
        db.session.commit()
        update_doc(self,
                   ServiceSchema(),
                   index="services",
                   doc_type="prestations")

    def delete(self):
        """ delete a user Services """

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

    @staticmethod
    def get_by_service_id(service_id=None):
        """ get one artist service """

        return Services.query.filter_by(id=service_id).first()