raphael
f156d38739
- moves app into package - adds sql alchemy equipment - moves templates into server package - add app.db sqlite file
62 lines
1.9 KiB
Python
62 lines
1.9 KiB
Python
from flask_login import UserMixin
|
|
from server import login_manager, db
|
|
|
|
@login_manager.user_loader
|
|
def load_user(id):
|
|
return User.query.get(id)
|
|
|
|
class User(UserMixin, db.Model):
|
|
id = db.Column(db.String(21), primary_key=True)
|
|
username = db.Column(db.String(64), index=True, unique=True)
|
|
email = db.Column(db.String(120), index=True, unique=True)
|
|
profile_pic = db.Column(db.String(256))
|
|
password_hash = db.Column(db.String(128))
|
|
|
|
def __repr__(self):
|
|
return '<User {}>'.format(self.username)
|
|
|
|
class Calendar(db.Model):
|
|
usr_id = db.Column(db.String(21), index=True)
|
|
calendar_id = db.Column(db.String(256), primary_key=True)
|
|
name = db.Column(db.String(256), index=True)
|
|
toggle = db.Column(db.String(8))
|
|
color = db.Column(db.String(16))
|
|
|
|
def getCalendars(self, user_id):
|
|
calendars = self.query.filter(Calendar.usr_id==user_id)
|
|
|
|
return calendars
|
|
|
|
def getCalendar(self, user_id, calendar_id):
|
|
calendars = self.query.filter(self.usr_id==user_id, self.calendar_id==calendar_id)
|
|
|
|
calendar = None
|
|
for c in calendars:
|
|
calendar = c
|
|
|
|
if not calendar:
|
|
return None
|
|
|
|
return calendar
|
|
|
|
@staticmethod
|
|
def updateCalendar(user_id, calendar_name, toggle=None, color=None):
|
|
|
|
calendar = Calendar.query.filter(Calendar.usr_id==user_id, Calendar.name==calendar_name).first()
|
|
|
|
|
|
print("updating")
|
|
if(toggle != None):
|
|
print(toggle)
|
|
calendar.toggle = toggle
|
|
db.session.commit()
|
|
|
|
if(color != None):
|
|
calendar.color = color
|
|
db.session.commit()
|
|
|
|
def create(self, user_id, calendar_id, name, color, toggle = 'True'):
|
|
newcal = Calendar(usr_id=user_id, calendar_id=calendar_id, name=name, toggle=toggle, color=color)
|
|
|
|
db.session.add(newcal)
|
|
db.session.commit() |