src: star rating added, links are now with url_for

master
tiyn 2 years ago
parent aeec4ffd73
commit b4609b88c6

@ -12,6 +12,7 @@ The blog is intended to be used to review and critique things.
- [x] Login - [x] Login
- [x] Logout - [x] Logout
- [x] Register - [x] Register
- [ ] User Page
- [ ] Review blog entries - [ ] Review blog entries
- [x] Writing entries - [x] Writing entries
- [ ] Editing entries - [ ] Editing entries

@ -64,10 +64,8 @@ def entry(ident):
def feed(): def feed():
content = con_gen.get_rss_string() content = con_gen.get_rss_string()
rss_xml = render_template("rss.xml", content_string=content, title=TITLE, rss_xml = render_template("rss.xml", content_string=content, title=TITLE,
description=DESCRIPTION, website=WEBSITE) description=DESCRIPTION)
response = make_response(rss_xml) return rss_xml
response.headers["Content-Type"] = "application/rss+xml"
return response
@login.user_loader @login.user_loader

@ -1,15 +1,33 @@
from flask import url_for
import config import config
from database import Database from database import Database
db = Database() db = Database()
def rating_to_star(rating):
"""
Creates a string with stars based on the rating.
Parameters:
rating: rating with minimum of 0 and maximum of 100.
Returns:
string: unicode-formatted star-rating string.
"""
res = u"\u272D"*int(rating/20)
if rating/20 % 1 >= 0.5:
res += u"\u00BD"
return res
def gen_arch_string(): def gen_arch_string():
""" """
Creates and returns a archive string of every file in ENTRY_DIR. Creates and returns a archive string of every file in ENTRY_DIR.
Returns: Returns:
string: html-formatted archive-string string: html-formatted archive-string.
""" """
content_string = "" content_string = ""
last_year = "" last_year = ""
@ -29,11 +47,11 @@ def gen_arch_string():
content_string += "<ul>\n" content_string += "<ul>\n"
last_year = year last_year = year
content_string += "<li>" content_string += "<li>"
content_string += "[<a href=\"" + "/index.html#" + str(ident) + \ content_string += "[<a href=\"" + url_for("index", _anchor=str(ident)) + \
"\">link</a> - <a href=\"/entry/" + \ "\">link</a> - <a href=\"" + url_for("entry", ident=str(ident)) + \
str(ident) + "\">standalone</a>] " "\">standalone</a>] "
content_string += title + " - " + str(rating) + "/100<br>" content_string += title + " " + rating_to_star(rating)
content_string += "</li>\n" content_string += "<br></li>\n"
return content_string return content_string
@ -43,7 +61,7 @@ def gen_index_string():
Create and returns a string including every file in the database as an index. Create and returns a string including every file in the database as an index.
Returns: Returns:
string: html-formatted index string string: html-formatted index string.
""" """
content_string = "" content_string = ""
entries = db.get_entries() entries = db.get_entries()
@ -59,15 +77,14 @@ def gen_index_string():
username = db.get_user_by_id(entry[5])[1] username = db.get_user_by_id(entry[5])[1]
reviewed = entry[6] reviewed = entry[6]
content_string += "<div class=\"entry\">\n" content_string += "<div class=\"entry\">\n"
content_string += "<h1 id=\"" + \ content_string += "<h1 id=\"" + str(ident) + "\">" + title + \
str(ident) + "\">" + title + " (" + year + ") - " + \ " (" + year + ") " + rating_to_star(rating) + "</h1>\n"
str(rating) + "/100</h1>\n" content_string += "[<a href=\"" + url_for("entry", ident=str(ident)) + \
content_string += "[<a href=\"" + "/entry/" + \ "\">" + "standalone" + "</a>]<br>\n"
str(ident) + "\">" + "standalone" + "</a>]<br>\n" content_string += "<small>rated " + str(rating) + " by " + username + \
" on " + str(reviewed) + "</small><br>"
content_string += text content_string += text
content_string += "<br>" content_string += "<br>"
content_string += "<small>" + \
str(reviewed) + " by " + username + "</small>"
content_string += "</div>" content_string += "</div>"
return content_string return content_string
@ -80,7 +97,7 @@ def gen_stand_string(ident):
ident: ident of an entry. ident: ident of an entry.
Returns: Returns:
string: html-formatted string string equivalent to the file string: html-formatted string string equivalent to the file.
""" """
entry = db.get_entry_by_id(ident) entry = db.get_entry_by_id(ident)
content_string = "" content_string = ""
@ -93,16 +110,14 @@ def gen_stand_string(ident):
username = db.get_user_by_id(entry[5])[1] username = db.get_user_by_id(entry[5])[1]
reviewed = entry[6] reviewed = entry[6]
content_string += "<h1>" + title + \ content_string += "<h1>" + title + \
" (" + year + ") - " + str(rating) + "/100 </h1>\n" " (" + year + ") "
content_string += "[" content_string += rating_to_star(rating)
content_string += "<a href=\"" + "/index.html#" + \ content_string += "</h1>\n"
str(ident) + "\">" + "link" + "</a>" content_string += "[<a href=\"" + url_for("index", ident=str(ident)) + \
content_string += "]<br>\n" "\">" + "link" + "</a>]<br>\n"
content_string += "<small>" + \ content_string += "<small>rated " + str(rating) + " by " + \
str(reviewed) + " by " + username + "</small>" username + " on " + str(reviewed) + "</small><br>\n"
content_string += "<br>\n" content_string += text + "<br>\n"
content_string += text
content_string += "<br>"
return content_string return content_string
@ -127,13 +142,12 @@ def get_rss_string():
username = db.get_user_by_id(entry[5])[1] username = db.get_user_by_id(entry[5])[1]
reviewed = entry[6] reviewed = entry[6]
content_string += "<item>\n" content_string += "<item>\n"
content_string += "<title>" + title + \ content_string += "<title>" + title + "(" + year + ") " + \
"(" + year + ") " + str(rating) + "/100 </title>\n" rating_to_star(rating) + "</title>\n"
content_string += "<guid>" + config.WEBSITE + \ content_string += "<guid>" + \
"/index.html#" + str(ident) + "</guid>\n" url_for("index", _anchor=str(ident), _external=True) + \
"</guid>\n"
content_string += "<pubDate>" + reviewed + "</pubDate>\n" content_string += "<pubDate>" + reviewed + "</pubDate>\n"
content_string += "<description>" content_string += "<description>" + text + "</description>\n"
content_string += text
content_string += "</description>\n"
content_string += "</item>\n" content_string += "</item>\n"
return content_string return content_string

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel> <channel>
<title>{{ title }}</title> <title>{{ title }}</title>
<description>{{ description }}</description> <description>{{ description }}</description>
<language>en-us</language> <language>en-us</language>
<link>{{ website }}/feed.xml</link> <link>{{ url_for("feed", _external=True) }}</link>
<atom:link href="/feed.xml" rel="self" type="application/rss+xml" /> <atom:link href="{{ url_for('feed', _external=True) }}" rel="self" type="application/rss+xml" />
{% autoescape off %} {% autoescape off %}
{{ content_string }} {{ content_string }}

Loading…
Cancel
Save