add pager
This commit is contained in:
parent
0663283893
commit
9823509909
@ -6,6 +6,7 @@ from photoapp.types import Photo, PhotoSet, Tag, TagItem
|
||||
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from sqlalchemy import func
|
||||
import math
|
||||
|
||||
|
||||
APPROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "../"))
|
||||
@ -18,6 +19,7 @@ class PhotosWeb(object):
|
||||
autoescape=select_autoescape(['html', 'xml']))
|
||||
self.tpl.globals.update(mime2ext=self.mime2ext)
|
||||
self.tpl.filters['basename'] = os.path.basename
|
||||
self.tpl.filters['ceil'] = math.ceil
|
||||
self.thumb = ThumbnailView(self)
|
||||
self.photo = PhotoView(self)
|
||||
self.download = DownloadView(self)
|
||||
@ -52,8 +54,9 @@ class PhotosWeb(object):
|
||||
def feed(self, page=0, pgsize=25):
|
||||
s = self.session()
|
||||
page, pgsize = int(page), int(pgsize)
|
||||
total_sets = s.query(func.count(PhotoSet.id)).first()[0]
|
||||
images = s.query(PhotoSet).order_by(PhotoSet.date.desc()).offset(pgsize * page).limit(pgsize).all()
|
||||
yield self.render("feed.html", images=[i for i in images], page=page)
|
||||
yield self.render("feed.html", images=[i for i in images], page=page, pgsize=int(pgsize), total_sets=total_sets)
|
||||
|
||||
@cherrypy.expose
|
||||
def monthly(self):
|
||||
|
@ -71,17 +71,15 @@ def get_exif_data(path):
|
||||
datestr = exif[key]
|
||||
continue
|
||||
|
||||
if datestr is None:
|
||||
print(exif.keys())
|
||||
raise Exception("{} has no DateTime".format(path)) # TODO how often do we hit this
|
||||
dateinfo = datetime.strptime(datestr, "%Y:%m:%d %H:%M:%S")
|
||||
if datestr is not None:
|
||||
dateinfo = datetime.strptime(datestr, "%Y:%m:%d %H:%M:%S")
|
||||
|
||||
orien = exif.get("Orientation")
|
||||
if orien:
|
||||
orientationinfo = {0: 0, 8: 1, 3: 2, 6: 3}.get(int(orien), 0)
|
||||
|
||||
gps = exif.get("GPSInfo")
|
||||
if gps:
|
||||
if gps and 1 in gps and 2 in gps and 3 in gps and 4 in gps:
|
||||
# see https://gis.stackexchange.com/a/273402
|
||||
gps_y = round(hms_to_decimal(rational64u_to_hms(gps[2])), 8)
|
||||
gps_x = round(hms_to_decimal(rational64u_to_hms(gps[4])), 8)
|
||||
|
@ -1,5 +1,6 @@
|
||||
import magic
|
||||
import argparse
|
||||
import traceback
|
||||
from photoapp.library import PhotoLibrary
|
||||
from photoapp.image import get_jpg_info, get_hash, get_mtime
|
||||
from itertools import chain
|
||||
@ -25,11 +26,16 @@ files_raw = ["cr2", "xmp"]
|
||||
files_video = ["mp4", "mov"]
|
||||
|
||||
|
||||
def pprogress(done, total=None):
|
||||
print(" complete: {}{}\r".format(done, " / {} ".format(total) if total else ''), end='')
|
||||
|
||||
|
||||
def batch_ingest(library, files):
|
||||
# group by extension
|
||||
byext = {k: [] for k in known_extensions}
|
||||
|
||||
print("processing {} items".format(len(files)))
|
||||
total = len(files)
|
||||
print("processing {} items".format(total))
|
||||
print("Pre-sorting files")
|
||||
for item in files:
|
||||
if not os.path.isfile(item):
|
||||
@ -52,9 +58,11 @@ def batch_ingest(library, files):
|
||||
# process regular images first.
|
||||
for item in chain(*[byext[ext] for ext in regular_images]):
|
||||
photos.append(get_jpg_info(item))
|
||||
pprogress(len(photos), total)
|
||||
|
||||
print("Scanning RAWs")
|
||||
print("\nScanning RAWs")
|
||||
# process raws
|
||||
done = len(photos)
|
||||
for item in chain(*[byext[ext] for ext in files_raw]):
|
||||
itemmeta = Photo(hash=get_hash(item), path=item, size=os.path.getsize(item),
|
||||
format=special_magic(item))
|
||||
@ -66,24 +74,38 @@ def batch_ingest(library, files):
|
||||
if os.path.basename(fmt.path).lower() == fmatch:
|
||||
foundmatch = True
|
||||
photo.files.append(itemmeta)
|
||||
done += 1
|
||||
pprogress(done, total)
|
||||
break
|
||||
if foundmatch:
|
||||
break
|
||||
if not foundmatch:
|
||||
photos.append(PhotoSet(date=get_mtime(item), lat=0, lon=0, files=[itemmeta]))
|
||||
done += 1
|
||||
pprogress(done, total)
|
||||
# TODO prune any xmp without an associated regular image or cr2
|
||||
|
||||
print("Scanning other files")
|
||||
print("\nScanning other files")
|
||||
# process all other formats
|
||||
for item in chain(*[byext[ext] for ext in files_video]):
|
||||
itemmeta = Photo(hash=get_hash(item), path=item, size=os.path.getsize(item),
|
||||
format=special_magic(item))
|
||||
photos.append(PhotoSet(date=get_mtime(item), lat=0, lon=0, files=[itemmeta]))
|
||||
done += 1
|
||||
pprogress(done, total)
|
||||
|
||||
print("Updating database")
|
||||
print("\nUpdating database")
|
||||
done = 0
|
||||
total = len(photos)
|
||||
for photoset in photos:
|
||||
library.add_photoset(photoset)
|
||||
print("Update complete")
|
||||
try:
|
||||
library.add_photoset(photoset)
|
||||
pprogress(done, total)
|
||||
done += 1
|
||||
except:
|
||||
traceback.print_exc()
|
||||
pass
|
||||
print("\nUpdate complete")
|
||||
|
||||
|
||||
def special_magic(fpath):
|
||||
|
@ -236,3 +236,13 @@ a {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ul.pager {
|
||||
padding: 0;
|
||||
li {
|
||||
display: inline-block;
|
||||
&.current {
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
{% set locals = namespace() %}
|
||||
|
||||
{% set total_pages = (total_sets/pgsize)|ceil %}
|
||||
|
||||
<div class="photo-feed">
|
||||
{% set locals.im_date = "" %}
|
||||
@ -21,7 +22,28 @@
|
||||
</div>
|
||||
{% endfor %}
|
||||
<br style="clear:both" />
|
||||
{% if page > 0 %}<a href="feed?page={{ page - 1 }}">Previous</a> {% endif %}<a href="feed?page={{ page + 1 }}">Next</a>
|
||||
<div class="pager">
|
||||
<h6>Page</h6>
|
||||
{% if page > 0 %}
|
||||
<div class="nav-prev">
|
||||
<a href="feed?page={{ page - 1 }}">Previous</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="pages">
|
||||
<ul class="pager">
|
||||
{% for pgnum in range(0, total_pages) %}
|
||||
<li{% if pgnum == page %} class="current"{% endif %}>
|
||||
<a href="/feed?page={{ pgnum }}">{{ pgnum }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% if page + 1 < total_pages %}
|
||||
<div class="nav-next">
|
||||
<a href="feed?page={{ page + 1 }}">Next</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% include "page-bottom.html" %}
|
||||
|
@ -9,9 +9,9 @@
|
||||
<script>
|
||||
<!-- https://wiki.openstreetmap.org/wiki/OpenLayers_Marker_Example -->
|
||||
var points = [
|
||||
{%- for item in images %}
|
||||
[{{item.lon}}, {{item.lat}}],
|
||||
{%- endfor %}
|
||||
{%- for item in images -%}
|
||||
[{{item.lon}}, {{item.lat}}],
|
||||
{%- endfor -%}
|
||||
]
|
||||
var map = new OpenLayers.Map("mapdiv");
|
||||
map.addLayer(new OpenLayers.Layer.OSM());
|
||||
|
Loading…
Reference in New Issue
Block a user