Skip to content

Commit

Permalink
PEP8 Guideline in: dbapi.py
Browse files Browse the repository at this point in the history
  • Loading branch information
yograterol committed Oct 26, 2013
1 parent c043591 commit d33ec07
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 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 @@ -268,15 +267,13 @@ def get_person(self, person_email=None, id=None, nickname=None):
query = self.session.query(Person)

if person_email and self.person_exists(email=person_email):
return query.filter(
func.lower(Person.email) == \
func.lower(person_email)).one()
return query.filter(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()
return query.filter(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 Expand Up @@ -689,7 +685,7 @@ def _make_leaderboard(self, start=None, stop=None):

leaderboard = leaderboard\
.order_by('count_1 desc')\
.filter(Person.opt_out == False)\
.filter(not Person.opt_out)\
.group_by(Person)\
.all()

Expand Down

0 comments on commit d33ec07

Please sign in to comment.