Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""LICENSE
2Copyright 2018 Hermann Krumrey <hermann@krumreyh.com>
4This file is part of progstats.
6progstats is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
11progstats is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
16You should have received a copy of the GNU General Public License
17along with progstats. If not, see <http://www.gnu.org/licenses/>.
18LICENSE"""
20import pkg_resources
21from flask import Flask, render_template, abort, request
22from progstats.entities import get_topics, get_projects
24app = Flask(__name__)
27@app.route("/")
28def index():
29 """
30 The Home page of the website. Will display the /project/ page.
31 :return: The /projects/ page
32 """
33 version = pkg_resources.get_distribution("progstats").version
34 return render_template("home.html", version=version)
37@app.route("/projects/")
38@app.route("/projects/<project_name>")
39def projects(project_name: str = None):
40 """
41 Lists all projects or displays details about a single project
42 :param project_name: The name of the project to display.
43 :return: An HTML document containing a list of projects
44 or the details of the selected project
45 """
46 all_projects = get_projects()
47 if project_name is None:
48 return render_template(
49 "lister.html", lister_type="Projects", items=all_projects
50 )
52 else:
53 filtered = list(filter(lambda x: x.name == project_name, all_projects))
54 if len(filtered) != 1:
55 abort(404)
56 else:
57 return render_template(
58 "project.html", host=request.host_url, project=filtered[0]
59 )
62@app.route("/topics/")
63@app.route("/topics/<topic_name>")
64def topics(topic_name: str = None):
65 """
66 Displays a list of all available topics or a list of projects that
67 offer info on a specified topic
68 :param topic_name: The name of the topic to display
69 :return: The page containing all available topics or the projects
70 applicable to a topic
71 """
72 all_topics = get_topics()
73 if topic_name is None:
74 return render_template(
75 "lister.html", lister_type="Topics", items=all_topics
76 )
78 else:
79 filtered = list(filter(lambda x: x.name == topic_name, all_topics))
81 if len(filtered) != 1:
82 abort(404)
83 else:
84 topic = filtered[0]
85 topic_projects = list(filter(
86 lambda x: topic in x.topics,
87 get_projects()
88 ))
89 print(topic_projects)
90 return render_template(
91 "topic.html",
92 topic=topic,
93 projects=topic_projects,
94 host=request.host_url
95 )