diff options
-rw-r--r-- | frontend/grumpy.py | 12 | ||||
-rw-r--r-- | frontend/templates/category.html | 22 | ||||
-rw-r--r-- | frontend/templates/index.html | 4 |
3 files changed, 35 insertions, 3 deletions
diff --git a/frontend/grumpy.py b/frontend/grumpy.py index 62ce9b1..8d106a6 100644 --- a/frontend/grumpy.py +++ b/frontend/grumpy.py @@ -1,4 +1,4 @@ -from flask import current_app, redirect, render_template, request, url_for +from flask import abort, current_app, redirect, render_template, request, url_for from flask_classy import FlaskView, route from sqlalchemy.sql import collate from flask_wtf import FlaskForm @@ -22,6 +22,16 @@ class GrumpyView(FlaskView): categories = models.Category.query.all() return render_template("index.html", categories=categories) + @route('/category/<categoryname>', methods=['GET']) + def category(self, categoryname): + category = models.Category.query.filter_by(name=categoryname).first() + + if category: + packages = models.Package.query.filter_by(category=category) + return render_template('category.html', category=category, packages=packages) + else: + abort(404) + class SetupView(FlaskView): @route('/', methods=['GET', 'POST']) # FIXME: Can we enable POST without giving a rule override from the automatic, or handle this some other better way with wtforms setup? def index(self): diff --git a/frontend/templates/category.html b/frontend/templates/category.html new file mode 100644 index 0000000..9c86085 --- /dev/null +++ b/frontend/templates/category.html @@ -0,0 +1,22 @@ +{% extends "base.html" %} +{% block content %} + +<div class="panel panel-default"> + <div class="panel-heading"> + <h3 class="panel-title"> + <span class="fa fa-fw fa-cubes"></span>{{ category.name }} + </h3> + </div> + <div class="table-responsive"> + <table class="table table-striped"> + {% for package in packages -%} + <tr> + <td class="text-nowrap">{{ package.name }}</td> + <td> </td> + </tr> + {%- endfor %} + </table> + </div> +</div> + +{% endblock %} diff --git a/frontend/templates/index.html b/frontend/templates/index.html index 782f407..fefa0c8 100644 --- a/frontend/templates/index.html +++ b/frontend/templates/index.html @@ -11,7 +11,7 @@ <table class="table table-striped"> {% for category in categories -%} <tr> - <td class="text-nowrap">{{ category.name }}</td> + <td class="text-nowrap"><a href="category/{{ category.name }}">{{ category.name }}</a></td> <td>{{ category.description }}</td> </tr> {%- endfor %} @@ -19,4 +19,4 @@ </div> </div> -{% endblock %}
\ No newline at end of file +{% endblock %} |