From 9399cc9577d46ca81ee1a3d65f05891fedc0400e Mon Sep 17 00:00:00 2001 From: Robin Sonnabend <robin@fsmpi.rwth-aachen.de> Date: Wed, 22 Feb 2017 06:30:00 +0100 Subject: [PATCH] Show protocols (although right now there aren't any) --- auth.py | 1 - server.py | 18 ++++++++++- templates/layout.html | 1 + templates/login.html | 2 ++ templates/macros.html | 21 ++++++++++++ templates/protocol-list.html | 9 ++++++ views/tables.py | 63 ++++++++++++++++++++++++++++++++++++ 7 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 templates/protocol-list.html create mode 100644 views/tables.py diff --git a/auth.py b/auth.py index 1faf872..23d5a15 100644 --- a/auth.py +++ b/auth.py @@ -29,7 +29,6 @@ class LdapManager: if not self.authenticate(username, password): return None groups = list(map(lambda g: g.decode("utf-8"), self.groups(username))) - print(groups) return User(username, groups) def authenticate(self, username, password): diff --git a/server.py b/server.py index c538520..b2c6849 100755 --- a/server.py +++ b/server.py @@ -12,7 +12,9 @@ from functools import wraps import config from shared import db, date_filter, datetime_filter, ldap_manager, security_manager from utils import is_past, mail_manager, url_manager +from models.database import ProtocolType, Protocol, DefaultTOP, TOP, Document, Todo, Decision, MeetingReminder, Error from views.forms import LoginForm +from views.tables import ProtocolsTable app = Flask(__name__) app.config.from_object(config) @@ -65,10 +67,24 @@ app.jinja_env.globals.update(current_user=current_user) # blueprints here @app.route("/") -@login_required +#@login_required def index(): return render_template("index.html") +@app.route("/protocol/list") +def list_protocols(): + is_logged_in = check_login() + user = current_user() + protocols = [ + protocol for protocol in Protocol.query.all() + if (not is_logged_in and protocol.protocoltype.is_public) + or (is_logged_in and ( + protocol.protocoltype.public_group in user.groups + or protocol.protocoltype.private_group in user.groups))] + protocols_table = ProtocolsTable(protocols) + return render_template("protocol-list.html", protocols=protocols, protocols_table=protocols_table) + + @app.route("/login", methods=["GET", "POST"]) def login(): if "auth" in session: diff --git a/templates/layout.html b/templates/layout.html index 95c63bd..31b61d5 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -27,6 +27,7 @@ <div id="navbar" class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li><a href="{{url_for("index")}}">Zuhause</a></li> + <li><a href="{{url_for("list_protocols")}}">Protokolle</a></li> {# todo: add more links #} </ul> <ul class="nav navbar-nav navbar-right"> diff --git a/templates/login.html b/templates/login.html index fa86d85..3948f97 100644 --- a/templates/login.html +++ b/templates/login.html @@ -3,5 +3,7 @@ {% block title %}Login{% endblock %} {% block content %} +<div class="container"> {{render_form(form)}} +</div> {% endblock %} diff --git a/templates/macros.html b/templates/macros.html index bc416ca..8ef7e6e 100644 --- a/templates/macros.html +++ b/templates/macros.html @@ -107,3 +107,24 @@ to not render a label for the CRSFTokenField --> <button type="submit" class="{{ btn_class }}">{{ action_text }} </button> </form> {%- endmacro %} + +{% macro render_table(table) -%} + <table class="table table-striped"> + <thead> + <tr> + {% for header in table.headers() %} + <th>{{header}}</th> + {% endfor %} + </tr> + </thead> + <tbody> + {% for row in table.rows() %} + <tr> + {% for entry in row %} + <td>{{entry}}</td> + {% endfor %} + </tr> + {% endfor %} + </tbody> + </table> +{%- endmacro %} diff --git a/templates/protocol-list.html b/templates/protocol-list.html new file mode 100644 index 0000000..43d3cdb --- /dev/null +++ b/templates/protocol-list.html @@ -0,0 +1,9 @@ +{% extends "layout.html" %} +{% from "macros.html" import render_table %} +{% block title %}Protokolle{% endblock %} + +{% block content %} +<div class="container"> + {{render_table(protocols_table)}} +</div> +{% endblock %} diff --git a/views/tables.py b/views/tables.py new file mode 100644 index 0000000..bb3a44d --- /dev/null +++ b/views/tables.py @@ -0,0 +1,63 @@ +# coding: utf-8 +from flask import Markup, url_for, request +from models.database import Protocol, ProtocolType, DefaultTOP, TOP, Todo, Decision +from shared import date_filter + +class Table: + def __init__(self, title, values, newlink=None): + self.title = title + self.values = values + self.newlink = newlink + self.newtext = "New" + + def rows(self): + return [row for row in [self.row(value) for value in self.values] if row is not None] + + @staticmethod + def link(target, text, confirm=None): + confirmation = "" + if confirm: + confirmation = " onclick=\"return confirm('{}');\"".format(confirm) + return Markup("<a href=\"{}\"{}>{}</a>".format(target, confirmation, text)) + + @staticmethod + def mail(target): + return Markup("<a href=\"mailto:{}\">{}</a>".format(target, target)) + + @staticmethod + def bool(value): + return "Yes" if value else "No" + + @staticmethod + def concat(values): + return ", ".join(values) + #if len(values) <= 1: + # return "".join(values) + #else: + # return "{} and {}".format(", ".join(values[:-1]), values[-1]) + + +class SingleValueTable: + def __init__(self, title, value, newlink=None): + self.title = title + self.value = value + self.newlink = newlink if newlink else None + self.newtext = "Edit" + + def rows(self): + return [self.row()] + +class ProtocolsTable(Table): + def __init__(self, protocols): + super().__init__("Protokolle", protocols, newlink=None) + + def headers(self): + return ["ID", "Sitzung", "Datum"] + + def row(self, protocol): + return [ + Table.link(url_for("protocol_view", protocol_id=protocol.id), str(protocol.id)), + protocol.protocoltype.name, + date_filter(protocol.data) + ] + -- GitLab