Skip to content
Permalink
Browse files

Add moderator support and token distribution

  • Loading branch information...
Smashman committed Jun 26, 2019
1 parent b90dca0 commit cc28aa16ed37df785fd5a7065c378073f3d0a07b
@@ -39,6 +39,7 @@
from .tf2.views import tf2 as tf2_blueprint
from .users.views import users as users_blueprint
from .mods.views import mods as mods_blueprint
from .moderator.views import moderator as moderator_blueprint

# Admin
from .users.models import User
@@ -53,6 +54,7 @@
app.register_blueprint(users_blueprint)
app.register_blueprint(mods_blueprint)
app.register_blueprint(tf2_blueprint)
app.register_blueprint(moderator_blueprint)

# Assets
from assets import assets
@@ -123,7 +123,7 @@ h1
&.open
+transform(rotate(180deg))

input[type=text].input-default, textarea.input-default, select.input-default, .ms-choice
input[type=text].input-default, textarea.input-default, select.input-default, .ms-choice, input[type=number].input-default
border: 0
padding: 3px
border-radius: 2px
No changes.
@@ -0,0 +1,10 @@
from flask.ext.wtf import Form
from wtforms import BooleanField, IntegerField, SubmitField
from wtforms.validators import NumberRange
from flask.ext.wtf.html5 import NumberInput


class TokenGrant(Form):
token_number = IntegerField('Tokens:', widget=NumberInput(), validators=[NumberRange(min=-1, max=10)])
is_moderator = BooleanField('Is user a moderator:')
save = SubmitField("Save")
@@ -0,0 +1,30 @@
from flask import Blueprint, render_template, abort, flash, redirect, url_for
from flask.ext.login import login_required, current_user
from ..users.models import User
from forms import TokenGrant
from app import db

moderator = Blueprint("moderator", __name__, url_prefix="/moderator")

@login_required
@moderator.route('/token/<int:user_id>/', methods=['GET', 'POST'])
def token(user_id=None):
user = None
token_form = None
if not current_user.is_moderator():
return abort(403)
if user_id:
user = User.query.get_or_404(user_id)
token_form = TokenGrant()

if token_form.validate_on_submit():
user.user_class = 1 if token_form.is_moderator.data else 0
user.upload_credits = token_form.token_number.data
db.session.add(user)
db.session.commit()
flash("Save successful.", "success")
return redirect(url_for("users.user_page", user_id=user.account_id))

token_form.is_moderator.data = user.is_moderator()
token_form.token_number.data = user.upload_credits
return render_template('moderator/token.html', title="Grant tokens", user=user, token_form=token_form)
@@ -7,7 +7,7 @@
{%- if current_user.is_uploader() -%}
<li><a href="{{ url_for('mods.upload') }}">Upload mod<br />(
{%- if current_user.upload_credits != -1 -%}
{{ current_user.upload_credits | default(0) }} {%- else -%} Infinite {%- endif %} credit{{ current_user.upload_credits | pluralize }}
{{ current_user.upload_credits | default(0) }} {%- else -%} Infinite {%- endif %} token{{ current_user.upload_credits | pluralize }}
)</a></li>
{%- endif -%}
{%- if current_user.is_admin() -%}
@@ -7,7 +7,7 @@
{%- if user_info.avatar_small -%}
<div class="iconholder"><img src="{{ user_info.avatar_small }}"/></div>
{%- endif -%}
<div class="name">{{ user_info.name }}</div>
<div class="name">{{ user_info.name }}{{ ' (Moderator)' if header and user_info.is_moderator() }}</div>
{%- if header -%}
<div class="dropdown-arrow"></div>
{%- endif -%}
@@ -0,0 +1,13 @@
{% extends "layout.html" %}
{% from "macros.html" import form_field, steam_block, field_errors %}
{% block content %}
{%- if user -%}
<div class="author-block cf">{{ steam_block(user, no_link=True) }}</div>
<form method=POST id="token_form">
{{ token_form.hidden_tag() }}
{{ form_field(token_form.token_number) }} (-1 is Infinite)
{{ form_field(token_form.is_moderator) }}
{{ token_form.save(class="input-default") }}
</form>
{%- endif -%}
{% endblock %}
@@ -2,6 +2,11 @@
{% block content %}
{{ user.name }}
<div><a href="{{ user.perma_profile_url }}" target="_blank">Steam</a></div>
{%- if current_user.is_moderator() -%}
<div>Current Tokens: {{ user.upload_credits }}</div>
<div>Is moderator: <input type="checkbox" disabled="disabled" {{ 'checked' if user.is_moderator() }}/></div>
<div><a href="{{ url_for('moderator.token', user_id=user.account_id) }}">Grant Tokens and Manage User</a></div>
{%- endif -%}
{%- if current_user.account_id == user.account_id -%}
{%- if current_user.is_uploader() -%}
<div><a href="{{ url_for('mods.upload') }}">Upload a mod</a></div>
@@ -11,6 +11,10 @@ class AnonymousUser(AnonymousUserMixin):
def update_steam():
return False

@staticmethod
def is_moderator():
return False

@staticmethod
def is_admin():
return False
@@ -63,6 +67,9 @@ def is_anonymous():
def is_authenticated():
return True

def is_moderator(self):
return True if self.user_class > 0 else False

def is_admin(self):
return True if self.user_class > 1 else False

@@ -13,7 +13,6 @@ Jinja2==2.7.3
Mako==1.0.0
MarkupSafe==0.23
MySQL-python==1.2.5
Pillow==2.5.0
SQLAlchemy==0.9.6
WTForms==1.0.5
Werkzeug==0.9.6

0 comments on commit cc28aa1

Please sign in to comment.
You can’t perform that action at this time.