aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Palimaka <kensington@gentoo.org>2017-07-26 21:13:27 +1000
committerMichael Palimaka <kensington@gentoo.org>2017-07-26 21:15:44 +1000
commit2fe5e2e4f6f79b92a9060952c44a37f17d1278aa (patch)
tree354964642c4b450b569b8e1d29530fd5c65711d2
parentAdd 404 error handling. (diff)
downloadgrumpy-2fe5e2e4f6f79b92a9060952c44a37f17d1278aa.tar.gz
grumpy-2fe5e2e4f6f79b92a9060952c44a37f17d1278aa.tar.bz2
grumpy-2fe5e2e4f6f79b92a9060952c44a37f17d1278aa.zip
frontend: add basic category page
-rw-r--r--frontend/grumpy.py12
-rw-r--r--frontend/templates/category.html22
-rw-r--r--frontend/templates/index.html4
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>&nbsp;</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 %}