add recent/nearby photos
Gitea/photolib/pipeline/head This commit looks good Details

This commit is contained in:
dave 2022-08-01 22:07:44 -07:00
parent be69f76ffb
commit d695d3a0a5
4 changed files with 61 additions and 6 deletions

View File

@ -17,7 +17,7 @@ from photoapp.utils import auth, require_auth, photoset_auth_filter, slugify, ch
from photoapp.storage import uri_to_storage
from photoapp.webutils import validate_password, serve_thumbnail_placeholder
from jinja2 import Environment, FileSystemLoader, select_autoescape
from sqlalchemy import desc, func, and_, or_
from sqlalchemy import desc, asc, func, and_, or_
class PhotosWeb(object):
@ -322,7 +322,30 @@ class PhotoView(object):
PhotoSet.slug == uuid)).first()
if not photo:
raise cherrypy.HTTPError(404)
yield self.master.render("photo.html", image=photo)
if photo.lat:
nearby_photos = photoset_auth_filter(db.query(PhotoSet)) \
.filter(PhotoSet.lat.isnot(None)) \
.filter(PhotoSet.lon.isnot(None)) \
.filter(PhotoSet.id != photo.id) \
.order_by(func.sqrt(func.pow(PhotoSet.lat - photo.lat, 2) +
func.pow(PhotoSet.lon - photo.lon, 2))) \
.limit(25).all()
else:
nearby_photos = []
before = photoset_auth_filter(db.query(PhotoSet)) \
.filter(PhotoSet.date > photo.date) \
.order_by(PhotoSet.date.asc()) \
.limit(13).all()
before.reverse()
recent_photos = before + \
photoset_auth_filter(db.query(PhotoSet)) \
.filter(PhotoSet.date <= photo.date) \
.order_by(PhotoSet.date.desc()) \
.limit(12).all()
yield self.master.render("photo.html", image=photo, nearby=nearby_photos, recent=recent_photos)
@cherrypy.expose
@require_auth

View File

@ -16,8 +16,8 @@ def get_jpg_info(fpath):
if date is None:
raise Exception("No date found, panicing for unknown reasons!")
# gps is set to 0,0 if unavailable
lat, lon = gps or [None, None]
# gps is set to None, None if unavailable
lat, lon = gps if gps and 0 not in gps else [None, None]
dimensions = dimensions or (None, None)
mime = magic.from_file(fpath, mime=True)
size = os.path.getsize(fpath)

View File

@ -203,7 +203,7 @@ a {
display: block;
}
&:hover {
&:hover, &.current-photo {
border: 3px solid #252a3a;
width: 256px;
height: 256px;
@ -330,7 +330,7 @@ ul.form-pager {
font-size: 12px;
}
}
&:hover {
&:hover, &.current-photo {
border: 3px solid #252a3a;
width: 106px;
height: 106px;

View File

@ -139,4 +139,36 @@
</div>
</div>
</div>
{% if nearby %}
<hr/>
<div>
<h2>Nearby</h2>
<div class="photo-feed">
{% for i in nearby %}
<div class="photo">
<a href="/photo/{{ i.uuid }}">
<img src="/thumb/set/feed/{{ i.uuid }}.jpg" style="max-width: 250px"/>
</a>
</div>
{% endfor %}
<br clear="all" />
</div>
</div>
{% endif %}
{% if recent %}
<hr/>
<div>
<h2>Recent</h2>
<div class="photo-feed">
{% for i in recent %}
<div class="photo{% if image.id == i.id %} current-photo{% endif %}">
<a href="/photo/{{ i.uuid }}">
<img src="/thumb/set/feed/{{ i.uuid }}.jpg" style="max-width: 250px"/>
</a>
</div>
{% endfor %}
<br clear="all" />
</div>
</div>
{% endif %}
{% endblock %}