moves models to database folder
This commit is contained in:
@ -23,5 +23,5 @@ migrate = Migrate(app, db)
|
||||
# https://flask-login.readthedocs.io/en/latest
|
||||
login_manager = LoginManager(app)
|
||||
|
||||
|
||||
from server import routes, models
|
||||
from server import routes
|
||||
from database import models
|
||||
|
@ -1,7 +1,7 @@
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField, PasswordField, BooleanField, SubmitField
|
||||
from wtforms.validators import DataRequired, ValidationError, Email, EqualTo
|
||||
from server.models import User
|
||||
from database.models import User
|
||||
import email_validator
|
||||
|
||||
class LoginForm(FlaskForm):
|
||||
|
@ -23,7 +23,7 @@ from flask_login import (
|
||||
)
|
||||
import requests
|
||||
|
||||
from server.models import Calendar as dbCalendar
|
||||
from database.models import Calendar as dbCalendar
|
||||
|
||||
# Configuration
|
||||
CLIENT_SECRETS_FILE = "certificate/client_secret.json"
|
||||
|
@ -1,94 +0,0 @@
|
||||
import json
|
||||
from flask_login import UserMixin
|
||||
from server import login_manager, db
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
|
||||
@login_manager.user_loader
|
||||
def load_user(id):
|
||||
return User.query.get(id)
|
||||
|
||||
class User(UserMixin, db.Model):
|
||||
id = db.Column(db.String(64), 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))
|
||||
calendarJson = db.Column(db.String)
|
||||
google_credentials = db.Column(db.String)
|
||||
|
||||
def __repr__(self):
|
||||
return '<User {}>'.format(self.username)
|
||||
|
||||
def setPassword(self, password):
|
||||
self.password_hash = generate_password_hash(password)
|
||||
|
||||
def checkPassword(self, password):
|
||||
return check_password_hash(self.password_hash, password)
|
||||
|
||||
def setJson(self, jsonObject):
|
||||
self.calendarJson = json.dumps(jsonObject)
|
||||
db.session.commit()
|
||||
|
||||
def getJson(self):
|
||||
return json.loads(self.calendarJson)
|
||||
|
||||
def setGoogleCredentials(self, credentials):
|
||||
self.google_credentials = json.dumps(credentials)
|
||||
db.session.commit()
|
||||
|
||||
def getGoogleCredentials(self):
|
||||
|
||||
if self.google_credentials is None:
|
||||
print("no credentials", flush=True)
|
||||
return None
|
||||
return json.loads(self.google_credentials)
|
||||
|
||||
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_id, toggle=None, color=None):
|
||||
|
||||
calendar = Calendar.query.filter(Calendar.usr_id==user_id, Calendar.calendar_id==calendar_id).first()
|
||||
|
||||
|
||||
print("updating", flush=True)
|
||||
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()
|
||||
|
||||
class Device(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
deviceId = db.Column(db.String(128), index=True)
|
@ -21,7 +21,7 @@ import server.googleHandler as google
|
||||
from backend.Routine import Routine
|
||||
from server import login_manager, app, db
|
||||
from server.forms import LoginForm, RegistrationForm, DeviceForm
|
||||
from server.models import User, Calendar, Device
|
||||
from database.models import User, Calendar, Device
|
||||
|
||||
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
|
||||
|
||||
|
Reference in New Issue
Block a user