class Seekerdetails(db.Model): __tablename__ = "seekerdetails" id = db.Column(db.Integer, primary_key=True) contactnumber = db.Column(db.Integer) experience = db.Column(db.Integer) currentpack = db.Column(db.Integer) expectedpack = db.Column(db.Integer) qualification = db.Column(db.Integer, db.ForeignKey('qualifications.id')) subject = db.Column(db.Integer, db.ForeignKey('subjects.id')) experiences = db.Column(db.String(2000)) address = db.Column(db.String(2000)) district = db.Column(db.Integer, db.ForeignKey('districts.id')) state = db.Column(db.Integer, db.ForeignKey('states.id')) medium = db.Column(db.Integer) user = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) def serialize(self): json_user = { "id": self.id, "Contact Number": self.contactnumber, #"registered_on": str(self.registered_on), "Experience": self.experience, "Current Package": self.currentpack, "Qualification": self.qualification, # "Experience History": self.experiences, #"Address": self.address, "District": self.district, "State": self.state, "Medium": self.medium, } return json_user
class Message(db.Model): id = db.Column(db.Integer, primary_key=True) sender_id = db.Column(db.Integer, db.ForeignKey('user.id')) recipient_id = db.Column(db.Integer, db.ForeignKey('user.id')) body = db.Column(db.String(240)) timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow) def __repr__(self): return '<Message {}>'.format(self.body)
class Track_Medicines(db.Model): id = db.Column(db.Integer, primary_key=True) patient_id = db.Column(db.Integer, db.ForeignKey('patient.patient_id')) med_id = db.Column(db.Integer, db.ForeignKey('medicine__master.med_id')) quantity_issued = db.Column(db.Integer) # patient_1 = Patient(ssn_id=12, name='asd', age=32, admission_date=12, bed_type='asd', address='asd', city='asd', state='asd', status='asd') # med_1 = Medicine_Master(med_name='sad', quantity=12, rate=21) # track_1 = Track_Medicines(patient_id=patient_1.patient_id, med_id=med_1.med_id, quantity_issued=213) # Patient.query.get(1).med_list[0].medicine.med_name
class Todo(db.Model): id = db.Column(db.Integer(), primary_key=True) task = db.Column(db.Text(), nullable=False) tasker_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __repr__(self): return [self.task, self.tasker_id]
class Notification(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(128), index=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) timestamp = db.Column(db.Float, index=True, default=time) payload_json = db.Column(db.Text) def get_data(self): return json.loads(str(self.payload_json))
class Resume(db.Model): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) category = db.Column(db.String(40), index=True) year = db.Column(db.String(30), index=True) title = db.Column(db.String(300), index=True) sub_title = db.Column(db.String(300), index=True) body = db.Column(db.String(800)) timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow) def __repr__(self): return "{0.user_id} - {0.body}".format(self)
class Options(db.Model): __tablename__ = "options" id = db.Column(db.Integer, primary_key=True) option = db.Column(db.String(200), nullable=False) question_id = db.Column(db.Integer, db.ForeignKey('questions.id'), nullable=False) is_correct_option = db.Column(db.Integer, nullable=False, default=0) insert_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow()) update_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow()) def __rept__(self): return "'id': {0}, 'option': {1}, 'question_id': {2}".format( self.id, self.option, self.question_id) @classmethod def get_all_options(classname): return [option.serialize() for option in classname.query.all()] @classmethod def get_options_from_qid(classname, question_id): options = classname.query.filter_by(question_id=question_id) return options @classmethod def submit_options_from_json(classname, json_options, question_id): for json_option in json_options: option = Options( option=json_option['option'], question_id=question_id, is_correct_option=json_option['is_correct_option']) db.session.add(option) db.session.commit() @classmethod def delete_options_from_qid(classname, question_id): options = classname.get_options_from_qid(question_id) if options is None: return None for option in options: db.session.delete(option) db.session.commit() return options def serialize(self): json_option = { 'id': self.id, 'option': self.option, 'question_id': self.question_id, 'is_correct_option': self.is_correct_option, 'insert_date': str(self.insert_date), 'update_date': str(self.update_date) } return json_option #todo:json encoding needed @staticmethod def serialize_all(options): return [option.serialize() for option in options] @staticmethod def validate_option(option): if ('id' in option and 'option' in option and 'question_id' in option and 'is_correct_option' in option): return True else: return False
class Jobs(db.Model): __tablename__ = "jobs" id = db.Column(db.Integer, primary_key=True) subject = db.Column(db.Integer, db.ForeignKey('subjects.id')) jobdetails = db.Column(db.String(2000), default="") minexperience = db.Column(db.Integer, default=0) maxexperience = db.Column(db.Integer, default=0) telephone = db.Column(db.Integer, default=0) institution = db.Column(db.String(80), default="") description = db.Column(db.String(80), default="") recruiter = db.Column(db.Integer, db.ForeignKey('users.id')) qualification = db.Column(db.Integer, db.ForeignKey('qualifications.id')) state = db.Column(db.Integer, db.ForeignKey('states.id')) district = db.Column(db.Integer, db.ForeignKey('districts.id')) registered_on = db.Column(db.DateTime, nullable=False, default=datetime.now()) closed_on = db.Column(db.DateTime) isactive = db.Column(db.Boolean, nullable=False, default=True) @classmethod def add_job(classname, _user): pass @classmethod def submit_job_from_json(classname, json_job): job = classname() if not json_job.get("subject", None) is None: job.subject = json_job.get("subject", None) if not json_job.get("jobdetails", None) is None: job.jobdetails = json_job.get("jobdetails", None) if not json_job.get("minexperience", None) is None: job.minexperience = json_job.get("minexperience", None) if not json_job.get("maxexperience", None) is None: job.maxexperience = json_job.get("maxexperience", None) if not json_job.get("telephone", None) is None: job.telephone = json_job.get("telephone", None) if not json_job.get("institution", None) is None: job.institution = json_job.get("institution", None) if not json_job.get("submitter", None) is None: user = users.Users.get_user_by_username(json_job.get("submitter", None)) if not user is None: print(user) job.recruiter = 1 if not json_job.get("district", None) is None: job.district = json_job.get("district", None) if not json_job.get("state", None) is None: job.state = json_job.get("state", None) if not json_job.get("qualification", None) is None: job.qualification = json_job.get("qualification", None) if not json_job.get("description", None) is None: job.description = json_job.get("description", None) db.session.add(job) db.session.commit() return job @classmethod def get_jobs_by_filter(classname, filter): query = "select * from jobs where " for key, value in filter.items(): query = "{} {} = {}".format(query, key, value) print(query) result = db.engine.execute(query) list_result =[] for job in result: job_object = dict(zip(result.keys(), job)) list_result.append(Jobs.serialize_dict(job_object)) return list_result def serialize(self): json_job = { "Id": self.id, "Title": self.description, #"Recruiter": users.Users.get_user_by(self.recruiter).email, "Minimum Qualification Needed": qualifications.Qualifications.get_qualification_from(self.qualification).qualification, "District": districts.Districts.get_district_from(self.district).district, "State": states.States.get_state_from(self.state).state, "School": self.institution, "Minimum years of Experience": self.minexperience, "Job Description": self.jobdetails, "Opened on":self.registered_on.strftime("%d-%B") } return json_job @classmethod def serialize_dict(classname, job_dict): json_job = { "Id": job_dict['id'], "Title": job_dict['description'], #"Recruiter": users.Users.get_user_by(self.recruiter).email, "Minimum Qualification Needed": qualifications.Qualifications.get_qualification_from(job_dict['qualification']).qualification, "District": districts.Districts.get_district_from(job_dict['district']).district, "State": states.States.get_state_from(job_dict['state']).state, "School": job_dict['institution'], "Minimum years of Experience": job_dict['minexperience'], "Job Description": job_dict['jobdetails'], "Opened on":job_dict['registered_on'] } return json_job