|
|
|
@ -1,5 +1,3 @@
|
|
|
|
|
from flask import url_for
|
|
|
|
|
|
|
|
|
|
from database import Database
|
|
|
|
|
|
|
|
|
|
db = Database()
|
|
|
|
@ -19,180 +17,3 @@ def rating_to_star(rating):
|
|
|
|
|
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.
|
|
|
|
|
"""
|
|
|
|
|
content_string = ""
|
|
|
|
|
last_year = ""
|
|
|
|
|
entries = db.get_entries()
|
|
|
|
|
if entries is None:
|
|
|
|
|
return ""
|
|
|
|
|
entries.sort(key=lambda y: y.item.name)
|
|
|
|
|
entries.reverse()
|
|
|
|
|
entries.sort(key=lambda y: y.item.date)
|
|
|
|
|
entries.reverse()
|
|
|
|
|
for entry in entries:
|
|
|
|
|
ident = entry.id
|
|
|
|
|
title = entry.item.name
|
|
|
|
|
print("title", title)
|
|
|
|
|
year = entry.item.date
|
|
|
|
|
rating = entry.rating
|
|
|
|
|
username = entry.user.name
|
|
|
|
|
if year != last_year:
|
|
|
|
|
if last_year != "":
|
|
|
|
|
content_string += "</ul>\n"
|
|
|
|
|
content_string += "<h2>" + year + "</h2>\n"
|
|
|
|
|
content_string += "<ul>\n"
|
|
|
|
|
last_year = year
|
|
|
|
|
content_string += "<li>"
|
|
|
|
|
content_string += title + "<a href=\"" + \
|
|
|
|
|
url_for("entry", ident=str(ident)) + "\"> " + \
|
|
|
|
|
rating_to_star(rating) + " by " + username
|
|
|
|
|
content_string += "</a><br></li>\n"
|
|
|
|
|
|
|
|
|
|
return content_string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def gen_user_string(name):
|
|
|
|
|
"""
|
|
|
|
|
Creates and returns a archive string of every file in ENTRY_DIR.
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
string: html-formatted archive-string.
|
|
|
|
|
"""
|
|
|
|
|
content_string = ""
|
|
|
|
|
last_year = ""
|
|
|
|
|
entries = db.get_entries_by_user(name)
|
|
|
|
|
if entries is None:
|
|
|
|
|
return ""
|
|
|
|
|
entries.sort(key=lambda y: y.item.name)
|
|
|
|
|
entries.reverse()
|
|
|
|
|
entries.sort(key=lambda y: y.item.date)
|
|
|
|
|
entries.reverse()
|
|
|
|
|
for entry in entries:
|
|
|
|
|
ident = entry.id
|
|
|
|
|
title = entry.item.name
|
|
|
|
|
year = entry.item.date
|
|
|
|
|
rating = entry.rating
|
|
|
|
|
username = entry.user.name
|
|
|
|
|
if year != last_year:
|
|
|
|
|
if last_year != "":
|
|
|
|
|
content_string += "</ul>\n"
|
|
|
|
|
content_string += "<h2>" + year + "</h2>\n"
|
|
|
|
|
content_string += "<ul>\n"
|
|
|
|
|
last_year = year
|
|
|
|
|
content_string += "<li>"
|
|
|
|
|
content_string += title + "<a href=\"" + \
|
|
|
|
|
url_for("entry", ident=str(ident)) + "\"> " + \
|
|
|
|
|
rating_to_star(rating)
|
|
|
|
|
content_string += "</a><br></li>\n"
|
|
|
|
|
|
|
|
|
|
return content_string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def gen_index_string():
|
|
|
|
|
"""
|
|
|
|
|
Create and returns a string including every file in the database as an
|
|
|
|
|
index.
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
string: html-formatted index string.
|
|
|
|
|
"""
|
|
|
|
|
content_string = ""
|
|
|
|
|
entries = db.get_entries()
|
|
|
|
|
if entries is None:
|
|
|
|
|
return ""
|
|
|
|
|
entries.reverse()
|
|
|
|
|
for entry in entries:
|
|
|
|
|
ident = entry.id
|
|
|
|
|
title = entry.item.name
|
|
|
|
|
year = entry.item.date
|
|
|
|
|
text = entry.text
|
|
|
|
|
rating = entry.rating
|
|
|
|
|
username = entry.user.name
|
|
|
|
|
reviewed = entry.reviewed
|
|
|
|
|
content_string += "<div class=\"entry\">\n"
|
|
|
|
|
content_string += "<h1 id=\"" + str(ident) + "\"><a href=\"" + \
|
|
|
|
|
url_for("entry", ident=str(ident)) + "\">" + title + \
|
|
|
|
|
" (" + year + ") " + rating_to_star(rating) + "</a></h1>\n"
|
|
|
|
|
content_string += "<small>rated " + str(rating) + \
|
|
|
|
|
"/100 by <a href=\"" + url_for("user", name=username) + "\">" \
|
|
|
|
|
+ username + "</a> on " + str(reviewed) + "</small><br>"
|
|
|
|
|
content_string += text
|
|
|
|
|
content_string += "<br>"
|
|
|
|
|
content_string += "</div>"
|
|
|
|
|
return content_string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def gen_stand_string(ident):
|
|
|
|
|
"""
|
|
|
|
|
Creates a html-string for an entry.
|
|
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
|
ident: ident of an entry.
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
string: html-formatted string string equivalent to the file.
|
|
|
|
|
"""
|
|
|
|
|
entry = db.get_entry_by_id(ident)
|
|
|
|
|
content_string = ""
|
|
|
|
|
if entry is not None:
|
|
|
|
|
ident = entry.id
|
|
|
|
|
title = entry.item.name
|
|
|
|
|
year = entry.item.date
|
|
|
|
|
text = entry.text
|
|
|
|
|
rating = entry.rating
|
|
|
|
|
username = entry.user.name
|
|
|
|
|
reviewed = entry.reviewed
|
|
|
|
|
content_string += "<h1>" + title + \
|
|
|
|
|
" (" + year + ") "
|
|
|
|
|
content_string += rating_to_star(rating)
|
|
|
|
|
content_string += "</h1>\n"
|
|
|
|
|
content_string += "<small>rated " + str(rating) + \
|
|
|
|
|
"/100 by <a href=\"" + url_for("user", name=username) + "\">" + \
|
|
|
|
|
username + "</a> on <a href=\"" + \
|
|
|
|
|
url_for("index", _anchor=str(ident)) + "\">" + str(reviewed) + \
|
|
|
|
|
"</a></small><br>\n"
|
|
|
|
|
content_string += "<small>[<a href=\"" + \
|
|
|
|
|
url_for("delete_entry", ident=ident) + \
|
|
|
|
|
"\">delete entry</a>]</small>"
|
|
|
|
|
content_string += text + "<br>\n"
|
|
|
|
|
return content_string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_rss_string():
|
|
|
|
|
"""
|
|
|
|
|
Create a rss-string of the blog and return it.
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
string: rss-string of everything that is in the ENTRY_DIR.
|
|
|
|
|
"""
|
|
|
|
|
content_string = ""
|
|
|
|
|
entries = db.get_entries()
|
|
|
|
|
if entries is None:
|
|
|
|
|
return ""
|
|
|
|
|
entries.reverse()
|
|
|
|
|
for entry in entries:
|
|
|
|
|
ident = entry.id
|
|
|
|
|
title = entry.item.name
|
|
|
|
|
year = entry.item.date
|
|
|
|
|
text = entry.text
|
|
|
|
|
rating = entry.rating
|
|
|
|
|
username = entry.user.name
|
|
|
|
|
reviewed = entry.reviewed
|
|
|
|
|
content_string += "<item>\n"
|
|
|
|
|
content_string += "<title>" + title + "(" + year + ") " + \
|
|
|
|
|
rating_to_star(rating) + " by " + username + "</title>\n"
|
|
|
|
|
content_string += "<guid>" + \
|
|
|
|
|
url_for("index", _anchor=str(ident), _external=True) + \
|
|
|
|
|
"</guid>\n"
|
|
|
|
|
content_string += "<pubDate>" + reviewed + "</pubDate>\n"
|
|
|
|
|
content_string += "<description>" + text + "</description>\n"
|
|
|
|
|
content_string += "</item>\n"
|
|
|
|
|
return content_string
|
|
|
|
|