From a1e660fc128cc0857391eaebc3770a8b6517c28c Mon Sep 17 00:00:00 2001 From: Tomek Dubrownik Date: Thu, 28 Feb 2013 19:08:08 +0100 Subject: [PATCH] deployable nao? --- gallery.cfg.dist | 2 ++ gallery.py | 32 ++++++++++++++++--- hackerspace/basic.html | 62 ++++++++++++++++++++++++++++++++++++ hackerspace/header.html | 11 +++++++ hackerspace/main.html | 27 ++++++++++++++++ hackerspace/rotimage_at.html | 6 ++++ static/gallery.css | 54 +++++++++++++++++++++++++++++++ templates/main.html | 2 +- 8 files changed, 190 insertions(+), 6 deletions(-) create mode 100644 hackerspace/basic.html create mode 100644 hackerspace/header.html create mode 100644 hackerspace/main.html create mode 100644 hackerspace/rotimage_at.html create mode 100644 static/gallery.css diff --git a/gallery.cfg.dist b/gallery.cfg.dist index 15e7a4d..fc7a468 100644 --- a/gallery.cfg.dist +++ b/gallery.cfg.dist @@ -5,3 +5,5 @@ MIME = r'image/.*' THUMB_DIR = './thumb' THUMB_SIZE = (100,100) + +TEMPLATE_DIR = 'templates' diff --git a/gallery.py b/gallery.py index e5a2e3c..fc9ebe0 100644 --- a/gallery.py +++ b/gallery.py @@ -4,11 +4,13 @@ import mimetypes from os.path import isdir, abspath, exists, split from flask import Flask, render_template, abort, send_file, safe_join from PIL import Image -from jinja2 import contextfilter +from jinja2 import contextfilter, FileSystemLoader app = Flask('gallery') app.config.from_pyfile('gallery.cfg') +app.jinja_loader = FileSystemLoader(app.config['TEMPLATE_DIR']) + picmime = re.compile(app.config['MIME']) base = app.config['DIRECTORY'] thumb = app.config['THUMB_DIR'] @@ -17,14 +19,31 @@ thsize = app.config['THUMB_SIZE'] def is_image(path): return picmime.match(mimetypes.guess_type(path)[0] or 'NOPE') -@app.template_filter('relurl') -@contextfilter def relurl(ctx, tgt): return safe_join(ctx['path'], tgt) +@app.template_filter('gallery') +@contextfilter +def url_gallery(ctx, tgt): + return safe_join('/', relurl(ctx, tgt)) + +@app.template_filter('picture') +@contextfilter +def url_picture(ctx, tgt): + return safe_join('/pictures', relurl(ctx, tgt)) + +@app.template_filter('thumb') +@contextfilter +def url_thumb(ctx, tgt): + return safe_join('/thumb', relurl(ctx, tgt)) + @app.route('/pictures/') def send_pic(tgt): - return send_file(safe_join(base, tgt)) + path = safe_join(base, tgt) + if is_image(path): + return send_file(path) + else: + abort(403) def ensure_dir(path): try: @@ -38,6 +57,8 @@ def ensure_dir(path): @app.route('/thumb/') def send_thumb(tgt): orig_path = safe_join(base, tgt) + if not is_image(orig_path): + abort(403) thumb_path = safe_join(thumb, tgt) if not exists(thumb_path) or \ os.stat(thumb_path).st_mtime < os.stat(orig_path).st_mtime: @@ -57,7 +78,8 @@ def view(tgt=''): names = map(lambda s: s.decode(app.config['CHARSET']), os.listdir(path)) dirs = filter(lambda f: isdir(safe_join(path,f)), names) pics = filter(is_image, names) - return render_template('main.html', dirs=dirs, pics=pics, path=tgt) + return render_template('main.html', dirs=dirs, pics=pics, path=tgt, + parent = '/' + os.path.split(tgt)[0]) except OSError as e: if e.errno == 2: abort(404) diff --git a/hackerspace/basic.html b/hackerspace/basic.html new file mode 100644 index 0000000..21582cc --- /dev/null +++ b/hackerspace/basic.html @@ -0,0 +1,62 @@ + + + + + + + {% block head %} + + + {% block title %}{% endblock %} + + {% block checkinator_script %} + + {% endblock %} + {% block page_scripts %} + {% endblock %} + {% block basic_style %} + + + + + + + + {% endblock %} + {% block page_style %} + {% endblock %} + {% endblock %} + + + {% block body %} + + {% block header %} + {% include 'header.html' %} + {% endblock %} +
+ {% block main %} +
+ {% block rotimage %} + {% include 'rotimage_at.html' %} + {% block rotimage_login %} + + {% endblock %} + {% endblock %} +
+ {% endblock %} +
+ {% block content %} + {% endblock %} +
+
+ {% block footer %} + {% endblock %} + {% endblock %} + + diff --git a/hackerspace/header.html b/hackerspace/header.html new file mode 100644 index 0000000..9604bcf --- /dev/null +++ b/hackerspace/header.html @@ -0,0 +1,11 @@ +
+ Warsaw Hackerspace + +
diff --git a/hackerspace/main.html b/hackerspace/main.html new file mode 100644 index 0000000..3224a67 --- /dev/null +++ b/hackerspace/main.html @@ -0,0 +1,27 @@ +{% extends 'basic.html' %} +{% block page_scripts %} + +{% endblock %} +{% block page_style %} + +{% endblock %} +{% block title %}Hackerspace Warszawa - Galamity - {{path}}{% endblock %} +{% block content %} + ↑ W górę ↑ +

{{ path }}

+

Podgalerie

+
    + {% for d in dirs %} +
  • {{ d }}
  • + {% endfor %} +
+

Zdjęcia

+
    + {% for p in pics %} +
  • + +
  • + {% endfor %} +
+ ↑ Powrót na górę ↑ +{% endblock %} diff --git a/hackerspace/rotimage_at.html b/hackerspace/rotimage_at.html new file mode 100644 index 0000000..dc2bf2b --- /dev/null +++ b/hackerspace/rotimage_at.html @@ -0,0 +1,6 @@ + diff --git a/static/gallery.css b/static/gallery.css new file mode 100644 index 0000000..d4205af --- /dev/null +++ b/static/gallery.css @@ -0,0 +1,54 @@ +ul.subgallery { +} + +ul.subgallery a:before { + content: url("https://static.hackerspace.pl/img/jigsoar/dark/16px/16_thumbnail.png"); + padding: 5px; +} + +h2 { + clear: both; + display: block; +} + +ul.subgallery li { + display: block; + float: left; +} + +ul.pictures { + list-style-type: none; +} + +ul.pictures li { +} + +ul.pictures a:after { + content: attr(title); +} + +ul.pictures a, ul.subgallery a { + box-shadow: 0 3px 6px rgba(0, 0, 0, 0.5); + display: inline; + float: left; + margin: 5px; + padding: 5px; + text-align: center; + text-decoration: none; + color: #333; + font-family: "Titillium Web"; + font-weight: 600; + overflow: hidden; + border: 1px solid #999; +} + +ul.pictures img { + display: block; + margin: auto; +} + +span.clear { + clear: both; + display: block; + text-align: center; +} diff --git a/templates/main.html b/templates/main.html index 68024a8..b0b76f5 100644 --- a/templates/main.html +++ b/templates/main.html @@ -6,7 +6,7 @@

Subgalleries

Pictures