Skip to content

Commit

Permalink
food model created.
Browse files Browse the repository at this point in the history
requirements.txt updated
.env files are now loading for environment variables
import loop in token.py fixed
  • Loading branch information
nimaafshar79 committed May 7, 2020
1 parent 92de7aa commit d8b8242
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ venv/
felan.txt
.vscode/
__pycache__
.DS_Store
.DS_Store
DATABASE_CREDENTIALS.txt
4 changes: 3 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from calculator import calculator
from extentions import db, jwt, migrate, mail
from users import users
from foods import foods


def create_app(environment='Development'):
Expand All @@ -22,7 +23,8 @@ def create_app(environment='Development'):
app.config.from_object(f'config.{environment}Config')

app.register_blueprint(calculator)
app.register_blueprint(users)
app.register_blueprint(users)
app.register_blueprint(foods)

db.init_app(app)
migrate.init_app(app)
Expand Down
2 changes: 2 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from dotenv import load_dotenv
import os

load_dotenv()

class Config(object):
SECRET_KEY = os.getenv('SECRET_KEY')
Expand Down
7 changes: 7 additions & 0 deletions foods/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from flask import Blueprint


foods = Blueprint('users', __name__, url_prefix='/food/')


from foods import views
22 changes: 22 additions & 0 deletions foods/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import datetime

from sqlalchemy import Column, Integer, REAL, CHAR, VARCHAR, TIMESTAMP

from extentions import db


class Food(db.Model):
__tablename__ = 'foods'

id = Column('id', Integer(), primary_key=True)
calories = Column('calories', Integer())
fat = Column('fat', REAL())
fiber = Column('fiber', REAL())
protein = Column('protein', REAL())
category = Column('category', CHAR(20), nullable=False)
image = Column('image', VARCHAR(400), default=None)
title = Column('title', VARCHAR(200), nullable=False)
createdAt = Column('created_at', TIMESTAMP())

def __repr__(self):
return f"<Food '{self.title}'>"
Empty file added foods/views.py
Empty file.
Binary file modified requirements.txt
Binary file not shown.
1 change: 0 additions & 1 deletion users/email.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from flask_mail import Message

from app import app
from extentions import mail


Expand Down
23 changes: 19 additions & 4 deletions users/models.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import datetime

from sqlalchemy import Boolean, Column, DateTime, Integer, String
from sqlalchemy import Boolean, Column, DateTime, Integer, String, REAL, CHAR, VARCHAR, TIMESTAMP
from werkzeug.security import check_password_hash, generate_password_hash

from extentions import db


class User(db.Model):

__tablename__ = "users"

id = Column(Integer(), primary_key=True)
Expand All @@ -16,12 +15,11 @@ class User(db.Model):
Password = Column(String(), nullable=False)
Admin = Column(Boolean(), nullable=False, default=False)
RegisteredOn = Column(DateTime(), nullable=False)
Confirmed = Column(Boolean(), nullable=False, default=False) # Confirmed Email Address Or Not
Confirmed = Column(Boolean(), nullable=False, default=False) # Confirmed Email Address Or Not
ConfirmedOn = Column(DateTime(), nullable=True)

def __init__(self, full_name, email, password, admin=False,
registerd_on=None, confirmed=False, confirmed_on=None):

self.FullName = full_name
self.Email = email
self.Password = generate_password_hash(password)
Expand All @@ -38,3 +36,20 @@ def check_password(self, password):

def __repr__(self):
return f'<Email {self.Email}>'


class Food(db.Model):
__tablename__ = 'foods'

id = Column('id', Integer(), primary_key=True)
calories = Column('calories', Integer())
fat = Column('fat', REAL())
fiber = Column('fiber', REAL())
protein = Column('protein', REAL())
category = Column('category', CHAR(20), nullable=False)
image = Column('image', VARCHAR(400), default=None)
title = Column('title', VARCHAR(200), nullable=False)
createdAt = Column('created_at', TIMESTAMP())

def __repr__(self):
return f"<Food '{self.title}'>"
8 changes: 4 additions & 4 deletions users/token.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from itsdangerous import URLSafeTimedSerializer

from app import app
from config import Config


def generate_confirmation_token(email):
Expand All @@ -13,9 +13,9 @@ def confirm_token(token, expiration=3600):
try:
email = serializer.loads(
token,
salt=app.config['SECURITY_PASSWORD_SALT'],
salt= Config['SECURITY_PASSWORD_SALT'],
max_age=expiration
)
except:
return False
return email
return False
return email

0 comments on commit d8b8242

Please sign in to comment.