Commit 9399cc95 authored by Robin Sonnabend's avatar Robin Sonnabend
Browse files

Show protocols (although right now there aren't any)

parent 22493f04
...@@ -29,7 +29,6 @@ class LdapManager: ...@@ -29,7 +29,6 @@ class LdapManager:
if not self.authenticate(username, password): if not self.authenticate(username, password):
return None return None
groups = list(map(lambda g: g.decode("utf-8"), self.groups(username))) groups = list(map(lambda g: g.decode("utf-8"), self.groups(username)))
print(groups)
return User(username, groups) return User(username, groups)
def authenticate(self, username, password): def authenticate(self, username, password):
......
...@@ -12,7 +12,9 @@ from functools import wraps ...@@ -12,7 +12,9 @@ from functools import wraps
import config import config
from shared import db, date_filter, datetime_filter, ldap_manager, security_manager from shared import db, date_filter, datetime_filter, ldap_manager, security_manager
from utils import is_past, mail_manager, url_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.forms import LoginForm
from views.tables import ProtocolsTable
app = Flask(__name__) app = Flask(__name__)
app.config.from_object(config) app.config.from_object(config)
...@@ -65,10 +67,24 @@ app.jinja_env.globals.update(current_user=current_user) ...@@ -65,10 +67,24 @@ app.jinja_env.globals.update(current_user=current_user)
# blueprints here # blueprints here
@app.route("/") @app.route("/")
@login_required #@login_required
def index(): def index():
return render_template("index.html") 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"]) @app.route("/login", methods=["GET", "POST"])
def login(): def login():
if "auth" in session: if "auth" in session:
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
<div id="navbar" class="navbar-collapse collapse"> <div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<li><a href="{{url_for("index")}}">Zuhause</a></li> <li><a href="{{url_for("index")}}">Zuhause</a></li>
<li><a href="{{url_for("list_protocols")}}">Protokolle</a></li>
{# todo: add more links #} {# todo: add more links #}
</ul> </ul>
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
......
...@@ -3,5 +3,7 @@ ...@@ -3,5 +3,7 @@
{% block title %}Login{% endblock %} {% block title %}Login{% endblock %}
{% block content %} {% block content %}
<div class="container">
{{render_form(form)}} {{render_form(form)}}
</div>
{% endblock %} {% endblock %}
...@@ -107,3 +107,24 @@ to not render a label for the CRSFTokenField --> ...@@ -107,3 +107,24 @@ to not render a label for the CRSFTokenField -->
<button type="submit" class="{{ btn_class }}">{{ action_text }} </button> <button type="submit" class="{{ btn_class }}">{{ action_text }} </button>
</form> </form>
{%- endmacro %} {%- 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 %}
{% extends "layout.html" %}
{% from "macros.html" import render_table %}
{% block title %}Protokolle{% endblock %}
{% block content %}
<div class="container">
{{render_table(protocols_table)}}
</div>
{% endblock %}
# 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)
]
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