Skip to content

Commit

Permalink
Clean up, add docstrings, remove commented out stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
euphwes committed Jun 3, 2018
1 parent e159053 commit 21d3022
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[TYPECHECK]
ignored-classes=scoped_session,SQLAlchemy
ignored-classes=scoped_session,SQLAlchemy,alembic.op

[MESSAGES CONTROL]
# Enable the message, report, category or checker with the given id(s). You can
Expand Down
2 changes: 1 addition & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@
#I don't want to specifically name every route I want to import here
from app.persistence import models
from .routes import *
from .commands import create_new_test_comp
from .commands import create_new_test_comp
5 changes: 2 additions & 3 deletions app/persistence/comp_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
""" Utility module for providing access to business logic for users. """

import json
from datetime import datetime

from app import DB
Expand All @@ -17,12 +16,13 @@ def get_active_competition():
""" Get the current active competition. """
return Competition.query.filter(Competition.active).first()


def get_competition(competition_id):
""" Get a competition by id """
comp = Competition.query.get(competition_id)
#comp["events"] = CompetitionEvent.query.filter_by(competition_id = competition_id).all()
return comp


def create_new_competition(title, reddit_id, event_data):
""" Creates a new active competition, events for that competition, and ensures all the other
competitions are now inactive. Returns the newly created competition. """
Expand All @@ -47,7 +47,6 @@ def create_new_competition(title, reddit_id, event_data):
scramble = Scramble(scramble = scramble_text)
comp_event.scrambles.append(scramble)


new_comp.events.append(comp_event)

DB.session.add(new_comp)
Expand Down
13 changes: 9 additions & 4 deletions app/persistence/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ class Event(Model):
description = Column(String(128))
CompEvents = relationship("CompetitionEvent", backref="Event")


class Scramble(Model):
__tablename__ = 'scrambles'
id = Column(Integer, primary_key = True)
""" A scramble for a specific event at a specific competition. """
__tablename__ = 'scrambles'
id = Column(Integer, primary_key = True)
scramble = Column(Text())
competition_event_id = Column(Integer, ForeignKey('competition_event.id'))
scramble = Column(Text())


class CompetitionEvent(Model):
""" Associative model for an event held at a competition - FKs to the competition and event,
Expand All @@ -67,7 +70,8 @@ class CompetitionEvent(Model):
id = Column(Integer, primary_key=True)
competition_id = Column(Integer, ForeignKey('competitions.id'))
event_id = Column(Integer, ForeignKey('events.id'))
scrambles = relationship('Scramble', backref='CompetitionEvent', primaryjoin = id == Scramble.competition_event_id)
scrambles = relationship('Scramble', backref='CompetitionEvent',
primaryjoin = id == Scramble.competition_event_id)


class Competition(Model):
Expand All @@ -84,6 +88,7 @@ class Competition(Model):
events = relationship('CompetitionEvent', backref='Competition',
primaryjoin=id == CompetitionEvent.competition_id)


class UserEventResults(Model):
""" A model detail a user's results for a single event at competition. References the user,
the competitionEvent, and has fields for best single, average, and up to five solves.
Expand Down
1 change: 1 addition & 0 deletions app/persistence/user_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from app import DB
from app.persistence.models import User

# -------------------------------------------------------------------------------------------------

def get_all_users():
Expand Down
8 changes: 3 additions & 5 deletions app/routes/auth/auth_routes.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
""" Routes related to authentication. """

from flask import render_template, request, redirect, url_for
from flask import request, redirect, url_for
from flask_login import current_user, login_user, logout_user

from app import CUBERS_APP
from app.persistence.user_manager import update_or_create_user, get_all_users
from app.persistence.user_manager import update_or_create_user

from app.util.reddit_util import get_username_refresh_token_from_code, get_user_auth_url
# -------------------------------------------------------------------------------------------------



# -------------------------------------------------------------------------------------------------

@CUBERS_APP.route("/logout")
def logout():
Expand Down
22 changes: 11 additions & 11 deletions app/routes/routes.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
""" Routes related to the time-entry and competition results pages. """

from flask import render_template, abort

from app import CUBERS_APP
from app.persistence import comp_manager

from flask import render_template
from flask_login import current_user

import sys
# -------------------------------------------------------------------------------------------------

@CUBERS_APP.route('/')
def index():
""" Main page for the app. Shows the competition time entry page if logged in, or an informative
landing page if not. """
#if current_user.is_authenticated:
#return render_template('comp.html')
return render_template('index.html', current_competition = comp_manager.get_active_competition())

competition = comp_manager.get_active_competition()
return render_template('index.html', current_competition = competition)


@CUBERS_APP.route('/comp/<competition_id>')
def competition(competition_id):
try:
competition_id = int(competition_id)
except ValueError:
print("Invalid competition_id", file=sys.stderr)

return render_template('comp.html', competition = comp_manager.get_competition(competition_id))
# TODO: come up with custom 404 not found page
return abort(404)

return render_template('comp.html', competition = comp_manager.get_competition(competition_id))
9 changes: 5 additions & 4 deletions app/util/reddit_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
""" Utility functions for dealing with PRAW Reddit instances. """
import re
import datetime
from praw import Reddit
from app import CUBERS_APP
from . import events_util
Expand All @@ -12,6 +11,7 @@
CLIENT_SECRET = CUBERS_APP.config['REDDIT_CLIENT_SECRET']

BLACKLIST = ["CaptainCockmunch", "LorettAttran", "purplepinapples", "CuberSaiklick", "xXxSteelVenomxXx"]

# -------------------------------------------------------------------------------------------------

#pylint: disable=C0111
Expand All @@ -20,7 +20,7 @@ def get_new_reddit():
return Reddit(client_id=CLIENT_ID, client_secret=CLIENT_SECRET, redirect_uri=REDIRECT,
user_agent = USER_AGENT)


#pylint: disable=C0111
def get_username_refresh_token_from_code(code):
""" Returns the username and current refresh token for a given Reddit auth code. """
Expand All @@ -30,12 +30,13 @@ def get_username_refresh_token_from_code(code):

return username, refresh_token


#pylint: disable=C0111
def get_user_auth_url(state='...'):
""" Returns a url for authenticating with Reddit. """
return get_new_reddit().auth.url(['identity', 'read', 'submit'], state, 'permanent')



#pylint: disable=C0111
def parse_comment(comment):
matcher = re.compile('^([^>].+?)\\:\\s*([^\\sA-Za-z!@#\$\%^&*()_+\-=,;\\\[\]\?<>`~\|]+).*')
Expand Down

0 comments on commit 21d3022

Please sign in to comment.