class Materials(db.Model): """ Materials Model """ __tablename__ = 'materials' id = db.Column(db.BIGINT, primary_key=True) list_of_materials = db.Column(db.ARRAY(db.String), default=[]) technical_sheet = db.Column(db.String(255), nullable=True) created_at = db.Column(db.DateTime) modified_at = db.Column(db.DateTime) # class constructor def __init__(self, data): """ Class constructor """ self.technical_sheet = data.get('technical_sheet') self.list_of_materials = data.get('list_of_materials') self.created_at = datetime.datetime.utcnow() self.modified_at = datetime.datetime.utcnow() def save(self): """ save a Materials """ db.session.add(self) db.session.commit() add_new_doc(self, MaterialsSchema(), index="materials", doc_type="material") def update(self, data): """ update a Materials """ self.technical_sheet = data.get('technical_sheet') self.list_of_materials = data.get('list_of_materials') self.modified_at = datetime.datetime.utcnow() db.session.commit() update_doc(self, MaterialsSchema(), index="materials", doc_type="material") def delete(self): """ delete a user Materials """ db.session.delete(self) db.session.commit() @staticmethod def get_by_materials_id(materials_id): """ get one artist service """ return Materials.query.filter_by(id=materials_id).first()
class Prestige(db.Model): """ Prestige Model """ # table name __tablename__ = 'prestige_moneys' id = db.Column(db.Integer, primary_key=True) key_share = db.Column(db.String(255)) prestige = db.Column(db.String(125)) sender_id = db.Column(db.Integer, db.ForeignKey('users.id')) recipient_id = db.Column(db.Integer, db.ForeignKey('users.id')) beat_id = db.Column(db.Integer, db.ForeignKey('medias.id'), nullable=True) service_id = db.Column(db.Integer, db.ForeignKey('services.id'), nullable=True) created_at = db.Column(db.DateTime) modified_at = db.Column(db.DateTime) # class constructor def __init__(self, data): """ Class constructor """ self.key_share = data.get('key_share') self.prestige = data.get('prestige') self.sender_id = data.get('sender_id') self.recipient_id = data.get('recipient_id') self.beat_id = data.get('beat_id') self.service_id = data.get('service_id') self.created_at = datetime.datetime.utcnow() self.modified_at = datetime.datetime.utcnow() def save(self): """ sav a prestige """ db.session.add(self) db.session.commit() def delete(self): """ delete an prestige """ db.session.delete(self) db.session.commit() @staticmethod def get_all_transaction(): """ check all prestige """ return Prestige.query.all()
class KeyResetPassword(db.Model): """ table for logout """ __tablename__ = 'key_reset_passwords' id = db.Column(db.Integer, primary_key=True) keys = db.Column(db.Integer, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=True, unique=True) password_reset = db.Column(db.Integer, nullable=False) created_at = db.Column(db.DateTime) modified_at = db.Column(db.DateTime) def __init__(self, data): self.keys = data["keys"] self.user_id = data["user_id"] try: self.password_reset = data["password_reset"] except KeyError: self.password_reset = 0 self.created_at = datetime.datetime.utcnow() self.modified_at = datetime.datetime.utcnow() def save(self): db.session.add(self) db.session.commit() def update(self, data): self.keys = data["keys"] self.user_id = data["user_id"] try: self.password_reset = data["password_reset"] except KeyError: self.password_reset = 0 self.modified_at = datetime.datetime.utcnow() db.session.commit() def delete(self): db.session.delete(self) db.session.commit() @staticmethod def get_by_user_id(user_id): return KeyResetPassword.query.filter_by(user_id=user_id).first()
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()
class Carts(db.Model): """ Cart Model """ # table name __tablename__ = 'carts' id = db.Column(db.BIGINT, primary_key=True) beat_id = db.Column(db.Integer) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) price = db.Column(db.Float()) license = db.Column(db.String(50)) created_at = db.Column(db.DateTime) modified_at = db.Column(db.DateTime) # class constructor def __init__(self, data): """ Class constructor """ self.beat_id = data.get("beat_id") self.user_id = data.get("user_id") self.price = data.get("price") self.license = data.get("license") self.created_at = datetime.datetime.now() self.modified_at = datetime.datetime.now() def save(self): """ save an article """ db.session.add(self) db.session.commit() def delete(self): """ delete an article """ db.session.delete(self) db.session.commit()
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()
class BankingDetails(db.Model): """ Materials Model """ __tablename__ = 'banking_details' id = db.Column(db.BIGINT, primary_key=True) name = db.Column(db.String(200), nullable=False) lastname = db.Column(db.String(200)) country = db.Column(db.String(200), nullable=False) phone = db.Column(db.String(125), nullable=True) iban = db.Column(db.String(125), nullable=False) swift = db.Column(db.String(125), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) email = db.Column(db.String(125), nullable=False) created_at = db.Column(db.DateTime) modified_at = db.Column(db.DateTime) # class constructor def __init__(self, data): """ Class constructor """ self.name = data.get('name') self.country = data.get('country') self.phone = data.get('phone') self.lastname = data.get('lastname') self.iban = data.get('iban') self.swift = data.get('swift') self.email = data.get('email') self.user_id = data.get('user_id') self.created_at = datetime.datetime.utcnow() self.modified_at = datetime.datetime.utcnow() def save(self): """ save a Materials """ db.session.add(self) db.session.commit() def update(self, data): """ update a Materials """ self.name = data.get('name') self.country = data.get('country') self.phone = data.get('phone') self.lastname = data.get('lastname') self.iban = data.get('iban') self.swift = data.get('swift') self.email = data.get('email') self.user_id = data.get('user_id') self.modified_at = datetime.datetime.utcnow() db.session.commit() def delete(self): """ delete a user Materials """ db.session.delete(self) db.session.commit()
class SupportMessages(db.Model): """ of Support messages """ # table name __tablename__ = 'messages' id = db.Column(db.BIGINT, primary_key=True) title = db.Column(db.String(125), nullable=False) user_email = db.Column(db.String(200), nullable=False) message = db.Column(db.Text(), nullable=False) resolved = db.Column(db.Boolean, default=False) created_at = db.Column(db.DateTime) modified_at = db.Column(db.DateTime) # class constructor def __init__(self, data): """ Class constructor """ self.title = data.get('title') self.user_email = data.get('user_email') self.message = data.get('gender') self.created_at = datetime.datetime.utcnow() self.modified_at = datetime.datetime.utcnow() def save(self): """ save a message """ db.session.add(self) db.session.commit() def update(self, data): """ update a message """ self.title = data.get('title') self.user_email = data.get('user_email') self.message = data.get('gender') self.modified_at = datetime.datetime.utcnow() db.session.commit() def delete(self): """ delete a message """ db.session.delete(self) db.session.commit() @staticmethod def get_message_by_id(support_message_id): """ get one support message """ return SupportMessages.query.filter_by(id=support_message_id).first() @staticmethod def get_support_message_resolved(): """ get all support message resolved """ return SupportMessages.query.filter_by(resolved=True).all() @staticmethod def get_support_message_not_resolved(): """ get all support message resolved """ return SupportMessages.query.filter_by(resolved=False).all()
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
class Payment(db.Model): """ Payment Model """ # table name __tablename__ = 'payment' id = db.Column(db.Integer, primary_key=True) artist_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) reference = db.Column(db.String(100), nullable=False) amount = db.Column(db.Float(), nullable=False) type = db.Column(db.String(150), nullable=False) licenses_name = db.Column(db.String(50), nullable=True) created_at = db.Column(db.DateTime) modified_at = db.Column(db.DateTime) # class constructor def __init__(self, data): """ Class constructor """ self.artist_id = data.get('artist_id') self.amount = data.get('amount') self.type = data.get('type') self.licenses_name = data.get('licenses_name') self.reference = data.get('reference') 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.artist_id = data.get('artist_id') self.amount = data.get('amount') self.type = data.get('type') self.licenses_name = data.get('licenses_name') self.reference = data.get('reference') 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_by_id(payment_id): """ get a payment by id """ return Payment.query.filter_by(id=payment_id).first() @staticmethod def get_payment_by_reference(reference): """ get a payment by reference """ return Payment.query.filter_by(reference=reference).first()
class Profiles(db.Model): """ Profile Model """ # table name __tablename__ = 'profiles' id = db.Column(db.BIGINT, primary_key=True) name = db.Column(db.String(125)) artist_name = db.Column(db.String(125), nullable=True) email = db.Column(db.String(125), unique=True, nullable=True) social_id = db.Column(db.String(128), unique=True, nullable=True, default=None) photo = db.Column(db.String(255), nullable=True) cover_photo = db.Column(db.String(255), nullable=True) gender = db.Column(db.String(155), nullable=True) birth = db.Column(db.Date, nullable=True) address = db.Column(db.String(155), nullable=True) phone = db.Column(db.String(125), nullable=True) country = db.Column(db.String(255), nullable=True) region = db.Column(db.String(255), nullable=True) city = db.Column(db.String(255), nullable=True) attached = db.Column(db.Integer, default=0) description = db.Column(db.String(255), nullable=True) age = db.Column(db.Integer, nullable=True) created_at = db.Column(db.DateTime) modified_at = db.Column(db.DateTime) # class constructor def __init__(self, data): """ Class constructor """ self.name = data.get('name') self.email = data.get('email') self.photo = data.get('photo') self.cover_photo = data.get('cover_photo') self.gender = data.get('gender') self.birth = data.get('birth') self.address = data.get('address') self.phone = data.get('phone') self.attached = data.get('attached') self.social_id = data.get('social_id') self.country = data.get('country') self.region = data.get('region') self.city = data.get('city') self.age = data.get('age') self.description = data.get('description') self.artist_name = data.get('artist_name') if data.get('artist_name') else None self.created_at = datetime.datetime.utcnow() self.modified_at = datetime.datetime.utcnow() def save(self): """ save a profile """ db.session.add(self) db.session.commit() def update(self, data): """ update a profile """ self.name = data.get('name') self.email = data.get('email') self.photo = data.get('photo') self.cover_photo = data.get('cover_photo') self.gender = data.get('gender') self.birth = data.get('birth') self.address = data.get('address') self.phone = data.get('phone') self.country = data.get('country') self.social_id = data.get('social_id') self.region = data.get('region') self.city = data.get('city') self.attached = data.get('attached') self.artist_name = data.get('artist_name') self.description = data.get('description') self.age = data.get('age') self.modified_at = datetime.datetime.utcnow() db.session.commit() def delete(self): """ delete a user profile """ db.session.delete(self) db.session.commit() @staticmethod def get_profile(email=None, social_id=None, profile_id=None): """ get a user profile """ if email: return Profiles.query.filter_by(email=email).first() if profile_id: return Profiles.query.filter_by(id=profile_id).first() if social_id: return Profiles.query.filter_by(social_id=social_id).first()
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()
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()
class ConditionGlobals(db.Model): """ Globals condition for all type of artist """ # table name __tablename__ = 'condition_globals' id = db.Column(db.Integer, primary_key=True) travel_expenses = db.Column(JSON, default={}) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), unique=True) refund_policy = db.Column(db.String(45), default='flexible') monday = db.Column(db.Boolean, default=True) tuesday = db.Column(db.Boolean, default=True) wednesday = db.Column(db.Boolean, default=True) thursday = db.Column(db.Boolean, default=True) friday = db.Column(db.Boolean, default=True) saturday = db.Column(db.Boolean, default=True) sunday = db.Column(db.Boolean, default=False) created_at = db.Column(db.DateTime) modified_at = db.Column(db.DateTime) # class constructor def __init__(self, data): """ Class constructor """ self.user_id = data.get('user_id') self.monday = data.get('monday') self.tuesday = data.get('tuesday') self.wednesday = data.get('wednesday') self.thursday = data.get('thursday') self.friday = data.get('friday') self.saturday = data.get('saturday') self.sunday = data.get('sunday') self.refund_policy = data.get('refund_policy') self.travel_expenses = data.get('travel_expenses', { "from": 0, "to": 0 }) self.created_at = datetime.datetime.utcnow() self.modified_at = datetime.datetime.utcnow() def save(self): """ save a playlist """ db.session.add(self) db.session.commit() def update(self, data): """ Update a user globals condition """ self.monday = data.get('monday') self.tuesday = data.get('tuesday') self.wednesday = data.get('wednesday') self.thursday = data.get('thursday') self.friday = data.get('friday') self.saturday = data.get('saturday') self.sunday = data.get('sunday') self.refund_policy = data.get('refund_policy') self.travel_expenses = data.get('travel_expenses') self.modified_at = datetime.datetime.utcnow() db.session.commit() def delete(self): """ delete a playlist """ db.session.delete(self) db.session.commit() @staticmethod def get_condition_globals_by_user_id(user_id): """ check globals id by id """ return ConditionGlobals.query.filter_by(user_id=user_id).first()
class Partner(db.Model): """ table for logout """ __tablename__ = 'partners' id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('users.id')) name = db.Column(db.String(155), nullable=False) logo = db.Column(db.String(255), nullable=False) partnership_desc = db.Column(db.String(255), nullable=False) contract_type = db.Column(db.Integer, default=0) active = db.Column(db.Boolean, default=True) created_at = db.Column(db.DateTime) modified_at = db.Column(db.DateTime) def __init__(self, data): self.name = data.get("name") self.logo = data.get("logo") self.user_id = data.get("user_id") self.contract_type = data.get("contract_type") self.partnership_desc = data.get("partnership_desc") self.created_at = datetime.datetime.utcnow() self.modified_at = datetime.datetime.utcnow() def save(self): """ save a new partner """ db.session.add(self) db.session.commit() def update(self, data): """ update a partner """ self.name = data.get("name") self.logo = data.get("logo") self.active = data.get("active") self.contract_type = data.get("contract_type") self.partnership_desc = data.get("partnership_desc") self.modified_at = datetime.datetime.utcnow() db.session.commit() def delete(self): """ delete a partner """ db.session.delete(self) db.session.commit() @staticmethod def partner_by_id(id_): """ get a partner by id """ return Partner.query.filter_by(id=id_).first() @staticmethod def partner_by_name(name_): """ get a partner by name """ return Partner.query.filter_by(name=name_).first() @staticmethod def all_partners(): """ get all partner with us """ return Partner.query.all()
class ContractBeatMaking(db.Model): """ Contract BeatMaking Model """ # table name __tablename__ = 'contract_beat_making' id = db.Column(db.Integer, primary_key=True) contract_name = db.Column(db.String(255), nullable=False) price = db.Column(db.Float(), default=0) mp3 = db.Column(db.BOOLEAN, default=False) wave = db.Column(db.BOOLEAN, default=False) stems = db.Column(db.BOOLEAN, default=False) enabled = db.Column(db.BOOLEAN, default=True) number_of_distribution_copies = db.Column(db.Integer, default=0) number_audio_stream = db.Column(db.Integer, default=0) number_music_video = db.Column(db.Integer, default=0) number_radio_station = db.Column(db.Integer, default=0) unlimited = db.Column(db.BOOLEAN, default=False) user_id = db.Column(db.Integer, db.ForeignKey('users.id')) created_at = db.Column(db.DateTime) modified_at = db.Column(db.DateTime) # class constructor def __init__(self, data): """ Class constructor """ self.user_id = data.get('user_id') self.contract_name = data.get('contract_name') self.price = data.get('price') self.mp3 = data.get('mp3', False) self.wave = data.get('wave', False) self.stems = data.get('stems', False) self.enabled = data.get('enabled') self.number_of_distribution_copies = data.get( 'number_of_distribution_copies') self.number_audio_stream = data.get('number_audio_stream') self.number_music_video = data.get('number_music_video') self.number_radio_station = data.get('number_radio_station') self.unlimited = data.get('unlimited') self.modified_at = datetime.datetime.utcnow() self.created_at = datetime.datetime.utcnow() def save(self): """save a new contract """ db.session.add(self) db.session.commit() def update(self, data): """ update one media """ self.price = data.get('price') self.enabled = data.get('enabled') self.number_of_distribution_copies = data.get( 'number_of_distribution_copies') self.number_audio_stream = data.get('number_audio_stream') self.number_music_video = data.get('number_music_video') self.number_radio_station = data.get('number_radio_station') self.unlimited = data.get('unlimited') self.modified_at = datetime.datetime.utcnow() db.session.commit() def delete(self): """ delete one media """ db.session.delete(self) db.session.commit() @staticmethod def get_contract_name_by_user_id(contract_name=None, user_id=None): """ get one contract name by user id """ if contract_name and not user_id: return ContractBeatMaking.query.filter_by( contract_name=contract_name).all() if not contract_name and user_id: return ContractBeatMaking.query.filter_by(user_id=user_id).all() return ContractBeatMaking.query.filter_by(contract_name=contract_name, user_id=user_id).first()
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()
class Stars(db.Model): """ Globals condition for all type of artist """ # table name __tablename__ = 'stars' id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), unique=True, nullable=True) service_id = db.Column(db.Integer, db.ForeignKey('services.id'), unique=True, nullable=True) note = db.Column(db.ARRAY(db.Integer), default=[]) users_who_rated = db.Column(JSON, default={}) created_at = db.Column(db.DateTime) modified_at = db.Column(db.DateTime) # class constructor def __init__(self, data): """ Class constructor """ self.note = data.get('note') self.user_id = data.get('user_id') self.service_id = data.get('service_id') self.users_who_rated = data.get('users_who_rated', {}) self.created_at = datetime.datetime.utcnow() self.modified_at = datetime.datetime.utcnow() def save(self): """ save a playlist """ db.session.add(self) db.session.commit() def update(self, data): """ Update a user notes condition """ self.note = data.get('note') self.service_id = data.get('service_id') self.users_who_rated = data.get('users_who_rated') self.modified_at = datetime.datetime.utcnow() db.session.commit() def delete(self): """ delete a playlist """ db.session.delete(self) db.session.commit() @staticmethod def get_stars_by_user_id(user_id): """ check notes user_id """ return Stars.query.filter_by(user_id=user_id).first() @staticmethod def get_stars_by_service_id(service_id): """ check notes by service_id """ return Stars.query.filter_by(service_id=service_id).first()