Skip to content

Commit e2da45d

Browse files
committed
templating
1 parent 257d098 commit e2da45d

9 files changed

Lines changed: 76 additions & 90 deletions

File tree

‎api/__init__.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from flask import Flask, jsonify
1+
from flask import Flask, jsonify, render_template
22
from flask_cors import CORS
33
from .modules import tweets, log
44

@@ -10,4 +10,8 @@ def create_app(test_config=None):
1010
app.register_blueprint(tweets.bp)
1111
app.register_blueprint(log.bp)
1212

13+
@app.route('/')
14+
def base():
15+
return render_template('index.html.j2')
16+
1317
return app

‎api/modules/log.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ def logfile(file, format = 'plain'):
1414
with open(os.path.join(base_folder, 'log/{}.log'.format(file))) as f:
1515
lines = reversed(f.readlines())
1616
if format == 'html':
17-
return render_template('index.log.html.j2', lines = lines, file = file, files = files)
17+
return render_template('log.html.j2', lines = lines, file = file, files = files)
1818
else:
1919
return Response(''.join(lines), mimetype='text/plain')

‎api/modules/tweets.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def add(id):
4646
@bp.route('/all')
4747
def all():
4848
tweets = readTweetsFromFolder()
49-
return render_template('index.all.html.j2', tweets = [Tweet(i) for i in tweets])
49+
return render_template('all.html.j2', tweets = [Tweet(i) for i in tweets])
5050

5151
@bp.route('/stories')
5252
def info():
@@ -58,6 +58,4 @@ def info():
5858
if storyId not in stories:
5959
stories[storyId] = []
6060
stories[storyId].append(Tweet.loadFromFile(id))
61-
else:
62-
stories[id] = [Tweet.loadFromFile(id)]
63-
return render_template('index.html.j2', stories = stories)
61+
return render_template('stories.html.j2', stories = stories)

‎api/templates/all.html.j2‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{% extends "index.html.j2" %}
2+
{% block title %}All Tweets{% endblock %}
3+
{% block content %}
4+
<h1>Tweets</h1>
5+
<ul>
6+
{% for tweet in tweets %}
7+
<li>
8+
{% include 'tweet.html.j2' %}
9+
<br/>
10+
</li>
11+
{% endfor %}
12+
</ul>
13+
{% endblock %}

‎api/templates/index.all.html.j2‎

Lines changed: 0 additions & 34 deletions
This file was deleted.

‎api/templates/index.html.j2‎

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,20 @@
11
<!DOCTYPE html>
22
<html lang="en">
3-
<head>
4-
<meta charset="utf-8">
5-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
6-
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
7-
<title>Decarbnow Backend</title>
8-
</head>
9-
<body>
10-
<div class="container">
11-
<h1>Stories</h1>
12-
<ul>
13-
{% for storyId, tweets in stories.items() %}
14-
<li>
15-
<strong>{{ storyId }}, {{ tweets|count }} Entries</strong>
16-
<ul>
17-
{% for t in tweets %}
18-
<li>
19-
<div>
20-
<strong>{{ t.getId() }}</strong>, {{ t.getUserName() }}, {{ t.getTime() }} (<a href="/tweets/{{ t.getId() }}" target="_blank">JSON</a>, <a href="{{ t.getUrl() }}" target="_blank">Twitter</a>)<br/>
21-
<strong>Hastags:</strong> {{ ', '.join(t.getHashtags()) }}<br/>
22-
{{ t.getText() }}<br/>
23-
<strong>Links:</strong>
24-
<ul>
25-
{% for l in t.getLinks() %}
26-
<li>
27-
<a href="{{ l }}" target="_blank">{{ l }}</a>
28-
</li>
29-
{% endfor %}
30-
</ul>
31-
</div>
32-
<br/>
33-
</li>
34-
{% endfor %}
35-
</ul>
36-
</li>
37-
{% endfor %}
38-
</ul>
39-
</div>
40-
</body>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
7+
<title>{% block title %}{% endblock %} - Decarbnow Backend</title>
8+
</head>
9+
<body style="font-family: monospace">
10+
<div id="header">
11+
<a href='/log/listener/html'>log</a>
12+
<a href='/tweets/all'>tweets all</a>
13+
<a href='/tweets/stories'>tweets stories</a>
14+
<a href='/tweets/forest' target="_blank">tweets forest</a>
15+
<a href='/tweets/forest/create' target="_blank">renew api json</a>
16+
</div>
17+
<br/>
18+
<div id="content">{% block content %}{% endblock %}</div>
19+
</body>
4120
</html>
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
<!DOCTYPE html>
2-
<html lang="en">
3-
<head>
4-
<meta charset="utf-8">
5-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
6-
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
7-
<title>Decarbnow Backend, Log {{ file }}</title>
8-
</head>
9-
<body>
10-
<div class="container" style="font-family: monospace">
1+
{% extends "index.html.j2" %}
2+
{% block title %}Log {{ file }}{% endblock %}
3+
{% block content %}
4+
<div>
115
{% for f in files %}
126
<a href='/log/{{f}}/html'>{{ f }}</a>
137
{% endfor %}
@@ -18,5 +12,4 @@
1812
{% endfor %}
1913
</div>
2014
</div>
21-
</body>
22-
</html>
15+
{% endblock %}

‎api/templates/stories.html.j2‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{% extends "index.html.j2" %}
2+
{% block title %}Stories{% endblock %}
3+
{% block content %}
4+
<h1>Stories</h1>
5+
<ul>
6+
{% for storyId, tweets in stories.items() %}
7+
<li>
8+
<strong>{{ storyId }}, {{ tweets|count }} Entries</strong>
9+
<ul>
10+
{% for tweet in tweets %}
11+
<li>
12+
{% include 'tweet.html.j2' %}
13+
<br/>
14+
</li>
15+
{% endfor %}
16+
</ul>
17+
</li>
18+
{% endfor %}
19+
</ul>
20+
{% endblock %}

‎api/templates/tweet.html.j2‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<div>
2+
<strong>{{ tweet.getId() }}</strong>, {{ tweet.getUserName() }}, {{ tweet.getTime() }} (<a href="/tweets/{{ tweet.getId() }}" target="_blank">JSON</a>, <a href="{{ tweet.getUrl() }}" target="_blank">Twitter</a>)<br/>
3+
<strong>Hastags:</strong> {{ ', '.join(tweet.getHashtags()) }}<br/>
4+
<strong>Links:</strong> {{ tweet.hasLinkTo() }}
5+
<ul>
6+
{% for l in tweet.getLinks() %}
7+
<li>
8+
<a href="{{ l }}" target="_blank">{{ l }}</a>
9+
</li>
10+
{% endfor %}
11+
</ul><br/>
12+
{{ tweet.getText() }}<br/>
13+
</div>

0 commit comments

Comments
 (0)