class WorkModel(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(200)) thumbnail = db.Column(db.String(200)) image = db.Column(db.String(200)) file = db.Column(db.String(200)) description = db.Column(db.Text) copyright = db.Column(db.Integer) status = db.Column(db.Integer) publishDate = db.Column(db.DateTime) price = db.Column(db.Integer) ownerid = db.Column(db.Integer, db.ForeignKey('user_model.id')) orders = db.relationship('OrderModel', backref=db.backref( 'work', lazy='joined'), lazy='dynamic') tags = db.relationship('WorkTagModel', secondary=work_tags, backref=db.backref('works', lazy='dynamic')) pics = db.relationship('WorkPicModel', backref=db.backref( 'work', lazy='joined'), lazy='dynamic') messages = db.relationship('WorkMessageModel', order_by="WorkMessageModel.publishDate", backref=db.backref('work', lazy='joined'), lazy='dynamic') def __init__(self, title=None, thumbnail=None, image=None, file=None, description=None, copyright=None, price=0): self.title = title self.thumbnail = thumbnail self.image = image self.file = file self.description = description self.copyright = copyright self.status = work_status.normal self.publishDate = datetime.datetime.now() self.price = price def __repr__(self): return '<User %r>' % (self.title) def serialize(self): return { 'userid': self.ownerid, 'workid': self.id, 'title': self.title, 'thumbnail': getUploadFileUrl(file_type.workThumbnail, self.ownerid, self.thumbnail), 'image': getUploadFileUrl(file_type.work, self.ownerid, self.image), 'file': getUploadFileUrl(file_type.workFile, self.ownerid, self.file), 'description': self.description, 'copyright': self.copyright, 'status': self.status, 'publishDate': self.publishDate.isoformat(), 'owner': url_for('.user', _external=True, userid=self.ownerid), 'tags': url_for('.workTags', _external=True, workid=self.id), 'price': self.price }
class NoteModel(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(500)) publishDate = db.Column(db.DateTime) status = db.Column(db.Integer) project_id = db.Column(db.Integer, db.ForeignKey('project_model.id')) user_id = db.Column(db.Integer, db.ForeignKey('user_model.id')) messages = db.relationship('NoteMessageModel', order_by="NoteMessageModel.publishDate", backref=db.backref('note', lazy='joined'), lazy='dynamic') def __init__(self, title): self.title = title self.publishDate = datetime.datetime.now() self.status = note_status.normal def __repr__(self): return '<User %r>' % (self.title) def serialize(self): return { 'noteid': self.id, 'userid': self.user_id, 'userName': self.owner.nickname, 'userImage': self.owner.getImage(), 'title': self.title, 'publishDate': self.publishDate.isoformat() }
class User(db.Model): id = db.Column(db.Integer, primary_key=True) admin = db.Column(db.Boolean, default=False) mail = db.Column(db.String(128), unique=True, nullable=False) password = db.Column(db.String(128), nullable=False) created = db.Column(db.DateTime, nullable=False, default=datetime.utcnow()) img = db.relationship('Userimg', secondary='user_imgs', backref=db.backref('users', lazy='dynamic')) def __repr__(self): return f"User('ID: {self.id}', 'Is Admin: {self.admin}', 'Mail: {self.mail}', 'Date Created: {self.created}')"
class Product(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(32, collation='NOCASE')) slug = db.Column(db.String(140, collation='NOCASE'), unique=True) description = db.Column(db.Text) created = db.Column(db.DateTime, default=datetime.utcnow()) price = db.Column(db.Float) img = db.relationship('Productimg', secondary='product_imgs', backref=db.backref('products', lazy='dynamic')) tags = db.relationship('Tag', secondary='product_tags', backref=db.backref('products', lazy='dynamic')) def __init__(self, *args, **kwargs): super(Product, self).__init__(*args, **kwargs) self.generate_slug() def generate_slug(self): if self.name: self.slug = slugify(self.name) def __repr__(self): return f"Product('Name: {self.name}','Date Created: {self.created}','Description: {self.description}')"
class KindModel(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50)) status = db.Column(db.Integer) parent_id = db.Column(db.Integer, db.ForeignKey('kind_model.id')) parent = db.relationship('KindModel', remote_side=[id], backref=db.backref('kids', lazy='dynamic'), lazy='joined') def __init__(self, name): self.name = name self.status = kind_status.normal
class TaskModel(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100)) timespan = db.Column(db.String(200)) requirements = db.Column(db.Text) bonus = db.Column(db.Integer) description = db.Column(db.Text) publishDate = db.Column(db.DateTime) bidderQualifiRequire = db.Column(db.String(100)) bidderLocationRequire = db.Column(db.String(100)) status = db.Column(db.Integer) receipt = db.Column(db.Boolean) receiptDes = db.Column(db.String(500)) winnerid = db.Column(db.Integer, db.ForeignKey('user_model.id')) projectid = db.Column(db.Integer, db.ForeignKey('project_model.id')) kinds = db.relationship('KindModel', secondary=task_kinds, backref=db.backref('tasks', lazy='dynamic')) versions = db.relationship('VersionModel', backref=db.backref('task', lazy='joined'), lazy='dynamic') notes = db.relationship('NoteModel', backref=db.backref('task', lazy='joined'), lazy='dynamic') bidders = db.relationship('BidModel', lazy='dynamic') def __init__(self, name, timespan=None, requirements=None, bonus=0, description=None, bidderQualifiRequire=None, bidderLocationRequire=None, receipt=False, receiptDes=None): self.name = name self.timespan = timespan self.requirements = requirements self.bonus = bonus self.description = description self.publishDate = datetime.datetime.now() self.bidderQualifiRequire = bidderQualifiRequire self.bidderLocationRequire = bidderLocationRequire self.status = task_status.disable self.receipt = receipt self.receiptDes = receiptDes def __repr__(self): return '<User %r>' % (self.name)
class RecommendTypeModel(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(200)) items = db.relationship('RecommendItemModel', order_by="RecommendItemModel.orderid", backref=db.backref('type', lazy='joined'), lazy='dynamic') def __init__(self, name): self.name = name def serialize(self): return { 'id': self.id, 'name': self.name, 'items': url_for('.recommendItem', _external=True, typeid=self.id) }
class ProjectModel(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(500)) status = db.Column(db.Integer) description = db.Column(db.Text) publish_date = db.Column(db.DateTime) ownerid = db.Column(db.Integer, db.ForeignKey('user_model.id')) tasks = db.relationship('TaskModel', backref=db.backref('project', lazy='joined'), lazy='dynamic') def __init__(self, projectName, description=None): self.name = projectName self.status = project_status.disable self.description = description self.publish_date = datetime.datetime.now() def __repr__(self): return '<User %r>' % (self.name) def serialize(self): return { 'ownerid': self.ownerid, 'projectId': self.id, 'projectName': self.name, 'description': self.description, 'publish_date': self.publish_date.isoformat(), 'status': self.status, 'tasks_url': url_for('.getTasksByProjectID', _external=True, projectid=self.id), 'owner': url_for('.userep', _external=True, userid=self.ownerid) }
class CategoryModel(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50)) status = db.Column(db.Integer) parent_id = db.Column(db.Integer, db.ForeignKey('category_model.id')) parent = db.relationship('CategoryModel', remote_side=[id], backref=db.backref('kids', lazy='dynamic'), lazy='joined') def __init__(self, name): self.name = name self.status = category_status.normal def serialize(self): return { 'id': self.id, 'name': self.name, 'parentid': self.parent_id, 'status': self.status }
class ProjectModel(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100)) timespan = db.Column(db.String(200)) requirements = db.Column(db.Text) bonus = db.Column(db.Integer) description = db.Column(db.Text) publishDate = db.Column(db.DateTime) bidderQualifiRequire = db.Column(db.String(100)) bidderLocationRequire = db.Column(db.String(100)) status = db.Column(db.Integer) receipt = db.Column(db.Boolean) receiptDes = db.Column(db.String(500)) ownerid = db.Column(db.Integer, db.ForeignKey('user_model.id')) winnerid = db.Column(db.Integer, db.ForeignKey('user_model.id')) categorys = db.relationship('CategoryModel', secondary=project_categorys, backref=db.backref('projects', lazy='dynamic')) versions = db.relationship('VersionModel', backref=db.backref('project', lazy='joined'), lazy='dynamic') notes = db.relationship('NoteModel', backref=db.backref('project', lazy='joined'), lazy='dynamic') bidders = db.relationship('BidModel', lazy='dynamic') def __init__(self, name, timespan=None, requirements=None, bonus=0, description=None, bidderQualifiRequire=None, bidderLocationRequire=None, receipt=False, receiptDes=None): self.name = name self.timespan = timespan self.requirements = requirements self.bonus = bonus self.description = description self.publishDate = datetime.datetime.now() self.bidderQualifiRequire = bidderQualifiRequire self.bidderLocationRequire = bidderLocationRequire self.status = project_status.disable self.receipt = receipt self.receiptDes = receiptDes def __repr__(self): return '<User %r>' % (self.name) def serialize(self): return { 'id': self.id, 'name': self.name, 'timespan': self.timespan, 'requirements': self.requirements, 'bonus': self.bonus, 'description': self.description, 'publishDate': self.publishDate.isoformat(), 'bidderQualifiRequire': self.bidderQualifiRequire, 'bidderLocationRequire': self.bidderLocationRequire, 'status': self.status, 'receipt': self.receipt, 'receiptDes': self.receiptDes, 'owner': url_for('.user', _external=True, userid=self.ownerid), 'winner': url_for('.user', _external=True, userid=self.winnerid) if self.winnerid else '', 'versions': url_for('.projectVersions', _external=True, projectid=self.id), 'notes': url_for('.projectNotes', _external=True, projectid=self.id), 'bids': url_for('.projectBids', _external=True, projectid=self.id), 'bidCount': url_for('.projectCount', _external=True, projectid=self.id), 'categorys': url_for('.projectCategorys', _external=True, projectid=self.id) }
class UserModel(db.Model): id = db.Column(db.Integer, primary_key=True) nickname = db.Column(db.String(200)) email = db.Column(db.String(120), unique=True) phone = db.Column(db.String(50)) location = db.Column(db.String(200)) imageLarge = db.Column(db.String(200)) imageMedium = db.Column(db.String(200)) imageSmall = db.Column(db.String(200)) defaultImage = db.Column(db.String(200)) description = db.Column(db.Text) status = db.Column(db.Integer) authenticationType = db.Column(db.Integer) registDate = db.Column(db.DateTime) categorys = db.relationship('CategoryModel', secondary=user_categorys, lazy='dynamic', backref=db.backref('users', lazy='dynamic')) tags = db.relationship('UserTagModel', secondary=user_tags, backref=db.backref('users', lazy='dynamic')) versions = db.relationship('VersionModel', backref=db.backref('owner', lazy='joined'), lazy='dynamic') notes = db.relationship('NoteModel', backref=db.backref('owner', lazy='joined'), lazy='dynamic') notemessages = db.relationship('NoteMessageModel', backref=db.backref('owner', lazy='joined'), lazy='dynamic') works = db.relationship('WorkModel', backref=db.backref('owner', lazy='joined'), lazy='dynamic') workpics = db.relationship('WorkPicModel', backref=db.backref('owner', lazy='joined'), lazy='dynamic') senderMessages = db.relationship('WorkMessageModel', foreign_keys='WorkMessageModel.sender_id', backref=db.backref('sender', lazy='joined'), lazy='dynamic') buyerMessages = db.relationship('WorkMessageModel', foreign_keys='WorkMessageModel.buyer_id', backref=db.backref('buyer', lazy='joined'), lazy='dynamic') sellerMessages = db.relationship('WorkMessageModel', foreign_keys='WorkMessageModel.seller_id', backref=db.backref('seller', lazy='joined'), lazy='dynamic') boughtOrders = db.relationship('OrderModel', primaryjoin='UserModel.id==OrderModel.buyerid', backref=db.backref('buyer', lazy='joined'), lazy='dynamic') soldOrders = db.relationship('OrderModel', primaryjoin='UserModel.id==OrderModel.sellerid', backref=db.backref('seller', lazy='joined'), lazy='dynamic') publishedProjects = db.relationship('ProjectModel', primaryjoin='UserModel.id==ProjectModel.ownerid', backref=db.backref('owner', lazy='joined'), lazy='dynamic') wonProjects = db.relationship('ProjectModel', primaryjoin='UserModel.id==ProjectModel.winnerid', backref=db.backref('winner', lazy='joined'), lazy='dynamic') bidProjects = db.relationship('BidModel', lazy='dynamic') authentications = db.relationship('ApprovalModel', backref=db.backref('owner', lazy='joined'), lazy='dynamic') privateAuthenHistory = db.relationship('PrivateModel', backref=db.backref('owner', lazy='joined'), lazy='dynamic') companyAuthenHistory = db.relationship('CompanyModel', backref=db.backref('owner', lazy='joined'), lazy='dynamic') bankAuthenHistory = db.relationship('BankModel', backref=db.backref('owner', lazy='joined'), lazy='dynamic') manualAuthenHistory = db.relationship('ManualModel', backref=db.backref('owner', lazy='joined'), lazy='dynamic') def __init__(self, email, nickname=None, phone=None, location=None, description=None): if nickname: self.nickname = nickname else: self.nickname = email[:email.find(r'@')] self.defaultImage = '{}.jpg'.format(random.randint(1, app.config['DEFAULT_IMAGE_COUNT'])) self.email = email self.phone = phone self.location = location self.description = description self.registDate = datetime.datetime.now() self.authenticationType = authentication_type.none def __repr__(self): return '<User %r>' % (self.nickname) def serialize(self): return { 'id': self.id, 'nickname': self.nickname, 'email': self.email, 'phone': self.phone, 'location': self.location, 'imageLarge': self.getImage(file_type.profileLarge), 'imageMedium': self.getImage(file_type.profileMedium), 'imageSmall': self.getImage(file_type.profileSmall), 'description': self.description, 'defaultImage': self.defaultImage, 'status': self.status, 'authenticationType': self.authenticationType, 'registDate': self.registDate.isoformat(), 'tags': url_for('.userTags', _external=True, userid=self.id), 'works': url_for('.userWorks', _external=True, userid=self.id, page=1), 'publishedProjects': url_for('.userPublishedProjects', _external=True, userid=self.id, page=1), 'participateProjects': url_for('.userParticipateProjects', _external=True, userid=self.id, page=1), 'privateAuthentication': url_for('.userAuthen', _external=True, userid=self.id, type=1), 'companyAuthentication': url_for('.userAuthen', _external=True, userid=self.id, type=2), 'bankAuthentication': url_for('.userAuthen', _external=True, userid=self.id, type=4), 'manualAuthentication': url_for('.userAuthen', _external=True, userid=self.id, type=8), 'categorys': url_for('.userCategorys', _external=True, userid=self.id) } def getImage(self, imageType=file_type.profileSmall): if self.imageLarge and imageType == file_type.profileLarge: return getUploadFileUrl(imageType, self.id, self.imageLarge) elif self.imageMedium and imageType == file_type.profileMedium: return getUploadFileUrl(imageType, self.id, self.imageMedium) elif self.imageSmall and imageType == file_type.profileSmall: return getUploadFileUrl(imageType, self.id, self.imageSmall) else: return getDefaultImageUrl(self.defaultImage)