Other dates in view are nice formatted.

master
Justyna Ilczuk 2013-01-28 13:19:14 +01:00
parent b910e2649e
commit 57f76f98ac
4 changed files with 42 additions and 21 deletions

11
note.py
View File

@ -8,8 +8,6 @@ class Note:
self.subject = subject self.subject = subject
self.pages = pages self.pages = pages
class Page: class Page:
def __init__(self, source, tags): def __init__(self, source, tags):
self.source = source self.source = source
@ -26,21 +24,12 @@ def convert_datestring_to_date(datestring):
month = "" month = ""
for m in months.keys(): for m in months.keys():
if m in datestring: if m in datestring:
print "m is " + m
month = months[m] month = months[m]
print month
if datestring[-4:].isdigit(): if datestring[-4:].isdigit():
year = datestring[-4:] year = datestring[-4:]
else: else:
year = "2013" year = "2013"
if month == "": if month == "":
print "unknown: " + datestring
month = "01" month = "01"
date = parse("-".join([year, month, day])) date = parse("-".join([year, month, day]))
print "date is: " + str(date)
print date.datetime.year
print date.datetime.month
print date.datetime.day
return date return date

BIN
note.pyc

Binary file not shown.

View File

@ -67,7 +67,7 @@ def teardown_request(exception):
@app.route('/view') @app.route('/view')
@app.route('/view/<subject>/<datestring>') @app.route('/view/<subject>/<datestring>')
def home(subject= "mechanika", datestring= "14grudnia2012"): def home(subject= "mechanika", datestring= "14grudnia2012"):
other_dates = [date["datestring"] for date in get_possible_dates(subject)] other_dates = prepare_other_dates(subject)
all_dates = prepare_all_dates() all_dates = prepare_all_dates()
all_subjects = [sub["subject"] for sub in get_all_subjects()] all_subjects = [sub["subject"] for sub in get_all_subjects()]
thumbs = get_thumbs(subject, datestring) thumbs = get_thumbs(subject, datestring)
@ -157,11 +157,18 @@ def get_all_subjects():
def prepare_all_dates(): def prepare_all_dates():
"""return all dates in well formated form of nested dictionaries""" """return all dates in well formated form of nested dictionaries"""
all_dates = [date["datestring"] for date in get_all_dates()] datestrings = [date["datestring"] for date in get_all_dates()]
datastrings = [date["datestring"] for date in get_all_dates()] all_dates = [convert_datestring_to_date(date) for date in datestrings]
all_dates = [convert_datestring_to_date(date) for date in datastrings] return sort_dates(datestrings, all_dates)
def prepare_other_dates(subject):
datestrings = [date["datestring"] for date in get_possible_dates(subject)]
dates = [convert_datestring_to_date(date) for date in datestrings]
return sort_dates(datestrings, dates)
def sort_dates(datestrings, dates):
sorted_dates = {} sorted_dates = {}
for date, datestring in zip(all_dates, datastrings): for date, datestring in zip(dates, datestrings):
if not date.datetime.year in sorted_dates: if not date.datetime.year in sorted_dates:
sorted_dates[date.datetime.year] = {} sorted_dates[date.datetime.year] = {}
if not date.datetime.month in sorted_dates[date.datetime.year]: if not date.datetime.month in sorted_dates[date.datetime.year]:

View File

@ -90,14 +90,39 @@ $("document").ready( function(){
<img src="{{ url_for('static', filename='mini/' + thumb.src) }}" alt=""> <img src="{{ url_for('static', filename='mini/' + thumb.src) }}" alt="">
</a> </a>
{% endfor %} {% endfor %}
<ul> <ul class="nav nav-pills">
<h4>Other dates...</h4> <h4>Other dates...</h4>
{% for date in thumbs_info.other_dates %} <ul class="nav nav-pills">
<li><a href="/view/{{thumbs_info.subject}}/{{date }}">{{date }}</a> </li> {%- for key, year in thumbs_info.other_dates.items() recursive %}
{% endfor %} {%- if year %}
<li> <a href="#">{{key}}</a>
<ul class="nav nav-pills">
{% for month, days in year.items() %}
<li>
<a href="#" class=" disabled"> ->{{month}}</a>
<ul class="nav nav-pills">
{% for day in days %}
{%- if day.source == thumbs_info.datestring%}
<li>
<a class="alert-danger" href="/view/{{thumbs_info.subject}}/{{day.source}}">
--> {{day.weekday}}, {{day.day}}
</a>
</li>
{%- else %}
<li><a href="/view/{{thumbs_info.subject}}/{{day.source}}"> --> {{day.weekday}}, {{day.day}}</a></li>
{%-endif%}
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
</li>
{%-endif%}
{%- endfor %}
</ul>
</ul> </ul>
</li> </li>
</ul> </ul>