Commit bca7b24c authored by Robin Sonnabend's avatar Robin Sonnabend

Merge branch 'master' of git.fsmpi.rwth-aachen.de:redl/redeleitsystem

parents 17779aac ddcfbe4b
......@@ -26,6 +26,10 @@ class AddStatementForm(Form):
speaker_name = StringField("Speaker", validators=[InputRequired("Entering the speaker is required.")])
topic = HiddenField("Topic")
class NewEventForm(Form):
name = StringField("Name", validators=[InputRequired("Entering the name is required.")])
class NewTopicForm(Form):
name = StringField("Name", validators=[InputRequired("Entering the name is required.")])
mode = StringField("Mode", validators=[InputRequired("Entering the mode is required."), AnyOf(values=["balanced", "fifo"], message="Must be 'balanced' or 'fifo' atm.")])
event_id = HiddenField("Event_ID")
......@@ -2,8 +2,8 @@ from flask import Blueprint, redirect, url_for, request, flash, abort, send_file
from flask.ext.login import login_required
from passlib.hash import pbkdf2_sha256
from models.database import User, Topic
from models.forms import AdminUserForm, NewUserForm, NewTopicForm
from models.database import User, Topic, Event
from models.forms import AdminUserForm, NewUserForm, NewTopicForm, NewEventForm
from shared import db, admin_permission, render_layout
......@@ -68,6 +68,59 @@ def user_new():
return redirect(url_for(".user"))
return render_layout("admin_user_new.html", form=form)
@admin.route("/event/")
@login_required
@admin_permission.require()
def event():
events = Event.query.all()
return render_layout("admin_event_index.html", events=events)
@admin.route("/event/new", methods=["GET", "POST"])
@login_required
@admin_permission.require()
def event_new():
form = NewEventForm()
if form.validate_on_submit():
if Topic.query.filter_by(name=form.name.data).count() > 0:
flash("There already is an event with that name.", "alert-error")
return render_layout("admin_event_new.html", form=form)
event = Event(form.name.data)
db.session.add(event)
db.session.commit()
return redirect(url_for(".event"))
return render_layout("admin_event_new.html", form=form)
@admin.route("/event/delete")
@login_required
@admin_permission.require()
def event_delete():
event_id = request.args.get("id", None)
if event_id is not None:
event = Event.query.filter_by(id=event_id).first()
db.session.delete(event)
db.session.commit()
flash("Event deleted.", "alert-success")
return redirect(url_for(".event"))
@admin.route("/event/edit", methods=["GET", "POST"])
@login_required
@admin_permission.require()
def event_edit():
event_id = request.args.get("id", None)
if event_id is not None:
event = db.session.query(Event).filter_by(id=event_id).first()
form = NewEventForm(obj=topic)
if form.validate_on_submit():
form.populate_obj(topic)
db.session.commit()
return redirect(url_for(".index"))
else:
return render_layout("admin_event_edit.html", form=form, id=event_id)
else:
return redirect(url_for(".index"))
@admin.route("/topic/new", methods=["GET", "POST"])
@login_required
......@@ -78,7 +131,7 @@ def topic_new():
if Topic.query.filter_by(name=form.name.data).count() > 0:
flash("There already is an topic with that name.", "alert-error")
return render_layout("admin_topic_new.html", form=form)
topic = Topic(form.name.data, form.mode.data)
topic = Topic(form.name.data, form.mode.data, form.event_id.data)
db.session.add(topic)
db.session.commit()
return redirect(url_for(".topic"))
......@@ -87,7 +140,7 @@ def topic_new():
@admin.route("/topic/delete")
@login_required
@admin_permission.require()
def topc_delete():
def topic_delete():
topic_id = request.args.get("id", None)
if topic_id is not None:
topic = Topic.query.filter_by(id=topic_id).first()
......
{% extends "layout.html" %}
{% from "macros.html" import render_form %}
{% block title %}Edit Event - Administration{% endblock %}
{% block content %}
{{ render_form(form, action_url=url_for(".event_edit", id=id), action_text="Apply", title="Edit Event") }}
{% endblock %}
{% extends "admin_index.html" %}
{% block admin_title %}Event{% endblock %}
{% block content %}
<div class="mdl-cell mdl-cell--3-col mdl-grid mdl-grid--no-spacing">
<table class="mdl-data-table mdl-js-table mdl-shadow--2dp mdl-cell mdl-cell--3-col">
<thead>
<tr>
<th class="mdl-data-table__cell--non-numeric">Name</th>
<th class="mdl-data-table__cell--non-numeric">Delete</th>
</tr>
</thead>
<tbody>
{% for event in events %}
<tr>
<td class="mdl-data-table__cell--non-numeric"><a href="{{ url_for(".event_edit", id=event.id) }}">{{ event.name }}</a></td>
<td class="mdl-data-table__cell--non-numeric">
<a href="{{ url_for('.event_delete', id=event.id) }}">
<i class="material-icons">delete</i>
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="rede-separator">
<div class="mdl-cell mdl-cell--1-col">
<a class="mdl-button mdl-button--colored mdl-js-button mdl-button--fab mdl-js-ripple-effect" href="{{ url_for('.event_new') }}">
<i class="material-icons">add</i>
</a>
</div>
</div>
</div>
{% endblock %}
{% extends "layout.html" %}
{% from "macros.html" import render_form %}
{% block title %}Add Event - Administration{% endblock %}
{% block content %}
{{ render_form(form, action_url=url_for(".event_new", id=id), action_text="Add", title="New Event") }}
{% endblock %}
......@@ -12,12 +12,12 @@
</tr>
</thead>
<tbody>
{% for topic in events %}
{% for topic in topics %}
<tr>
<td class="mdl-data-table__cell--non-numeric"><a href="{{ url_for(".topic_edit", id=event.id) }}">{{ event.name }}</a></td>
<td class="mdl-data-table__cell--non-numeric"><a href="{{ url_for(".topic_edit", id=topic.id) }}">{{ topic.name }}</a></td>
<td class="mdl-data-table__cell--non-numeric">{{ topic.mode }}</td>
<td class="mdl-data-table__cell--non-numeric">
<a href="{{ url_for('.topic_delete', id=event.id) }}">
<a href="{{ url_for('.topic_delete', id=topic.id) }}">
<i class="material-icons">delete</i>
</a>
</td>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment