diff --git a/.gitignore b/.gitignore index 3019225..c0f6bcf 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ env *.cfg *.log *.sock -*.pid \ No newline at end of file +*.pid +thumbs/* \ No newline at end of file diff --git a/foto_gallery/__init__.py b/foto_gallery/__init__.py index a1c451a..c99f658 100644 --- a/foto_gallery/__init__.py +++ b/foto_gallery/__init__.py @@ -14,20 +14,8 @@ import os import re from PIL import Image, ExifTags, ImageOps from functools import partial -#from .flatpages import FileLists -# This is the directory, required for absolute file paths -#package_directory = os.path.dirname(os.path.abspath(__file__)) -# Loading the config file -#cfg = Config((os.path.join(package_directory, '../config.cfg'))) cfg = Config("config.cfg") -# Loading constants from config file -#FLATPAGES_AUTO_RELOAD = cfg.get("FLATPAGES_AUTO_RELOAD",True) # Default can be overwritten by config cfg -#FLATPAGES_EXTENSION = cfg.get("FLATPAGES_EXTENSION",".md") # Default can be overwritten by config cfg -#FLATPAGES_ROOT = os.path.abspath(cfg.pages_root) -#FLATPAGES_DEFAULT_TEMPLATE = cfg.get("FLATPAGES_DEFAULT_TEMPLATE","gallery.html") - - # Initialize application app = Flask(__name__) @@ -37,19 +25,16 @@ app.logger.setLevel(logging.DEBUG) flatpages = FlatPagesIndex(app) flatpages_index.Links.endpoint="intern.post" +flatpages_index.Links.image_url=lambda s,x: url_for(s.endpoint,name=x) flatpages_index.Links.thumb_url=lambda s,x: url_for("intern.thumb",size=128,name=x) flatpages_index.Links.image_url=lambda s,x: url_for("intern.post",name=x) - +flatpages_index.Page.page_defaults={"type":"gallery"} flatpages.get('index') -app.logger.info('Initialize Foto Gallery App') +app.logger.info('Initialize FET Foto Gallery App') app.logger.info('flatpages loaded %d pages' % len(flatpages._pages)) app.logger.info("Data directory is: %s" % flatpages.root) app.logger.info("Url prefix;: %s" % cfg.url_prefix) -app.url_map.strict_slashes=True - - - @@ -57,6 +42,7 @@ freezer = Freezer(app) page_blueprint = Blueprint('intern', __name__) +api_blueprint = Blueprint('api', __name__) @page_blueprint.route('/thumb/') def thumb(size=64,name=''): @@ -69,18 +55,19 @@ def thumb(size=64,name=''): print("creating thumb") image= Image.open(file_name,'r') s=size, size - for orientation in ExifTags.TAGS.keys(): - if ExifTags.TAGS[orientation]=='Orientation': - break - exif=dict(image._getexif().items()) + if image._getexif() is not None: + for orientation in ExifTags.TAGS.keys(): + if ExifTags.TAGS[orientation]=='Orientation': + break + exif=dict(image._getexif().items()) - if exif[orientation] == 3: - image=image.rotate(180, expand=True) - elif exif[orientation] == 6: - image=image.rotate(270, expand=True) - elif exif[orientation] == 8: - image=image.rotate(90, expand=True) - thumb=ImageOps.fit(image,s,Image.ANTIALIAS) + if exif[orientation] == 3: + image=image.rotate(180, expand=True) + elif exif[orientation] == 6: + image=image.rotate(270, expand=True) + elif exif[orientation] == 8: + image=image.rotate(90, expand=True) + thumb=ImageOps.fit(image,s,Image.ANTIALIAS) print("writing %s"% thumb_name) os.makedirs(thumb_path,exist_ok=True) @@ -103,7 +90,6 @@ def post(name=''): page["has_img"]=True page.links.endpoint='intern.post' - return render_template(page["template"], post=page, pth=page["dirpath"]) @@ -112,19 +98,21 @@ def post(name=''): elif os.path.exists(os.path.join('static',name)): print("send from static dir %s" % name) return send_from_directory('static',name) + elif os.path.exists(os.path.join(cfg["fet_assets"],name)): + return send_from_directory(cfg["fet_assets"],name) else: return send_from_directory('blueimp',name) -@page_blueprint.route('/.json',strict_slashes=False) -@page_blueprint.route('/.json',strict_slashes=False) +@api_blueprint.route('/.json',strict_slashes=False) +@api_blueprint.route('/.json',strict_slashes=False) def postjson(name='index'): print("Post: %s" % name) page = flatpages.get(name) if not page is None: page["has_img"]=True # can be overwritten by file - page.links.endpoint='intern.postjson' + page.links.endpoint='api.postjson' return jsonify(page=dict(page)) @@ -136,4 +124,5 @@ def postjson(name='index'): app.register_blueprint(page_blueprint, url_prefix=cfg.url_prefix,static_folder='static') +app.register_blueprint(api_blueprint, url_prefix="/api/"+cfg.url_prefix,static_folder='static') app.add_url_rule('%s/' % cfg.url_prefix,'page', post) diff --git a/foto_gallery/templates/gallery.html b/foto_gallery/templates/gallery.html index 69e4588..c09ed43 100644 --- a/foto_gallery/templates/gallery.html +++ b/foto_gallery/templates/gallery.html @@ -1,7 +1,8 @@ {# -*-jinja2-*- #} -{% extends "layout.html" %} +{% extends "layoutfetbs3.html" %} {% block content %}

{{post.title}}

+ von {{post.author}} {{post.html | safe}} {% if post.links.images |length > 0 %} @@ -22,11 +23,11 @@ - + + Fetsite + + + +
+
+
+
+ +
+ Logo2014_64 +
+
+ Fachschaft Elektrotechnik +
+
+ + +
+
+
+ +
+
+ + + {% block content %} + {% endblock %} + + +
+
+ +
+ + diff --git a/foto_gallery/templates/page.html b/foto_gallery/templates/page.html index c38ef0a..b9e98fb 100644 --- a/foto_gallery/templates/page.html +++ b/foto_gallery/templates/page.html @@ -1,5 +1,5 @@ {# -*-jinja2-*- #} -{% extends "layout.html" %} +{% extends "layoutfetbs3.html" %} {% block content %}

{{post.title}}

@@ -10,8 +10,8 @@