Skip to content

Commit

Permalink
Merge pull request #23 from yograterol/develop
Browse files Browse the repository at this point in the history
Fix minor issues in Tahir-API
  • Loading branch information
yograterol committed Oct 26, 2013
2 parents c043591 + 07376fc commit fd808bb
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 27 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'simplejson',
'SQLAlchemy',
'zope.sqlalchemy',
'alembic'
]

if sys.version_info[0] == 2 and sys.version_info[1] <= 6:
Expand Down
48 changes: 22 additions & 26 deletions tahrir_api/dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def badge_exists(self, badge_id):
"""

return self.session.query(Badge).filter(
func.lower(Badge.id) == func.lower(badge_id)).count() != 0
func.lower(Badge.id) == func.lower(badge_id)).count() != 0

def get_badge(self, badge_id):
"""
Expand All @@ -70,7 +70,7 @@ def get_badge(self, badge_id):

if self.badge_exists(badge_id):
return self.session.query(Badge).filter(
func.lower(Badge.id) == func.lower(badge_id)).one()
func.lower(Badge.id) == func.lower(badge_id)).one()
return None

def get_badges_from_tags(self, tags, match_all=False):
Expand All @@ -96,8 +96,8 @@ def get_badges_from_tags(self, tags, match_all=False):
# Return badges matching any of the tags
for tag in tags:
badges.extend(self.session.query(Badge).filter(
func.lower(Badge.tags).contains(
str(tag + ',').lower())).all())
func.lower(Badge.tags).contains(
str(tag + ',').lower())).all())

# Eliminate any duplicates.
unique_badges = list()
Expand Down Expand Up @@ -198,13 +198,12 @@ def person_exists(self, email=None, id=None, nickname=None):
query = self.session.query(Person)
if email:
return query.filter(
func.lower(Person.email) == func.lower(email)).count() != 0
func.lower(Person.email) == func.lower(email)).count() != 0
elif id:
return query.filter_by(id=id).count() != 0
elif nickname:
return query.filter(
func.lower(Person.nickname) == func.lower(
nickname)).count() != 0
return query.filter(func.lower(Person.nickname) == func.lower(
nickname)).count() != 0
else:
return False

Expand Down Expand Up @@ -247,7 +246,7 @@ def get_person_email(self, person_id):

if self.person_exists(id=person_id):
return self.session.query(Person).filter(
func.lower(Person.id) == func.lower(person_id)).one().email
func.lower(Person.id) == func.lower(person_id)).one().email
return None

def get_person(self, person_email=None, id=None, nickname=None):
Expand All @@ -269,14 +268,12 @@ def get_person(self, person_email=None, id=None, nickname=None):

if person_email and self.person_exists(email=person_email):
return query.filter(
func.lower(Person.email) == \
func.lower(person_email)).one()
func.lower(Person.email) == func.lower(person_email)).one()
elif id and self.person_exists(id=id):
return query.filter_by(id=id).one()
elif nickname and self.person_exists(nickname=nickname):
return query.filter(
func.lower(Person.nickname) == \
func.lower(nickname)).one()
func.lower(Person.nickname) == func.lower(nickname)).one()
else:
return None

Expand Down Expand Up @@ -359,8 +356,8 @@ def issuer_exists(self, origin, name):
:param issuer_id: The unique ID of this issuer
"""

return self.session.query(Issuer)\
.filter_by(origin=origin, name=name).count() != 0
return self.session.query(Issuer).filter_by(
origin=origin, name=name).count() != 0

@autocommit
def add_invitation(self, badge_id, created_on=None, expires_on=None,
Expand Down Expand Up @@ -407,8 +404,8 @@ def invitation_exists(self, invitation_id):
:param invitation_id: The unique ID of this invitation
"""

return self.session.query(Invitation)\
.filter_by(id=invitation_id).count() != 0
return self.session.query(Invitation).filter_by(
id=invitation_id).count() != 0

def get_all_invitations(self):
"""
Expand All @@ -426,8 +423,8 @@ def get_invitation(self, invitation_id):
"""

if self.invitation_exists(invitation_id):
return self.session.query(Invitation)\
.filter_by(id=invitation_id).one()
return self.session.query(Invitation).filter_by(
id=invitation_id).one()
else:
return False

Expand All @@ -440,8 +437,8 @@ def get_invitations(self, person_id):
will be retrieved.
"""

return self.session.query(Invitation)\
.filter_by(created_by=person_id).all()
return self.session.query(Invitation).filter_by(
created_by=person_id).all()

def get_issuer(self, issuer_id):
"""
Expand Down Expand Up @@ -528,9 +525,9 @@ def get_assertions_by_email(self, person_email):

if self.person_exists(email=person_email):
person_id = self.session.query(Person).filter_by(
email=person_email).one().id
email=person_email).one().id
return self.session.query(Assertion).filter_by(
person_id=person_id).all()
person_id=person_id).all()
else:
return False

Expand All @@ -544,8 +541,7 @@ def get_assertions_by_badge(self, badge_id):

if self.badge_exists(badge_id):
return self.session.query(Assertion).filter(
func.lower(Assertion.badge_id) ==\
func.lower(badge_id)).all()
func.lower(Assertion.badge_id) == func.lower(badge_id)).all()
else:
return False

Expand All @@ -566,7 +562,7 @@ def assertion_exists(self, badge_id, email):
return False

return self.session.query(Assertion).filter_by(
person_id=person.id, badge_id=badge_id).count() != 0
person_id=person.id, badge_id=badge_id).count() != 0

@autocommit
def add_assertion(self, badge_id, person_email, issued_on):
Expand Down
1 change: 0 additions & 1 deletion tahrir_api/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
scoped_session,
sessionmaker,
relationship,
backref,
)


Expand Down
1 change: 1 addition & 0 deletions tahrir_api/scripts/initializedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import sys
import transaction
import pprint

from sqlalchemy import engine_from_config
from paste.deploy import appconfig
Expand Down
1 change: 1 addition & 0 deletions tahrir_api/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
""" Module to keep random utils. """


def autocommit(func):
""" A decorator that autocommits after API calls unless
configured otherwise.
Expand Down

0 comments on commit fd808bb

Please sign in to comment.