Submenus!

master
Justyna Ilczuk 2013-01-26 20:41:39 +01:00
parent e635ab2c1b
commit b0ed3cc800
26 changed files with 143 additions and 48 deletions

46
note.py Normal file
View File

@ -0,0 +1,46 @@
from delorean import Delorean
from delorean import parse
class Note:
def __init__(self, datestring, author, subject, pages):
self.date = convert_datestring_to_date(datestring)
self.author = author
self.subject = subject
self.pages = pages
class Page:
def __init__(self, source, tags):
self.source = source
self.tags = tags
def convert_datestring_to_date(datestring):
day = ""
if datestring[0:2].isdigit():
day = datestring[0:2]
else:
day = "0" + datestring[0:1]
months = {"stycznia" : "01", "lutego" : "02", "marca" : "03", "kwietnia" : "04", "maja" : "05", "czerwca" : "06",
"lipca" : "07", "sierpnia" : "08", "wrzesnia" : "09", "padziernik": "10", "padziernika" : "10", "listopada" : "11", "grudnia" : "12"}
month = ""
for m in months.keys():
if m in datestring:
print "m is " + m
month = months[m]
print month
if datestring[-4:].isdigit():
year = datestring[-4:]
else:
year = "2013"
if month == "":
print "unknown: " + datestring
month = "01"
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

BIN
note.pyc Normal file

Binary file not shown.

View File

@ -8,11 +8,17 @@ def add_all_notes_in_dir(path):
subjects = os.listdir(path)
if "bootstrap" in subjects:
subjects.remove("bootstrap")
if "mini" in subjects:
subjects.remove("mini")
if ".directory" in subjects:
subjects.remove(".directory")
print "all subjects: " + str(subjects)
for subject in subjects:
for date in os.listdir(path+"/" + subject):
notes = []
for note in os.listdir(path+"/" + subject +"/" + date ):
notes.append({"tags": "none", "name": note})
print subject + " " + date + note
add_note(subject, date, notes)
@ -24,6 +30,7 @@ def add_note(subject, datestring, notes):
for note in notes:
db.execute('insert into pages (note_id, name, tags ) values (?, ?, ?)', [note_id, note["name"], note["tags"]])
connection_db.commit()
print "note added"
def connect_db():
return sqlite3.connect(DATABASE)

BIN
notes.db

Binary file not shown.

View File

@ -10,6 +10,7 @@ import re
from email.mime.text import MIMEText
from subprocess import Popen, PIPE
import smtplib
from note import Note, Page, convert_datestring_to_date
# configuration
DATABASE = 'notes.db'
@ -65,29 +66,66 @@ def teardown_request(exception):
@app.route('/')
@app.route('/view')
@app.route('/view/<subject>/<datestring>')
def home(subject= "chemia", datestring= "12grudnia2012"):
def home(subject= "mechanika", datestring= "14grudnia2012"):
other_dates = [date["datestring"] for date in get_possible_dates(subject)]
all_dates = [date["datestring"] for date in get_all_dates()]
all_dates = prepare_all_dates()
all_subjects = [sub["subject"] for sub in get_all_subjects()]
thumbs = get_thumbs(subject, datestring)
if datestring in other_dates:
other_dates.remove(datestring)
thumbs_info = {"subject": subject, "datestring": datestring, "other_dates": other_dates}
thumbs = get_thumbs(subject, datestring)
print thumbs
thumbs = [dict(href=thumb.href, src=thumb.src) for thumb in thumbs]
main_page_src=thumbs[0]["href"]
print all_dates
return render_template('index.html', thumbs=thumbs, main_page_src=main_page_src,thumbs_info=thumbs_info,
all_dates=all_dates, all_subjects=all_subjects)
def prepare_all_dates():
all_dates = [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 datastrings]
sorted_dates = {}
for date, datestring in zip(all_dates, datastrings):
if not date.datetime.year in sorted_dates:
sorted_dates[date.datetime.year] = {}
if not date.datetime.month in sorted_dates[date.datetime.year]:
sorted_dates[date.datetime.year][date.datetime.month] = []
sorted_dates[date.datetime.year][date.datetime.month].append({"day" : date.datetime.day, "source": datestring,
"weekday": weekday(date.datetime.weekday())})
sorted = sort_number_strings(sorted_dates[date.datetime.year][date.datetime.month])
sorted_dates[date.datetime.year][date.datetime.month] = sorted
print sorted_dates
return sorted_dates
def sort_number_strings(data):
number_data = [int(day["day"]) for day in data]
number_data.sort()
print "sorted date" + str(number_data)
return [{"day": number, "source": data[get_index_for(number, data)]["source"],
"weekday": data[get_index_for(number, data)]["weekday"] } for i, number in enumerate(number_data)]
def weekday(number):
weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
return weekdays[number]
def get_index_for(number, data):
index = 0
for i, day in enumerate(data):
if day["day"] == number:
index = i
return index
@app.route('/subject/<subject>')
def show_subject(subject):
dates = [date["datestring"] for date in get_possible_dates(subject)]
all_dates = [date["datestring"] for date in get_all_dates()]
all_dates = prepare_all_dates()
all_subjects = [sub["subject"] for sub in get_all_subjects()]
return render_template('subject.html', subject=subject, dates=dates, all_dates=all_dates, all_subjects=all_subjects)
@app.route('/date/<datestring>')
def show_date(datestring):
all_dates = [date["datestring"] for date in get_all_dates()]
all_dates = prepare_all_dates()
all_subjects = [sub["subject"] for sub in get_all_subjects()]
notes = get_notes_for_day(datestring)
separated_notes = {}
@ -100,13 +138,13 @@ def show_date(datestring):
@app.route('/search')
def show_search():
all_dates = [date["datestring"] for date in get_all_dates()]
all_dates = prepare_all_dates()
all_subjects = [sub["subject"] for sub in get_all_subjects()]
return render_template('search.html', all_dates=all_dates, all_subjects=all_subjects )
@app.route('/about')
def about():
all_dates = [date["datestring"] for date in get_all_dates()]
all_dates = prepare_all_dates()
all_subjects = [sub["subject"] for sub in get_all_subjects()]
return render_template('about.html', all_dates=all_dates, all_subjects=all_subjects )
@ -130,6 +168,7 @@ def get_thumbs(subject, datestring=""):
else:
query_result = query_db("select pages.* from pages left join notes on notes.id = pages.note_id \
where notes.subject = ? and datestring = ?", [subject, datestring])
print query_result
return [create_thumb(subject, datestring, t["name"], t["tags"]) for t in query_result ]
def get_possible_dates(subject):

Binary file not shown.

Before

Width:  |  Height:  |  Size: 692 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 697 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 393 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 399 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 814 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 779 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 706 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 786 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 719 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 663 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 642 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 621 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 558 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 759 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 638 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

View File

@ -19,6 +19,15 @@ $("document").ready( function(){
$('#display').hide();
$('#display').fadeIn('slow');
$('#display').attr("src", image);
i = $(this).data("number");
console.log(i);
next_page = pages[i];
console.log("next: " + next_page)
if(i >= 2)
{
previous_page = pages[i - 2];
console.log("previous: " + previous_page)
}
return false;
});
@ -34,12 +43,9 @@ $("document").ready( function(){
$('#display').fadeIn('slow');
$('#display').attr("src", next_page);
i++;
i++;
next_page = pages[i];
}
return false;
});
$("#older").click(function() {
@ -52,8 +58,6 @@ $("document").ready( function(){
previous_page = pages[i-3];
next_page = pages[i-1]
i--;
}
return false;
});
@ -80,8 +84,9 @@ $("document").ready( function(){
</li>
<li class="span2">
{% for thumb in thumbs %}
<a href="#" rel="{{ url_for('static', filename=thumb.href) }}" class="thumbnail image">
{% for thumb in thumbs %}
<a href="#" rel="{{ url_for('static', filename=thumb.href) }}" class="thumbnail image"
data-number="{{loop.index}}">
<img src="{{ url_for('static', filename='mini/' + thumb.src) }}" alt="">
</a>
{% endfor %}

View File

@ -47,7 +47,7 @@ $("document").ready( function() {
border-radius: 3px;
display: block;
left: 95%;
margin-top: -30px !important;
margin-top: -50px !important;
moz-border-radius: 3px;
position: absolute;
webkit-border-radius: 3px;
@ -129,43 +129,41 @@ $("document").ready( function() {
<li>n</li>
</ul>
</li>
{% for date in all_dates %}
<li><a href="/date/{{date }}">{{date }}</a> </li>
{% endfor %}
<li>
</li>
</ul>
<ul class="dropdown-menu">
<li class="dropdown submenu">
<a href="#" class="dropdown-toggle" id="levelone" data-toggle="dropdown">Level 1</a>
<ul class="dropdown-menu submenu-hide">
<li class="dropdown submenu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Level 1.1</a>
<ul class="dropdown-menu submenu-show submenu-hide">
<li><a href="#">Level 1.1.1</a></li>
<li><a href="#">Level 1.1.2</a></li>
<li><a href="#">Level 1.1.3</a></li>
<li><a href="#">Level 1.1.4</a></li>
</ul>
</li>
<li class="dropdown submenu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Level 1.2</a>
<ul class="dropdown-menu submenu-hide">
<li><a href="#">Level 1.2.1</a></li>
<li><a href="#">Level 1.2.2</a></li>
</ul>
</li>
<li><a href="#">Level 1.3</a></li>
<li><a href="#">Level 1.4</a></li>
<li><a href="#">Level 1.5</a></li>
</ul>
</li>
{% for date in all_dates %}
<li><a href="/date/{{date }}">{{date }}</a> </li>
{% endfor %}
<li class="nav-header">Year</li>
{%- for key, year in all_dates.items() recursive %}
<li class="dropdown submenu">
<a href="#" class="dropdown-toggle" id="{{key}}" data-toggle="dropdown">{{key}}</a>
{%- if year %}
<ul class="dropdown-menu submenu-hide">
<li class="nav-header">Month</li>
{% for month, days in year.items() %}
<li class="dropdown submenu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">{{month}}</a>
<ul class="dropdown-menu submenu-show submenu-hide">
<li class="nav-header">Day</li>
{% for day in days %}
<li><a href="/date/{{day.source}}">{{day.weekday}}, {{day.day}}</a></li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
{%-endif%}
</li>
{%- endfor %}
</ul>
</div>
</ul>