Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add config page

  • Loading branch information...
commit 7214752600b3674d3b76576d17903cefc1f8ca80 1 parent 628a2ed
@artnez authored
View
7 src/faceoff/forms.py
@@ -97,3 +97,10 @@ class ProfileForm(Form):
label='New Password',
validators=[Optional(), Length(4)]
)
+
+class ConfigForm(Form):
+ access_code = TextField(
+ label='Access Code',
+ id='access_code',
+ description='This code is used to create a new Faceoff account.'
+ )
View
8 src/faceoff/templates/config.html
@@ -0,0 +1,8 @@
+{% extends 'layouts/simple.html' %}
+{% set head_title='League Configuration' %}
+{% set logo_url = url_for('landing') %}
+{% block content %}
+<div>
+ {% include 'forms/config.html' %}
+</div>
+{% endblock %}
View
8 src/faceoff/templates/forms/config.html
@@ -0,0 +1,8 @@
+{% from 'macros/form.html' import render_field %}
+<form id='config' action='{{ request.url }}' method='post'>
+ <fieldset>
+ {{ render_field(config_form.access_code, errpos='inline') }}
+ <button type='submit' class='btn btn-large'>Save Config</button>
+ <a href='#' class='cancel go-back'>cancel</a>
+ </fieldset>
+</form>
View
22 src/faceoff/views.py
@@ -12,7 +12,8 @@
from faceoff import app
from faceoff.debug import debug
from faceoff.forms import \
- LoginForm, JoinForm, ReportForm, NewLeagueForm, SettingsForm, ProfileForm
+ LoginForm, JoinForm, ReportForm, NewLeagueForm, SettingsForm, ProfileForm, \
+ ConfigForm
from faceoff.helpers.decorators import authenticated, templated
from faceoff.models.user import \
get_active_users, create_user, update_user, auth_login, auth_logout
@@ -22,7 +23,7 @@
from faceoff.models.match import \
create_match, get_match_history, get_league_ranking, get_user_standing, \
rebuild_rankings
-from faceoff.models.setting import get_setting
+from faceoff.models.setting import get_setting, del_setting, set_setting
@app.teardown_request
def db_close(exception): # pylint:disable=W0613
@@ -156,6 +157,23 @@ def new_league():
create_league(form.name.data)
return redirect(url_for('landing'))
+@app.route('/config', methods=('GET', 'POST'))
+@templated()
+@authenticated
+def config():
+ form = ConfigForm(request.form)
+ if request.method != 'POST' or not form.validate():
+ form.access_code.data = get_setting('access_code')
+ return dict(config_form=form)
+ access_code = form.access_code.data.strip()
+ if access_code == '':
+ del_setting('access_code')
+ flash('Access code removed')
+ else:
+ set_setting('access_code', access_code)
+ flash('Access changed')
+ return redirect(url_for('config'))
+
@app.route('/<league>/')
@templated()
@authenticated
Please sign in to comment.
Something went wrong with that request. Please try again.