Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add ui support for inactive leagues

  • Loading branch information...
commit df4923c269ba98a5c521990d15126c56fdc6a403 1 parent 9019b71
Artem Nezvigin authored
21 src/faceoff/forms.py
View
@@ -21,7 +21,12 @@ class JoinForm(Form):
nickname = TextField(
label='Nickname',
id='join_nickname',
- validators=[Required(), Length(2, 20), Regexp(r'^[a-zA-Z0-9_]+$'), UniqueNickname()]
+ validators=[
+ Required(),
+ Length(2, 20),
+ Regexp(r'^[a-zA-Z0-9_]+$'),
+ UniqueNickname()
+ ]
)
password = PasswordField(
label='Password',
@@ -68,12 +73,20 @@ class NewLeagueForm(Form):
name = TextField(
label='League Name',
id='name',
- validators=[Required(), Length(2), NoneOf(['new'], values_formatter=lambda v: map(str.lower, v))]
+ validators=[
+ Required(),
+ Length(2),
+ NoneOf(['new'], values_formatter=lambda v: map(str.lower, v))
+ ]
)
class SettingsForm(Form):
name = TextField(
label='League Name',
- id='name',
- validators=[Required(), Length(2), NoneOf(['new'], values_formatter=lambda v: map(str.lower, v))]
+ validators=[
+ Required(),
+ Length(2),
+ NoneOf(['new'], values_formatter=lambda v: map(str.lower, v))
+ ]
)
+ active = RadioField(label='Active?', choices=[('1', 'Yes'), ('0', 'No')])
25 src/faceoff/models/league.py
View
@@ -36,21 +36,24 @@ def create_league(db, name, description=None, active=True):
)
@use_db
-def change_league_name(db, league_id, name, slug=None):
+def update_league(db, league_id, name=None, active=None):
league = find_league(db, id=league_id)
- name = name.strip()
- if league is None or league['name'] == name:
- return league
- db.update(
- 'league',
- league_id,
- name = name,
- slug = generate_league_slug(db, name)
- )
+ if league is None:
+ return False
+ fields = {}
+ if name is not None:
+ name = name.strip()
+ slug = league['slug'] if name == league['name'] else \
+ generate_league_slug(db, name)
+ fields['name'] = name
+ fields['slug'] = slug
+ if active is not None:
+ fields['active'] = '1' if active else '0'
+ db.update('league', league_id, **fields)
return find_league(db, id=league_id)
@use_db
-def generate_league_slug(db, name, omit=None):
+def generate_league_slug(db, name):
short = re.sub(r'[^0-9a-zA-Z]+', '-', name.lower()).strip('-')
count = 0
while True:
4 src/faceoff/templates/dashboard.html
View
@@ -1,7 +1,9 @@
{% extends 'layouts/league.html' %}
{% set head_title = 'Dashboard' %}
{% block content %}
-{% include 'forms/report.html' %}
+{% if current_league.active %}
+ {% include 'forms/report.html' %}
+{% endif %}
<div id='profile'>
<p class='rank'>
<span class='player'>
3  src/faceoff/templates/forms/settings.html
View
@@ -1,7 +1,8 @@
-{% from 'macros/form.html' import render_field %}
+{% from 'macros/form.html' import render_field, render_radio_field %}
<form id='settings' action='{{ request.url }}' method='post'>
<fieldset>
{{ render_field(settings_form.name, errpos='inline') }}
+ {{ render_radio_field(settings_form.active) }}
<button type='submit' class='btn btn-large'>Save</button>
</fieldset>
</form>
7 src/faceoff/templates/layouts/league.html
View
@@ -39,6 +39,13 @@
</div>
{% endif %}
<div id='content'>
+ {% if not current_league.active %}
+ <div class='alert alert-block'>
+ <h4 class='alert-heading'>Inactive League</h4>
+ <p>This league has been set to an inactive state. You will not be able to record new matches or
+ change existing ones.</p>
+ </div>
+ {% endif %}
<h1>{{ page_title or head_title }}</h1>
{% block content %}{% endblock %}
</div>
20 src/faceoff/templates/macros/form.html
View
@@ -17,3 +17,23 @@
</div>
</div>
{%- endmacro %}
+
+{% macro render_radio_field(field) %}
+<div class='control-group{{ ' error' if field.errors | length }}'>
+ <label class='control-label'>
+ {{ field.label.text }}
+ {%- if field.description -%}
+ <span class='description'>(<a href='#' class='tip' title='{{ field.description }}'>?</a>)</span>
+ {%- endif -%}
+ </label>
+ <div class='controls'>
+ {%- for subfield in field %}
+ <label class='radio'>
+ <input type='radio' id='{{ subfield.id }}' name='{{ subfield.name }}' value='{{ subfield.data }}' {% if subfield.data == field.data %}checked="checked"{% endif %} />
+ {{ subfield.label.text }}
+ </label>
+ {%- endfor %}
+ <p class='help-block'>{{ field.errors[0] }}</p>
+ </div>
+</div>
+{%- endmacro %}
28 src/faceoff/views.py
View
@@ -7,14 +7,19 @@
import logging
from datetime import datetime
from time import localtime, strftime
-from flask import g, request, session, abort, redirect, url_for, send_from_directory
+from flask import \
+ g, request, session, abort, redirect, url_for, send_from_directory
from faceoff import app
from faceoff.debug import debug
-from faceoff.forms import LoginForm, JoinForm, ReportForm, NewLeagueForm, SettingsForm
+from faceoff.forms import \
+ LoginForm, JoinForm, ReportForm, NewLeagueForm, SettingsForm
from faceoff.helpers.decorators import authenticated, templated
-from faceoff.models.user import get_active_users, create_user, auth_login, auth_logout
-from faceoff.models.league import find_league, get_active_leagues, create_league, change_league_name
-from faceoff.models.match import create_match, get_match_history, get_league_ranking, get_user_standing
+from faceoff.models.user import \
+ get_active_users, create_user, auth_login, auth_logout
+from faceoff.models.league import \
+ find_league, get_active_leagues, create_league, update_league
+from faceoff.models.match import \
+ create_match, get_match_history, get_league_ranking, get_user_standing
from faceoff.models.setting import get_setting
@app.teardown_request
@@ -27,7 +32,7 @@ def get_league_from_url(endpoint, view_args):
if not view_args or 'league' not in view_args:
return
league = find_league(slug=view_args.pop('league'))
- if league is None or league['active'] != 1:
+ if league is None:
abort(404)
g.current_league = league
@@ -144,6 +149,8 @@ def dashboard():
@templated()
@authenticated
def report():
+ if not g.current_league['active']:
+ abort(403)
form = ReportForm(get_active_users(), request.form)
if not form.validate():
return dict(form=form)
@@ -174,8 +181,13 @@ def settings():
form = SettingsForm(request.form)
if request.method != 'POST':
form.name.data = g.current_league['name']
+ form.active.data = '1' if g.current_league['active'] else '0'
return dict(settings_form=form)
if form.validate():
- league = change_league_name(league['id'], form.name.data)
- return redirect(url_for('dashboard', league=league['slug']))
+ league = update_league(
+ league['id'],
+ name = form.name.data,
+ active = True if form.active.data == '1' else False
+ )
+ return redirect(url_for('settings', league=league['slug']))
return dict(settings_form=form)
Please sign in to comment.
Something went wrong with that request. Please try again.