class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) image_file = db.Column(db.String(20), nullable=False, default="default.jpg") password = db.Column(db.String(60), nullable=False) posts = db.relationship("Post", backref="author", lazy=True) def get_reset_token(self, expires_sec=1800): s = Serializer(current_app.config["SECRET_KEY"], expires_in=expires_sec) return s.dumps({"user_id": self.id}).decode("utf-8") @staticmethod def verify_reset_token(token): s = Serializer(current_app.config["SECRET_KEY"]) try: user_id = s.loads(token)["user_id"] except: return None return User.query.get(user_id) def __repr__(self): return f"User('{self.username}', '{self.email}', '{self.image_file}')"
class Post(db.Model): __tablename__ = 'post' id = db.Column('id', db.Integer, primary_key=True) verified = db.Column('verified', db.Integer, default=0, nullable=True) title = db.Column('title', db.String(70), nullable=True) category = db.Column('category', db.String(10), nullable=True) description = db.Column('description', db.String(100), nullable=True) files = db.Column('file', db.String) date = db.Column('Date', db.String, nullable=True) user_id = db.Column('user_id', db.Integer, db.ForeignKey('user.id'), nullable=True) start_time = db.Column("Start Time", db.String, nullable=True) end_time = db.Column('End time', db.String, nullable=True) lesson = db.relationship('Lesson', backref=db.backref('lessons')) def __repr__(self, id, verified, title, category, description, files, date, user_id, start_time, end_time): self.id = id self.verified = verified self.title = title self.category = category self.files = files self.description = description self.date = date self.user_id = user_id self.start_time = start_time self.end_time = end_time
class Korisnik(db.Model): __tablename__ = 'Korisnik' id = db.Column(db.Integer, primary_key=True) password = db.Column(db.String(50)) phone = db.Column(db.String(50)) ulogovan = db.Column(db.Boolean()) score = db.Column(db.Float()) security = db.Column(db.Integer) def __init__(self, phone, password, security): self.phone = phone self.password = password self.score = 0 self.ulogovan = False self.security = security def json(self): return { 'id': self.id, 'phone': self.phone, 'password': self.password, 'ulogovan': self.ulogovan, 'score': self.score } @classmethod def vrati_rang_listu(cls): return cls.query.all() @classmethod def vrati_korisnik(cls, id): return cls.query.filter_by(id=id).first() @classmethod def nadji_korisnika(cls, phone, password): ele = cls.query.filter_by(phone=phone).first() if ele == None: return None return ele if ele.password == password else None def odjavi(self): self.ulogovan = False db.session.commit() def prijavi(self): self.ulogovan = True db.session.commit() def update(self, new_score): self.score += new_score db.session.commit() def add(self): db.session.add(self) db.session.commit() def delete(self): db.session.delete(self) db.session.commit()
class sedeModel(db.Model): __tablename__ = 'ci_sedes' #__table_args__ = {'schema':'UBBJ_01'} id_sede = db.Column(db.Integer, primary_key=True) id_localidad = db.Column(db.Integer, nullable=True) colonia = db.Column(db.String(45), nullable=True) calle = db.Column(db.String(255), nullable=True) numero = db.Column(db.String(255), nullable=True) codigo_postal = db.Column(db.Integer, nullable=True) fecha_actualizacion = db.Column(db.DateTime(timezone=True), onupdate=func.now()) fecha_creacion = db.Column(db.DateTime(timezone=True), server_default=func.now()) b_estado = db.Column(db.Boolean, nullable=True) id_status = db.Column(db.Integer, nullable=True) def save_to_db(self): db.session.add(self) db.session.commit() db.session.refresh(self) @classmethod def find_by_id(cls, id): return cls.query.filter_by(id_sede=id).first() @classmethod def supdate_sede(cls, id, id_localidad, colonia, calle, numero, codigo_postal, b_estado): db.session.query(cls).filter(cls.id_sede == id).\ update({cls.id_localidad:id_localidad, cls.colonia:colonia, cls.calle:calle, cls.numero:numero, cls.codigo_postal:codigo_postal, cls.b_estado:b_estado, cls.id_status:5}, synchronize_session=False) db.session.commit() @classmethod def fupdate_sede(cls, id): db.session.query(cls).filter(cls.id_sede == id).\ update({cls.id_status:4}, synchronize_session=False) db.session.commit() @classmethod def tupdate_sede(cls, id): db.session.query(cls).filter(cls.id_sede == id).\ update({cls.id_status:6}, synchronize_session=False) db.session.commit() @classmethod def return_all(cls): def to_json(x): return {'id_sede': x.id_sede, 'b_estado': x.b_estado} return { 'sedes': list(map(lambda x: to_json(x), sedeModel.query.all())) }
class User(db.Model, UserMixin): id = db.Column(db.Integer,primary_key=True) username = db.Column(db.String(20),unique=True,nullable=False) email = db.Column(db.String(120),unique=True,nullable=False) image_file = db.Column(db.String(20),nullable=False,default='default.jpg') password = db.Column(db.String(60),nullable=False) lessons = db.relationship('Lesson',backref='author',lazy=True) def __repr__(self): return f"User('{self.username}','{self.email}','{self.image_file}')"
class User(db.Model): socketID = db.Column(db.String(32), primary_key=True) sessionID = db.Column(db.String(30)) def __init__(self, socketID, sessionID): self.socketID = socketID self.sessionID = sessionID def __repr__(self): return "Socket user %s accessing %s" % (self.socketID, self.sessionID)
class Grievance(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) category_grievance = db.Column(db.String(20), nullable=False) title = db.Column(db.String(20), nullable=False) content = db.Column(db.Text, nullable=False) grievance_image_file = db.Column(db.String(20), nullable='False', default='default.jpg') date_posted = db.Column(db.DateTime, nullable=False, default=datetime.now) used_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __repr__(self): return f"Grievance('{self.category_grievance}', '{self.title}', '{self.content}', '{self.date_posted}')"
class schoolLocation(db.Model): id = db.Column(db.Integer, primary_key=True) ncesid = db.Column(db.String(10)) urbanOrRural = db.Column(db.String(10)) def __init__(self, ncesid, urbanOrRural): self.ncesid = ncesid self.urbanOrRural = urbanOrRural def __repr__(self): return '<schoolLocation {}>'.format(self.ncesid)
class Lesson(db.Model): __tablename__ = 'lesson' id = db.Column('id', db.Integer, primary_key=True) title = db.Column('title', db.String(100), nullable=True) description = db.Column('description', db.String(100), nullable=True) post_id = db.Column('post_id', db.Integer, db.ForeignKey('post.id'), nullable=False) user_id = db.Column('user_id', db.Integer, db.ForeignKey('user.id'), nullable=False) def __repr__(self, id, title, description, post_id): self.id = id self.title = title self.description = description self.post_id = post_id
class Post(db.Model): __tablename__ = 'posts' id = db.Column(db.Integer, nullable=False, primary_key=True, unique=True, autoincrement=True) text_content = db.Column(db.String(1000), nullable=False) data_filename = db.Column(db.String(100), default=None, nullable=True) # tag required to display data_type = db.Column(db.String(100), default=None, nullable=True) visibility = db.Column(db.Boolean, default=True, nullable=False) timestamp = db.Column( db.Integer, nullable=False) # time since Unix Epoch (can be seconds granularity) edit_timestamp = db.Column(db.Integer, default=None) thread_id = db.Column(db.Integer, db.ForeignKey('pleep_threads.id')) thread = db.relationship('Thread', back_populates='posts') # Many (Posts) to One (User) author_id = db.Column(db.Integer, db.ForeignKey('users.id')) author = db.relationship('User', back_populates='myPosts') # many likes to many users likers = db.relationship('User', \ secondary=like_table, \ back_populates='liked') like_count = db.Column(db.Integer, nullable=False, default=0) def jsonify(self): likerIDs = [] for l in self.likers: likerIDs.append(l.id) return {'id': self.id, \ 'thread_id': self.thread_id, \ 'thread_title': self.thread.title, \ 'author_id': self.author_id, \ 'author_name': self.author.name, \ 'author_color': self.author.color, \ 'timestamp': self.timestamp, \ 'edit_timestamp': self.edit_timestamp, \ 'thread_timestamp_close': self.thread.timestamp_close, \ 'text_content': self.text_content, \ 'data_filename': self.data_filename, \ 'data_type' : self.data_type, \ 'visibility': self.visibility, \ 'likes': self.like_count, \ 'likerIDs': likerIDs}
class Thread(db.Model): __tablename__ = 'pleep_threads' id = db.Column(db.Integer, nullable=False, primary_key=True, unique=True, autoincrement=True) title = db.Column(db.String(100), nullable=False) categories = db.Column(db.String(1000)) # csv of 'hashtags' timestamp = db.Column(db.Integer, nullable=False) timestamp_close = db.Column(db.Integer) timestamp_delete = db.Column(db.Integer) closed = db.Column(db.Boolean, nullable=False, default=False) # back ref to display user info easier creator_id = db.Column(db.Integer, db.ForeignKey('users.id')) creator = db.relationship("User", back_populates='myThreads') # One (Thread) to Many (Posts) posts = db.relationship('Post', back_populates='thread') total_likes = db.Column(db.Integer, nullable=False, default=0) # permissions work best with a friends list, otherwise private list # requires knowing all other user's names? # unless it queries for all usernames and filters in realtime for autocomplete read_access = db.Column(db.Boolean, nullable=False, default=True) write_access = db.Column(db.Boolean, nullable=False, default=True) permission_list = db.Column(db.String(1000), nullable=False, default='') # csv? # generate list of post ids def jsonify(self): postIDs = [] for p in self.posts: postIDs.append(p.id) return {'id': self.id, \ 'title': self.title, \ 'categories': self.categories, \ 'timestamp': self.timestamp, \ 'timestamp_close': self.timestamp_close, \ 'timestamp_delete': self.timestamp_delete, \ 'closed': self.closed, \ 'creator': self.creator.name, \ 'creator_id': self.creator_id, \ 'postCount': len(self.posts), \ 'postIDs': postIDs, \ 'total_likes': self.total_likes}
class User(UserMixin, db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), index=True, unique=True) email = db.Column(db.String(120), index=True, unique=True) password_hash = db.Column(db.String(128)) posts = db.relationship('Post', backref='author', lazy='dynamic') about_me = db.Column(db.String(140)) last_seen = db.Column(db.DateTime, default=datetime.utcnow) followed = db.relationship('User', secondary=followers, primaryjoin=(followers.c.follower_id == id), secondaryjoin=(followers.c.followed_id == id), backref=db.backref('followers', lazy='dynamic'), lazy='dynamic') def __repr__(self): return '<User {}>'.format(self.username) def set_password(self, password): self.password_hash = generate_password_hash(password) def check_password(self, password): return check_password_hash(self.password_hash, password) def avatar(self, size): digest = md5(self.email.lower().encode('utf-8')).hexdigest() return 'https://www.gravatar.com/avatar/{}?d=identicon&s={}'.format( digest, size) def follow(self, user): if not self.is_following(user): self.followed.append(user) def unfollow(self, user): # print("user id",user.id) if self.is_following(user): self.followed.remove(user) def is_following(self, user): # print(user.id) return self.followed.filter( followers.c.followed_id == user.id).count() > 0 def followed_posts(self): followed = Post.query.join( followers, (followers.c.followed_id == Post.user_id)).filter( followers.c.follower_id == self.id) own = Post.query.filter_by(user_id=self.id) return followed.union(own).order_by(Post.timestamp.desc())
class DocumentoSedeModel(db.Model): __tablename__ = 'dd_documento_sede' #__table_args__ = {'schema':'UBBJ_01'} id_documento = db.Column(db.Integer, primary_key=True) id_sede = db.Column(db.Integer, nullable=False) documento = db.Column(db.String(45), nullable=False) url = db.Column(db.String(255), nullable=False) b_estado = db.Column(db.Boolean, nullable=False) def save_to_db(self): db.session.add(self) db.session.commit() db.session.refresh(self)
class studentDemographics(db.Model): __tablename__ = 'student_demographics' id = db.Column(db.Integer, primary_key=True) ncesid = db.Column(db.String(10)) totalstudent = db.Column(db.Integer) stype = db.Column(db.String(20)) value = db.Column(db.Integer) def __init__(self, ncesid, totalstudent, stype, value): self.ncesid = ncesid self.totalstudent = totalstudent self.stype = stype self.value = value def __repr__(self): return '<studentDemographics {}>'.format(self.ncesid)
class Pitanje(db.Model): __tablename__='Pitanje' id=db.Column(db.Integer,primary_key=True,autoincrement=True) text=db.Column(db.String(50)) kviz_id = db.Column(db.Integer, db.ForeignKey('Kviz.id'),nullable=False) def __init__(self,text,kviz_id): self.text=text self.kviz_id=kviz_id def json(self): return { 'id' : self.id, 'text' : self.text, 'kviz' : self.kviz_id } @classmethod def vrati_sve_za_kviz(cls,id): return cls.query.filter_by(kviz_id=id) def add(self): db.session.add(self) db.session.commit() def delete(self): db.session.delete(self) db.session.commit()
class acs5PlaceOfBirthByCitizenship(db.Model): id = db.Column(db.Integer, primary_key=True) censustractid = db.Column(db.String(10)) censustract = db.Column(db.String(10)) placeofbirth = db.Column(db.String(10)) count = db.Column(db.Integer) def __init__(self, censustractid, censustract, placeofbirth, count): self.censustractid = censustractid self.censustract = censustract self.placeofbirth = placeofbirth self.count = count def __repr__(self): return '<acs5PlaceOfBirthByCitizenship {}>'.format(self.censustractid)
class Odgovor(db.Model): __tablename__='Odgovor' id=db.Column(db.Integer,primary_key=True,autoincrement=True) text = db.Column(db.String(50)) tacan = db.Column(db.Boolean()) pitanje_id = db.Column(db.Integer, db.ForeignKey('Pitanje.id'),nullable=False) def __init__(self,text,tacan,pitanje_id): self.text=text self.tacan=tacan self.pitanje_id=pitanje_id def json(self): return { 'id' : self.id, 'text' : self.text, 'tacan':self.tacan, 'pitanje': self.pitanje_id } @classmethod def vrati_sve_za_pitanje(cls,id): return cls.query.filter_by(pitanje_id=id) @classmethod def vrati_odgovor(cls,id): return cls.query.filter_by(id=id).first() def add(self): db.session.add(self) db.session.commit() def delete(self): db.session.delete(self) db.session.commit()
class acs5SchoolEnrollment(db.Model): id = db.Column(db.Integer, primary_key=True) censustractid = db.Column(db.String(10)) censustract = db.Column(db.String(10)) schoolenrollment = db.Column(db.String(10)) count = db.Column(db.Integer) def __init__(self, censustractid, censustract, schoolenrollment, count): self.censustractid = censustractid self.censustract = censustract self.schoolenrollment = schoolenrollment self.count = count def __repr__(self): return '<acs5SchoolEnrollment {}>'.format(self.censustractid)
class acs5HouseholdIncomeByRace(db.Model): id = db.Column(db.Integer, primary_key=True) censustractid = db.Column(db.String(10)) censustract = db.Column(db.String(10)) householdincome = db.Column(db.String(10)) count = db.Column(db.Integer) def __init__(self, censustractid, censustract, householdincome, count): self.censustractid = censustractid self.censustract = censustract self.householdincome = householdincome self.count = count def __repr__(self): return '<acs5HouseholdIncomeByRace {}>'.format(self.censustractid)
class acs5PopulationAgeByRace(db.Model): id = db.Column(db.Integer, primary_key=True) censustractid = db.Column(db.String(10)) censustract = db.Column(db.String(10)) agegroup = db.Column(db.String(10)) count = db.Column(db.Integer) def __init__(self, censustractid, censustract, agegroup, count): self.censustractid = censustractid self.censustract = censustract self.agegroup = agegroup self.count = count def __repr__(self): return '<acs5PopulationAgeByRace {}>'.format(self.censustractid)
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) body = db.Column(db.String(140)) timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) def __repr__(self): return '<Post {}>'.format(self.body)
class ImagenesModel(db.Model): __tablename__ = 'im_imagenes' #__table_args__ = {'schema':'UBBJ_01'} id_imagen = db.Column(db.Integer, primary_key=True) imagen = db.Column(db.String(45), nullable=True) url = db.Column(db.String(255), nullable=False) alto = db.Column(db.Integer, nullable=True) ancho = db.Column(db.Integer, nullable=True) fcreacion = db.Column(db.DateTime(timezone=True), server_default=func.now()) b_estado = db.Column(db.Boolean, nullable=False) def save_to_db(self): db.session.add(self) db.session.commit() db.session.refresh(self)
class acs5DetailedEdAttain25yrs(db.Model): id = db.Column(db.Integer, primary_key=True) censustractid = db.Column(db.String(10)) censustract = db.Column(db.String(10)) educational_attainment = db.Column(db.String(10)) count = db.Column(db.Integer) def __init__(self, censustractid, censustract, educational_attainment, count): self.censustractid = censustractid self.censustract = censustract self.educational_attainment = educational_attainment self.count = count def __repr__(self): return '<acs5DetailedEdAttain25yrs {}>'.format(self.censustractid)
class acs5EdAttainByEmployment25yrs(db.Model): id = db.Column(db.Integer, primary_key=True) censustractid = db.Column(db.String(10)) censustract = db.Column(db.String(10)) employment_status_25_64_years = db.Column(db.String(10)) count = db.Column(db.Integer) def __init__(self, censustractid, censustract, employment_status_25_64_years, count): self.censustractid = censustractid self.censustract = censustract self.employment_status_25_64_years = employment_status_25_64_years self.count = count def __repr__(self): return '<acs5EdAttainByEmployment25yrs {}>'.format(self.censustractid)
class acs5DetailedFieldOfBachelorDegree(db.Model): id = db.Column(db.Integer, primary_key=True) censustractid = db.Column(db.String(10)) censustract = db.Column(db.String(10)) field_of_bachelor_degree = db.Column(db.String(10)) count = db.Column(db.Integer) def __init__(self, censustractid, censustract, field_of_bachelor_degree, count): self.censustractid = censustractid self.censustract = censustract self.field_of_bachelor_degree = field_of_bachelor_degree self.count = count def __repr__(self): return '<acs5DetailedFieldOfBachelorDegree {}>'.format( self.censustractid)
class adeEnrollmentSubgroup(db.Model): id = db.Column(db.Integer, primary_key=True) adeid = db.Column(db.String(10)) subgroup = db.Column(db.String(10)) totalStudents = db.Column(db.Integer) Type = db.Column(db.String(10)) Value = db.Column(db.Integer) def __init__(self, adeid, subgroup, totalStudents, Type, Value): self.adeid = adeid self.subgroup = subgroup self.totalStudents = totalStudents self.Type = Type self.Value = Value def __repr__(self): return '<adeEnrollmentSubgroup {}>'.format(self.ncesid)
class Lesson(db.Model): id = db.Column(db.Integer,primary_key=True) title = db.Column(db.String(100),nullable=False) date_posted = db.Column(db.DateTime,nullable=False,default=datetime.utcnow) content = db.Column(db.Text,nullable=False) user_id = db.Column(db.Integer,db.ForeignKey('user.id'),nullable=False) def __repr__(self): return f"User('{self.title}','{self.date_posted}')"
class Upload(db.Model): __tablename__ = 'upload' id = db.Column('id', db.Integer, primary_key=True) title = db.Column('title', db.String(30)) category = db.Column('category', db.String(30)) description = db.Column('description', db.String(600)) price = db.Column('price', db.Integer) upload_ref = db.Column('upload_ref', db.VARCHAR) timestamp = db.Column(db.DateTime, default=datetime.datetime.utcnow) user_id = db.Column('user_id', db.Integer, db.ForeignKey('user.id'), nullable=False) comments = db.relationship('Comment', backref='upload', lazy='dynamic') def __repr__(self, id, title, category, description, price, upload_ref, user_id): self.id = id self.title = title self.category = category self.description = description self.price = price self.upload_ref = upload_ref self.user_id = user_id
class Post(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) title = db.Column(db.String(100), nullable=False) date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) content = db.Column(db.Text, nullable=False) is_answered = db.Column(db.Boolean, default=False, nullable=False) answers = db.relationship('Answer', backref='post', lazy=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __repr__(self): return f"Post('{self.title}', '{self.date_posted}', '{self.author}')"
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) content = db.Column(db.Text, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False) def __repr__(self): return f"Post('{self.title}', '{self.created_at}')"