This is a simple gallery of notes.

master
Justyna Ilczuk 2013-01-19 09:33:44 +01:00
commit abe640e75c
50 changed files with 13619 additions and 0 deletions

4
jquery.js vendored Normal file

File diff suppressed because one or more lines are too long

198
notes.py Normal file
View File

@ -0,0 +1,198 @@
# -*- coding: utf-8 -*-
# all the imports
from __future__ import with_statement
from contextlib import closing
import sqlite3
from flask import Flask, request, session, g, redirect, url_for, abort, render_template, flash, jsonify
import requests
from bs4 import BeautifulSoup
import re
from email.mime.text import MIMEText
from subprocess import Popen, PIPE
import smtplib
# configuration
DATABASE = '/tmp/notes.db'
DEBUG = True
SECRET_KEY = 'development key'
USERNAME = 'admin'
PASSWORD = 'dupa.8'
app = Flask(__name__)
app.config.from_object(__name__)
class Thumb:
def __init__(self, source, href, tags):
self.src = source
self.href = href
self.tags = tags
def connect_db():
return sqlite3.connect(app.config['DATABASE'])
def init_db():
with closing(connect_db()) as db:
with app.open_resource('schema.sql') as f:
db.cursor().executescript(f.read())
db.commit()
def query_db(query, args=(), one=False):
cur = g.db.execute(query, args)
rv = [dict((cur.description[idx][0], value)
for idx, value in enumerate(row)) for row in cur.fetchall()]
return (rv[0] if rv else None) if one else rv
@app.before_request
def before_request():
try:
g.db = g._db.cursor()
except AttributeError:
g._db = connect_db()
g.db = g._db.cursor()
@app.teardown_request
def teardown_request(exception):
try:
g.db.close()
except AttributeError:
pass
@app.route('/view')
@app.route('/view/<subject>/<datestring>')
def home(subject= "chemia", datestring= "12grudnia"):
other_dates = [date["datestring"] for date in get_possible_dates(subject)]
all_dates = [date["datestring"] for date in get_all_dates()]
all_subjects = [sub["subject"] for sub in get_all_subjects()]
if datestring in other_dates:
other_dates.remove(datestring)
thumbs_info = {"subject": subject, "datestring": datestring, "other_dates": other_dates}
thumbs = get_thumbs(subject, datestring)
thumbs = [dict(href=thumb.href, src=thumb.src) for thumb in thumbs]
main_page_src=thumbs[0]["href"]
print thumbs
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)
@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_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_subjects = [sub["subject"] for sub in get_all_subjects()]
notes = get_notes_for_day(datestring)
separated_notes = {}
for note in notes:
if not note["subject"] in separated_notes:
separated_notes[note["subject"]] = []
separated_notes[note["subject"]].append(note)
print separated_notes
return render_template('date.html', date=datestring, all_dates=all_dates, all_subjects=all_subjects, separated_notes=separated_notes)
@app.route('/search')
def show_search():
all_dates = [date["datestring"] for date in get_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_subjects = [sub["subject"] for sub in get_all_subjects()]
return render_template('about.html', all_dates=all_dates, all_subjects=all_subjects )
def add_note(subject, datestring, notes):
g.db.execute('insert into notes (subject, datestring ) values (?, ?)', [subject, datestring])
note_id = g.db.lastrowid
for note in notes:
g.db.execute('insert into pages (note_id, name, tags ) values (?, ?, ?)', [note_id, note["name"], note["tags"]])
g._db.commit()
def create_thumb(subject, datestring, name, tags):
src = subject + "/" + datestring + "/" + name
href = src
thumb = Thumb(src, href, tags)
return thumb
def get_thumbs(subject, datestring=""):
if(datestring==""):
query_result = query_db("select pages.* from pages left join notes on notes.id = pages.note_id where notes.subject = ?", [subject,])
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 "qr " + str(query_result)
return [create_thumb(subject, datestring, t["name"], t["tags"]) for t in query_result ]
def get_possible_dates(subject):
dates = query_db("select distinct datestring from notes where subject = ? ", [subject])
return dates
def get_notes_for_day(datestring):
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():
dates = query_db("select distinct datestring from notes ")
return dates
def get_all_subjects():
subjects = query_db("select distinct subject from notes ")
return subjects
@app.before_first_request
def add_notes_data_to_db():
init_db()
g._db = connect_db()
g.db = g._db.cursor()
query_result = query_db("select * from pages ")
print query_result
if not query_result:
notes = []
notes.append({"name": "0003.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
notes.append({"name": "0004.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
add_note("chemia", "12grudnia", notes)
notes = []
notes.append({"name": "0005.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
notes.append({"name": "0006.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
add_note("chemia", "19grudnia", notes)
notes = []
notes.append({"name": "0005.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
notes.append({"name": "0006.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
notes.append({"name": "0007.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
add_note("chemia", "28listopada", notes)
notes = []
notes.append({"name": "0009.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
notes.append({"name": "0010.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
notes.append({"name": "0011.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
notes.append({"name": "0012.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
add_note("analiza", "2stycznia", notes)
notes = []
notes.append({"name": "0013.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
notes.append({"name": "0014.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
notes.append({"name": "0015.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
notes.append({"name": "0016.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
add_note("analiza", "9stycznia", notes)
g.db.close()
if __name__ == '__main__':
app.run()

13
schema.sql Normal file
View File

@ -0,0 +1,13 @@
create table if not exists pages (
id integer primary key autoincrement,
note_id integer,
name string not null,
tags string not null
);
create table if not exists notes (
id integer primary key autoincrement,
subject string not null,
datestring string not null
);

BIN
static/3stycznia/0024.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 746 KiB

BIN
static/3stycznia/0025.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 567 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 649 KiB

BIN
static/4paźdź/0002.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 635 KiB

BIN
static/4paźdź/0003.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 552 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 454 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 436 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 390 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 344 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 740 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 778 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 732 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 703 KiB

4741
static/bootstrap.css Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

File diff suppressed because it is too large Load Diff

6
static/bootstrap/js/bootstrap.min.js vendored Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 692 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 697 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 393 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 399 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 814 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 779 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 706 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 786 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 719 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 663 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 642 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 621 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 558 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 759 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 638 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

15
templates/about.html Normal file
View File

@ -0,0 +1,15 @@
{% extends "layout.html" %}
{% block body %}
<script type="text/javascript">
//Change active button in navbar
$("document").ready( function(){
$("li").removeClass("active");
$("#about").addClass("active");
});
</script>
<div class="container ">
<h1>About</h1>
</div>
{% endblock %}

19
templates/date.html Normal file
View File

@ -0,0 +1,19 @@
{% extends "layout.html" %}
{% block body %}
<div class="container ">
<h1>{{date}}</h1>
{%- for key, subject in separated_notes.items() recursive %}
<h2>{{ key }}</h2>
{%- if subject %}
{% for note in subject %}
<a href="/view/{{note.subject}}/{{note.datestring }}" ><img src="{{ url_for('static', filename=note.subject + '/' + note.datestring + '/' + note.name) }}" height="30%" class="img img-rounded" width="30%" alt=""></a>
{% endfor %}
{%- endif %}
{%- endfor %}
</div>
{% endblock %}

46
templates/index.html Normal file
View File

@ -0,0 +1,46 @@
{% extends "layout.html" %}
{% block body %}
<script type="text/javascript">
//Change active button in navbar
$("document").ready( function(){
$("li").removeClass("active");
$("#home").addClass("active");
});
</script>
<div class="container ">
<h2>{{thumbs_info.subject}}, {{thumbs_info.datestring}}</h2>
<ul class="thumbnails">
<li class="span10">
<a href="#" id="image">
<img id="display" src="{{ url_for('static', filename=main_page_src) }}" alt="">
</a>
</li>
<li class="span2">
{% for thumb in thumbs %}
<a href="#" rel="{{ url_for('static', filename=thumb.href) }}" class="thumbnail image">
<img src="{{ url_for('static', filename=thumb.src) }}" alt="">
</a>
{% endfor %}
<ul>
<h4>Other dates...</h4>
{% for date in thumbs_info.other_dates %}
<li><a href="/view/{{thumbs_info.subject}}/{{date }}">{{date }}</a> </li>
{% endfor %}
</ul>
</li>
</ul>
<p>
What I want todo.
4. make it easy download upload of notes
5. add tagging and searching and subjects
</p>
{% endblock %}

115
templates/layout.html Normal file
View File

@ -0,0 +1,115 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>nooz</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<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 type="text/javascript">
$(function() {
$(".image").click(function() {
var image = $(this).attr("rel");
$('#display').hide();
$('#display').fadeIn('slow');
$('#display').attr("src", image);
return false;
});
});
</script>
<script type=text/javascript>
$SCRIPT_ROOT = {{ request.script_root|tojson|safe }};
</script>
<script >
/*function get_file_paths(address, message) {
$.getJSON( $SCRIPT_ROOT + '/_prepare_paths', {
mail_address:address,
message:message
}, function(data) {
console.log(data);
}
);
}*/
$("document").ready( function() {
});
</script>
</head>
<style type="text/css">
body {
padding-top: 40px;
padding-bottom: 40px;
}
</style>
<body>
<div class="well-small">
<h1>My own fuckin' gallery of notes</h1>
<p id="communicates"> </p>
</div>
<div class="navbar">
<div class="navbar-inner">
<ul class="nav">
<li class="active" id="home"><a href="/view" >Home</a></li>
<li id="about"><a href="/about" >About</a></li>
<li id="source"><a href="#" >Source</a></li>
<li>
<ul class="nav ">
<div class="dropdown">
<a class="btn dropdown-toggle " data-toggle="dropdown" href="#">
Subject
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
{% for subject in all_subjects %}
<li><a href="/subject/{{ subject }}">{{ subject }}</a> </li>
{% endfor %}
</ul>
</div>
</ul>
</li>
<li>
<ul class="nav ">
<div class="dropdown">
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
Date
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
{% for date in all_dates %}
<li><a href="/date/{{date }}">{{date }}</a> </li>
{% endfor %}
</ul>
</div>
</ul>
</li>
<li>
<li id="search" ><a href="/search" >Advanced search</a></li>
</li>
</ul>
</div>
</div>
{% block body %}
{% endblock %}
</html>

15
templates/search.html Normal file
View File

@ -0,0 +1,15 @@
{% extends "layout.html" %}
{% block body %}
<script type="text/javascript">
//Change active button in navbar
$("document").ready( function(){
$("li").removeClass("active");
$("#search").addClass("active");
});
</script>
<div class="container ">
<h1>Search</h1>
</div>
{% endblock %}

26
templates/subject.html Normal file
View File

@ -0,0 +1,26 @@
{% extends "layout.html" %}
{% block body %}
<div class="container ">
<h1>{{subject}}</h1>
{% for date in dates %}
<div class="row-fluid well-small">
<div class="span4">
<a href="/view/{{subject}}/{{date }}">{{date }}</a>
</div>
<div class="pull-right">
<a class="btn" href="/view/{{subject}}/{{date }}"> View</a>
<a class="btn"> Download</a>
</div>
</div>
{% endfor %}
<div class="row-fluid well">
<a class="btn btn-large"> Download all</a>
</div>
</div>
{% endblock %}