deployable nao?
This commit is contained in:
parent
a1c1f24087
commit
a1e660fc12
8 changed files with 190 additions and 6 deletions
|
@ -5,3 +5,5 @@ MIME = r'image/.*'
|
|||
|
||||
THUMB_DIR = './thumb'
|
||||
THUMB_SIZE = (100,100)
|
||||
|
||||
TEMPLATE_DIR = 'templates'
|
||||
|
|
32
gallery.py
32
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/<path:tgt>')
|
||||
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/<path:tgt>')
|
||||
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)
|
||||
|
|
62
hackerspace/basic.html
Normal file
62
hackerspace/basic.html
Normal file
|
@ -0,0 +1,62 @@
|
|||
<!DOCTYPE html>
|
||||
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
|
||||
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
|
||||
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
|
||||
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
|
||||
<head>
|
||||
{% block head %}
|
||||
<meta charset="utf-8" />
|
||||
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /><![endif]-->
|
||||
<title>{% block title %}{% endblock %}</title>
|
||||
<script src="https://static.hackerspace.pl/js/jquery.min.js"></script>
|
||||
{% block checkinator_script %}
|
||||
<script src="https://static.hackerspace.pl/js/checkinator-header.js"></script>
|
||||
{% endblock %}
|
||||
{% block page_scripts %}
|
||||
{% endblock %}
|
||||
{% block basic_style %}
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
|
||||
<link rel="shortcut icon" href="https://static.hackerspace.pl/img/favicon.ico"/>
|
||||
<link rel="apple-touch-icon" href="https://static.hackerspace.pl/img/glider.png"/>
|
||||
<link rel="stylesheet" href="https://static.hackerspace.pl/fonts/news-cycle/stylesheet.css"/>
|
||||
<link rel="stylesheet" href="https://static.hackerspace.pl/fonts/titillium/stylesheet.css"/>
|
||||
<link rel="stylesheet" href="https://static.hackerspace.pl/css/style.css"/>
|
||||
{% endblock %}
|
||||
{% block page_style %}
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
{% block body %}
|
||||
<a name="top"></a>
|
||||
{% block header %}
|
||||
{% include 'header.html' %}
|
||||
{% endblock %}
|
||||
<div id="hs_main">
|
||||
{% block main %}
|
||||
<div id="hs_rotimage">
|
||||
{% block rotimage %}
|
||||
{% include 'rotimage_at.html' %}
|
||||
{% block rotimage_login %}
|
||||
<div class="hs_login_bar">
|
||||
{% block login %}
|
||||
<ul>
|
||||
<li><a class="action user" href="https://ldap.hackerspace.pl">Member profile</a></li>
|
||||
</ul>
|
||||
{% endblock %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
<div id="hs_content">
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
</div>
|
||||
{% block footer %}
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
</body>
|
||||
</html>
|
11
hackerspace/header.html
Normal file
11
hackerspace/header.html
Normal file
|
@ -0,0 +1,11 @@
|
|||
<header id="hs_branding">
|
||||
<a id="hs_header" href="https://hackerspace.pl/">Warsaw Hackerspace</a>
|
||||
<ul id="hs_header_menu">
|
||||
<li><a href="https://hackerspace.pl/">about</a></li>
|
||||
<li><a href="https://blog.hackerspace.pl">blog</a></li>
|
||||
<li><a href="https://wiki.hackerspace.pl">wiki</a></li>
|
||||
<li><a href="https://code.hackerspace.pl">code</a></li>
|
||||
<li><a href="https://webchat.hackerspace.pl">chat</a></li>
|
||||
<li><a href="https://redmine.hackerspace.pl">tasks</a></li>
|
||||
</ul>
|
||||
</header>
|
27
hackerspace/main.html
Normal file
27
hackerspace/main.html
Normal file
|
@ -0,0 +1,27 @@
|
|||
{% extends 'basic.html' %}
|
||||
{% block page_scripts %}
|
||||
<script type="text/javascript" src="https://widgets.twimg.com/j/2/widget.js"></script>
|
||||
{% endblock %}
|
||||
{% block page_style %}
|
||||
<link rel="stylesheet" href="/static/gallery.css"/>
|
||||
{% endblock %}
|
||||
{% block title %}Hackerspace Warszawa - Galamity - {{path}}{% endblock %}
|
||||
{% block content %}
|
||||
<a href="{{ parent }}">↑ W górę ↑</a>
|
||||
<h1>{{ path }}</h1>
|
||||
<h2>Podgalerie</h2>
|
||||
<ul class="subgallery">
|
||||
{% for d in dirs %}
|
||||
<li><a href="{{d | gallery }}">{{ d }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<h2>Zdjęcia</h2>
|
||||
<ul class="pictures">
|
||||
{% for p in pics %}
|
||||
<li><a title="{{p}}" href="{{p | picture }}">
|
||||
<img src="{{ p | thumb }}"></img>
|
||||
</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<span class="clear"><a href="#top">↑ Powrót na górę ↑</span>
|
||||
{% endblock %}
|
6
hackerspace/rotimage_at.html
Normal file
6
hackerspace/rotimage_at.html
Normal file
|
@ -0,0 +1,6 @@
|
|||
<div id="status" style="display: none;">
|
||||
<div id="status-tooltip" style="display: none;">
|
||||
<p>Refreshing...</p>
|
||||
</div>
|
||||
<img src="https://static.hackerspace.pl/img/status-open.png" alt="Sorry, we're open! - The Warsaw Hackerspace is open right now." />
|
||||
</div>
|
54
static/gallery.css
Normal file
54
static/gallery.css
Normal file
|
@ -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;
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
<h2>Subgalleries</h2>
|
||||
<ul>
|
||||
{% for d in dirs %}
|
||||
<li><a href="{{d | relurl}}">{{d}}</a></li>
|
||||
<li><a href="{{d | relurl}}/index.html">{{d}}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<h2>Pictures</h2>
|
||||
|
|
Loading…
Add table
Reference in a new issue