summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustyna Ilczuk <justyna.ilczuk@gmail.com>2013-01-27 15:23:52 +0100
committerJustyna Ilczuk <justyna.ilczuk@gmail.com>2013-01-27 15:23:52 +0100
commitb910e2649e87b9b52106a2c2c9fa7277f306b34c (patch)
tree0a4119944603c9ff2c68d707cba2f476d6047ef4
parentb0ed3cc8009f3459dc9a342c89c92f9f67c93b50 (diff)
downloadnooz-b910e2649e87b9b52106a2c2c9fa7277f306b34c.tar.gz
nooz-b910e2649e87b9b52106a2c2c9fa7277f306b34c.tar.bz2
nooz-b910e2649e87b9b52106a2c2c9fa7277f306b34c.zip
Some refactoring and documentation (docstrings).
-rw-r--r--notes.py75
-rw-r--r--templates/about.html8
-rw-r--r--templates/index.html4
-rw-r--r--templates/layout.html92
-rw-r--r--templates/search.html2
5 files changed, 87 insertions, 94 deletions
diff --git a/notes.py b/notes.py
index 8aeb179..82f6ef2 100644
--- a/notes.py
+++ b/notes.py
@@ -75,46 +75,11 @@ def home(subject= "mechanika", datestring= "14grudnia2012"):
other_dates.remove(datestring)
thumbs_info = {"subject": subject, "datestring": datestring, "other_dates": other_dates}
- 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):
@@ -168,7 +133,6 @@ 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):
@@ -176,20 +140,57 @@ def get_possible_dates(subject):
return dates
def get_notes_for_day(datestring):
- """returns pages which where written that day (daystring) with other info"""
+ """return pages which where written that day (daystring) with other info"""
query_result = query_db("select pages.*,notes.subject from pages left join notes on notes.id = pages.note_id \
where datestring = ?", [datestring])
return [{"subject": t["subject"], "datestring": datestring, "name": t["name"]}for t in query_result ]
def get_all_dates():
+ """return all dates from database"""
dates = query_db("select distinct datestring from notes ")
return dates
def get_all_subjects():
+ """return all subject from database"""
subjects = query_db("select distinct subject from notes ")
return subjects
+def prepare_all_dates():
+ """return all dates in well formated form of nested dictionaries"""
+ 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
+ return sorted_dates
+def sort_number_strings(data):
+ """return array of dictionaries sorted by day treated as a number, i.e. 12 is after 3."""
+ number_data = [int(day["day"]) for day in data]
+ number_data.sort()
+ 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):
+ """return name of the weekday for a specific number in range 0-6"""
+ weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
+ return weekdays[number]
+
+def get_index_for(number, data):
+ """get index of dictionary which day value equals number"""
+ index = 0
+ for i, day in enumerate(data):
+ if day["day"] == number:
+ index = i
+ return index
if __name__ == '__main__':
app.run()
diff --git a/templates/about.html b/templates/about.html
index 30a8a50..ee0a033 100644
--- a/templates/about.html
+++ b/templates/about.html
@@ -9,22 +9,22 @@ $("document").ready( function(){
</script>
<div class="container ">
- <h1>About</h1>
+ <h2>About</h2>
<p>
This application is a reader of notes. You can easily browse any notes which are uploaded and indexed.
</p>
<p>
Later on easy download, uploading, searching, tagging and commenting will be implemented.
</p>
- <h1>User guide</h1>
+ <h2>User guide</h2>
<p>
Select a subject from navigation bar menu. Then you will be able to see, which notes are uploaded.There is link, view and download buttons click on anything you are interested in.
</p>
- <h1>Why? What for? Motivation</h1>
+ <h2>Why? What for? Motivation</h2>
<p>
I like digital notes. But I encountered some problems, it wasn't very comfortable. I wanted to improve it. I wanted to share, to have easy access and automated updates and maintainence. So I made nooz. I am still working on it.
</p>
- <h1>How was it made?</h1>
+ <h2>How was it made?</h2>
<p>
Whole app is written in python. I used flask, amazing, fast, simple python web framework as backend. To make it look somehow I used twitter bootstrap. As database I use sqlite3.
</p>
diff --git a/templates/index.html b/templates/index.html
index c43bf33..ebff1b3 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -75,10 +75,10 @@ $("document").ready( function(){
</a>
<ul class="pager">
<li class="previous">
- <a href="" id="older">&larr; Older</a>
+ <a href="" id="older">&larr; Previous</a>
</li>
<li class="next">
- <a href="" id="newer">Newer &rarr;</a>
+ <a href="" id="newer">Next &rarr;</a>
</li>
</ul>
</li>
diff --git a/templates/layout.html b/templates/layout.html
index 86ebdd5..f6eb48e 100644
--- a/templates/layout.html
+++ b/templates/layout.html
@@ -7,38 +7,35 @@
<meta name="description" content="Home page of Attero">
<meta name="author" content="Justyna Ilczuk" >
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
- <script src="{{ url_for('static', filename='bootstrap/js/bootstrap.js') }}"></script>
- <link rel=stylesheet type=text/css href="{{ url_for('static', filename='bootstrap/css/bootstrap.css') }}">
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
+ <script src="{{ url_for('static', filename='bootstrap/js/bootstrap.js') }}"></script>
+ <link rel=stylesheet type=text/css href="{{ url_for('static', filename='bootstrap/css/bootstrap.css') }}">
-<script type=text/javascript>
- $SCRIPT_ROOT = {{ request.script_root|tojson|safe }};
-</script>
+ <script type=text/javascript>
+ $SCRIPT_ROOT = {{ request.script_root|tojson|safe }};
+ </script>
-<script >
+ <script >
-$("document").ready( function() {
- $('.submenu').hover(function () {
- console.log("hover");
- $(this).children('ul').removeClass('submenu-hide').addClass('submenu-show');
-
- }, function () {
- console.log("hide");
- $(this).children('ul').removeClass('.submenu-show').addClass('submenu-hide');
- }).find("a:first").append(" &raquo; ");
+ $("document").ready( function() {
+ $('.submenu').hover(function () {
+ console.log("hover");
+ $(this).children('ul').removeClass('submenu-hide').addClass('submenu-show');
+
+ }, function () {
+ console.log("hide");
+ $(this).children('ul').removeClass('.submenu-show').addClass('submenu-hide');
+ }).find("a:first").append(" &raquo; ");
-});
+ });
-
-
-
-</script>
+ </script>
</head>
<style type="text/css">
body {
- padding-top: 40px;
+ padding-top: 20px;
padding-bottom: 40px;
}
@@ -90,7 +87,7 @@ $("document").ready( function() {
</div>
- <div class="navbar well-small">
+ <div class="navbar well-small navbar-inverse">
<div class="navbar-inner">
<ul class="nav">
<li class="active" id="home"><a href="/view" >Home</a></li>
@@ -136,40 +133,37 @@ $("document").ready( function() {
<ul class="dropdown-menu">
<li class="nav-header">Year</li>
- {%- for key, year in all_dates.items() recursive %}
+ {%- for key, year in all_dates.items() recursive %}
<li class="dropdown submenu">
- <a href="#" class="dropdown-toggle" id="{{key}}" data-toggle="dropdown">{{key}}</a>
+ <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>
+
+ <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 %}
-
+ {%-endif%}
+ </li>
+ {%- endfor %}
</ul>
</div>
</ul>
</li>
-
-
<li>
<li id="search" ><a href="/search" >Advanced search</a></li>
</li>
@@ -177,8 +171,6 @@ $("document").ready( function() {
</div>
</div>
-<br />
-<br />
{% block body %}
{% endblock %}
diff --git a/templates/search.html b/templates/search.html
index 930359b..77f33ae 100644
--- a/templates/search.html
+++ b/templates/search.html
@@ -9,7 +9,7 @@ $("document").ready( function(){
</script>
<div class="container ">
- <h1>Search</h1>
+ <h2>Search</h2>
</div>
{% endblock %} \ No newline at end of file