Skip to content

Commit

Permalink
Corrected inconsistent spacing and indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
sunday Nwuguru committed Jun 1, 2016
1 parent 5b8b36a commit 4ba9e13
Show file tree
Hide file tree
Showing 11 changed files with 546 additions and 468 deletions.
114 changes: 60 additions & 54 deletions app/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,71 +5,77 @@

encrypt_key = 'bucketlists api'


def save(model):
""" Save a row in the database """
try:
db.session.add(model)
db.session.commit()
return True
except:
return False
""" Save a row in the database """
try:
db.session.add(model)
db.session.commit()
return True
except:
return False


def delete(model):
""" Deletes a row from the database """
try:
db.session.delete(model)
db.session.commit()
return True
except:
return False
""" Deletes a row from the database """
try:
db.session.delete(model)
db.session.commit()
return True
except:
return False


def get_user_id_from_token(token):
"""
This method extracts the user id from provided access token
"""
data = token.split('|')
try:
return data[1]
except:
return 0
"""
This method extracts the user id from provided access token
"""
data = token.split('|')
try:
return data[1]
except:
return 0


def validate_args(fields={}):
"""
This method helps to parse and validate provided parameters.
It will return parsed argument if the require fields are in request
"""
parser = reqparse.RequestParser()
for field in fields.keys():
help_message = field + ' can not be blank'
parser.add_argument(field, required=fields[field], help=help_message)

return parser.parse_args()
"""
This method helps to parse and validate provided parameters.
It will return parsed argument if the require fields are in request
"""
parser = reqparse.RequestParser()
for field in fields.keys():
help_message = field + ' can not be blank'
parser.add_argument(field, required=fields[field], help=help_message)

return parser.parse_args()


def md5(string):
"""
This method will return md5 hash of a given string
"""
return hashlib.md5(string.encode("utf")).hexdigest()
"""
This method will return md5 hash of a given string
"""
return hashlib.md5(string.encode("utf")).hexdigest()


def encrypt(string):
"""
This method will return encrypted version of a string.
It will return False if encryption fails
"""
try:
signer = TimestampSigner(encrypt_key)
return signer.sign(string)
except:
return False
"""
This method will return encrypted version of a string.
It will return False if encryption fails
"""
try:
signer = TimestampSigner(encrypt_key)
return signer.sign(string)
except:
return False


def decrypt(string, max_age=15000):
"""
This method will return decrypted version of an encrypted string.
If age of encryption is greater than max age it will return False
"""
try:
signer = TimestampSigner(encrypt_key)
return signer.unsign(string, max_age=max_age)
except:
return False
"""
This method will return decrypted version of an encrypted string.
If age of encryption is greater than max age it will return False
"""
try:
signer = TimestampSigner(encrypt_key)
return signer.unsign(string, max_age=max_age)
except:
return False
59 changes: 32 additions & 27 deletions app/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from app import db
from datetime import datetime
from app import db
from app.helper import encrypt, decrypt


Expand All @@ -8,21 +8,23 @@ class BucketListModel(db.Model):
name = db.Column(db.String(255), unique=True)
created_by = db.Column(db.Integer, db.ForeignKey('user.id'))
date_created = db.Column(db.DateTime, default=db.func.current_timestamp())
date_modified = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp())
user = db.relationship('User', backref=db.backref('bucketlists', lazy='dynamic'))
date_modified = db.Column(db.DateTime, default=db.func.current_timestamp(
), onupdate=db.func.current_timestamp())
user = db.relationship(
'User', backref=db.backref('bucketlists', lazy='dynamic'))

def __init__(self, name, user):
self.name = name
self.name = name
self.user = user

def get(self):
return {
'id':self.id,
'name':self.name,
'created_by':self.user.username,
'date_created':str(self.date_created),
'date_modified':str(self.date_modified),
'items':self.get_items()
'id': self.id,
'name': self.name,
'created_by': self.user.username,
'date_created': str(self.date_created),
'date_modified': str(self.date_modified),
'items': self.get_items()
}

def get_items(self):
Expand All @@ -32,7 +34,6 @@ def get_items(self):
data.append(item.get())
return data


def __repr__(self):
return '<BucketListModel %r>' % self.name

Expand All @@ -42,22 +43,25 @@ class BucketListItemModel(db.Model):
task = db.Column(db.String(255))
done = db.Column(db.Boolean(), default=False)
date_created = db.Column(db.DateTime, default=db.func.current_timestamp())
date_modified = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp())
bucketlist_id = db.Column(db.Integer, db.ForeignKey('bucket_list_model.id'))
bucketlist = db.relationship('BucketListModel', backref=db.backref('items', lazy='dynamic'))
date_modified = db.Column(db.DateTime, default=db.func.current_timestamp(
), onupdate=db.func.current_timestamp())
bucketlist_id = db.Column(
db.Integer, db.ForeignKey('bucket_list_model.id'))
bucketlist = db.relationship(
'BucketListModel', backref=db.backref('items', lazy='dynamic'))

def __init__(self, task, bucketlist):
self.task = task
self.task = task
self.bucketlist = bucketlist

def get(self):
return {
'id':self.id,
'task':self.task,
'done':self.done,
'bucketlists':self.bucketlist.name,
'date_created':str(self.date_created),
'date_modified':str(self.date_modified)
'id': self.id,
'task': self.task,
'done': self.done,
'bucketlists': self.bucketlist.name,
'date_created': str(self.date_created),
'date_modified': str(self.date_modified)
}

def __repr__(self):
Expand All @@ -70,7 +74,8 @@ class User(db.Model):
password = db.Column(db.String(20))
email = db.Column(db.String(200), unique=True)
date_created = db.Column(db.DateTime, default=db.func.current_timestamp())
date_modified = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp())
date_modified = db.Column(db.DateTime, default=db.func.current_timestamp(
), onupdate=db.func.current_timestamp())

def __init__(self, username, email, password):
self.username = username
Expand All @@ -82,11 +87,11 @@ def __repr__(self):

def get(self):
return {
'id':self.id,
'username':self.username,
'email':self.email,
'date_created':str(self.date_created),
'date_modified':str(self.date_modified),
'id': self.id,
'username': self.username,
'email': self.email,
'date_created': str(self.date_created),
'date_modified': str(self.date_modified),
}

def generate_token(self):
Expand Down
Loading

0 comments on commit 4ba9e13

Please sign in to comment.