From 2fe5e2e4f6f79b92a9060952c44a37f17d1278aa Mon Sep 17 00:00:00 2001 From: Michael Palimaka Date: Wed, 26 Jul 2017 21:13:27 +1000 Subject: frontend: add basic category page --- frontend/grumpy.py | 12 +++++++++++- frontend/templates/category.html | 22 ++++++++++++++++++++++ frontend/templates/index.html | 4 ++-- 3 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 frontend/templates/category.html 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/', 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 %} + +
+
+

+ {{ category.name }} +

+
+
+ + {% for package in packages -%} + + + + + {%- endfor %} +
{{ package.name }} 
+
+
+ +{% 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 @@ {% for category in categories -%} - + {%- endfor %} @@ -19,4 +19,4 @@ -{% endblock %} \ No newline at end of file +{% endblock %} -- cgit v1.2.3-65-gdbad
{{ category.name }}{{ category.name }} {{ category.description }}