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] Logout
- [x] Register
- [ ] User Page
- [ ] Review blog entries
- [x] Writing entries
- [ ] Editing entries

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

@ -1,15 +1,33 @@
from flask import url_for
import config
from database import 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():
"""
Creates and returns a archive string of every file in ENTRY_DIR.
Returns:
string: html-formatted archive-string
string: html-formatted archive-string.
"""
content_string = ""
last_year = ""
@ -29,11 +47,11 @@ def gen_arch_string():
content_string += "<ul>\n"
last_year = year
content_string += "<li>"
content_string += "[<a href=\"" + "/index.html#" + str(ident) + \
"\">link</a> - <a href=\"/entry/" + \
str(ident) + "\">standalone</a>] "
content_string += title + " - " + str(rating) + "/100<br>"
content_string += "</li>\n"
content_string += "[<a href=\"" + url_for("index", _anchor=str(ident)) + \
"\">link</a> - <a href=\"" + url_for("entry", ident=str(ident)) + \
"\">standalone</a>] "
content_string += title + " " + rating_to_star(rating)
content_string += "<br></li>\n"
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.
Returns:
string: html-formatted index string
string: html-formatted index string.
"""
content_string = ""
entries = db.get_entries()
@ -59,15 +77,14 @@ def gen_index_string():
username = db.get_user_by_id(entry[5])[1]
reviewed = entry[6]
content_string += "<div class=\"entry\">\n"
content_string += "<h1 id=\"" + \
str(ident) + "\">" + title + " (" + year + ") - " + \
str(rating) + "/100</h1>\n"
content_string += "[<a href=\"" + "/entry/" + \
str(ident) + "\">" + "standalone" + "</a>]<br>\n"
content_string += "<h1 id=\"" + str(ident) + "\">" + title + \
" (" + year + ") " + rating_to_star(rating) + "</h1>\n"
content_string += "[<a href=\"" + url_for("entry", ident=str(ident)) + \
"\">" + "standalone" + "</a>]<br>\n"
content_string += "<small>rated " + str(rating) + " by " + username + \
" on " + str(reviewed) + "</small><br>"
content_string += text
content_string += "<br>"
content_string += "<small>" + \
str(reviewed) + " by " + username + "</small>"
content_string += "</div>"
return content_string
@ -80,7 +97,7 @@ def gen_stand_string(ident):
ident: ident of an entry.
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)
content_string = ""
@ -93,16 +110,14 @@ def gen_stand_string(ident):
username = db.get_user_by_id(entry[5])[1]
reviewed = entry[6]
content_string += "<h1>" + title + \
" (" + year + ") - " + str(rating) + "/100 </h1>\n"
content_string += "["
content_string += "<a href=\"" + "/index.html#" + \
str(ident) + "\">" + "link" + "</a>"
content_string += "]<br>\n"
content_string += "<small>" + \
str(reviewed) + " by " + username + "</small>"
content_string += "<br>\n"
content_string += text
content_string += "<br>"
" (" + year + ") "
content_string += rating_to_star(rating)
content_string += "</h1>\n"
content_string += "[<a href=\"" + url_for("index", ident=str(ident)) + \
"\">" + "link" + "</a>]<br>\n"
content_string += "<small>rated " + str(rating) + " by " + \
username + " on " + str(reviewed) + "</small><br>\n"
content_string += text + "<br>\n"
return content_string
@ -127,13 +142,12 @@ def get_rss_string():
username = db.get_user_by_id(entry[5])[1]
reviewed = entry[6]
content_string += "<item>\n"
content_string += "<title>" + title + \
"(" + year + ") " + str(rating) + "/100 </title>\n"
content_string += "<guid>" + config.WEBSITE + \
"/index.html#" + str(ident) + "</guid>\n"
content_string += "<title>" + title + "(" + year + ") " + \
rating_to_star(rating) + "</title>\n"
content_string += "<guid>" + \
url_for("index", _anchor=str(ident), _external=True) + \
"</guid>\n"
content_string += "<pubDate>" + reviewed + "</pubDate>\n"
content_string += "<description>"
content_string += text
content_string += "</description>\n"
content_string += "<description>" + text + "</description>\n"
content_string += "</item>\n"
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">
<channel>
<title>{{ title }}</title>
<description>{{ description }}</description>
<language>en-us</language>
<link>{{ website }}/feed.xml</link>
<atom:link href="/feed.xml" rel="self" type="application/rss+xml" />
<link>{{ url_for("feed", _external=True) }}</link>
<atom:link href="{{ url_for('feed', _external=True) }}" rel="self" type="application/rss+xml" />
{% autoescape off %}
{{ content_string }}

Loading…
Cancel
Save