default template vars

This commit is contained in:
dave 2018-09-09 17:21:23 -07:00
parent 018faecc3a
commit ef63c30f8b
5 changed files with 28 additions and 20 deletions

View File

@ -22,6 +22,16 @@ class PhotosWeb(object):
self.photo = PhotoView(self) self.photo = PhotoView(self)
self.download = DownloadView(self) self.download = DownloadView(self)
def render(self, template, **kwargs):
return self.tpl.get_template(template).render(**kwargs, **self.get_default_vars())
def get_default_vars(self):
s = self.session()
ret = {
"all_tags": s.query(Tag).order_by(Tag.title).all()
}
return ret
def session(self): def session(self):
return self.library.session() return self.library.session()
@ -43,7 +53,7 @@ class PhotosWeb(object):
s = self.session() s = self.session()
page, pgsize = int(page), int(pgsize) page, pgsize = int(page), int(pgsize)
images = s.query(PhotoSet).order_by(PhotoSet.date.desc()).offset(pgsize * page).limit(pgsize).all() images = s.query(PhotoSet).order_by(PhotoSet.date.desc()).offset(pgsize * page).limit(pgsize).all()
yield self.tpl.get_template("feed.html").render(images=[i for i in images], page=page) yield self.render("feed.html", images=[i for i in images], page=page)
@cherrypy.expose @cherrypy.expose
def monthly(self): def monthly(self):
@ -53,7 +63,7 @@ class PhotosWeb(object):
func.strftime('%m', PhotoSet.date).label('month')). \ func.strftime('%m', PhotoSet.date).label('month')). \
group_by('year', 'month').order_by('year', 'month').all() group_by('year', 'month').order_by('year', 'month').all()
yield self.tpl.get_template("monthly.html").render(images=images) yield self.render("monthly.html", images=images)
@cherrypy.expose @cherrypy.expose
def map(self, i=None, zoom=3): def map(self, i=None, zoom=3):
@ -61,7 +71,7 @@ class PhotosWeb(object):
query = s.query(PhotoSet).filter(PhotoSet.lat != 0, PhotoSet.lon != 0) query = s.query(PhotoSet).filter(PhotoSet.lat != 0, PhotoSet.lon != 0)
if i: if i:
query = query.filter(PhotoSet.uuid == i) query = query.filter(PhotoSet.uuid == i)
yield self.tpl.get_template("map.html").render(images=query.all(), zoom=int(zoom)) yield self.render("map.html", images=query.all(), zoom=int(zoom))
@cherrypy.popargs('item_type', 'thumb_size', 'uuid') @cherrypy.popargs('item_type', 'thumb_size', 'uuid')
@ -134,7 +144,7 @@ class PhotoView(object):
s = self.master.session() s = self.master.session()
photo = s.query(PhotoSet).filter(PhotoSet.uuid == uuid).first() photo = s.query(PhotoSet).filter(PhotoSet.uuid == uuid).first()
yield self.master.tpl.get_template("photo.html").render(image=photo) yield self.master.render("photo.html", image=photo)
# yield "viewing {}".format(uuid) # yield "viewing {}".format(uuid)
@ -143,7 +153,7 @@ class PhotoView(object):
s = self.master.session() s = self.master.session()
photo = s.query(PhotoSet).filter(PhotoSet.uuid == uuid).first() photo = s.query(PhotoSet).filter(PhotoSet.uuid == uuid).first()
alltags = s.query(Tag).order_by(Tag.title).all() alltags = s.query(Tag).order_by(Tag.title).all()
yield self.master.tpl.get_template("photo_tag.html").render(image=photo, alltags=alltags) yield self.master.render("photo_tag.html", image=photo, alltags=alltags)
@cherrypy.expose @cherrypy.expose
def tag_create(self, uuid, tag): def tag_create(self, uuid, tag):

View File

@ -84,9 +84,9 @@ class PhotoLibrary(object):
return None return None
if photo.uuid not in self._failed_thumbs_cache[style]: if photo.uuid not in self._failed_thumbs_cache[style]:
thumb_width, thumb_height, flip_ok = styles[style] thumb_width, thumb_height, flip_ok = styles[style]
im_is_rotated = photo.orientation % 2 != 0
i_width = photo.width i_width = photo.width
i_height = photo.height i_height = photo.height
im_is_rotated = photo.orientation % 2 != 0 or i_height > i_width
if im_is_rotated and flip_ok: if im_is_rotated and flip_ok:
thumb_width, thumb_height = thumb_height, thumb_width thumb_width, thumb_height = thumb_height, thumb_width

View File

@ -1,4 +1,4 @@
from sqlalchemy import Column, Integer, String, DateTime, Unicode, DECIMAL, ForeignKey from sqlalchemy import Column, Integer, String, DateTime, Unicode, DECIMAL, ForeignKey, Boolean
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from sqlalchemy.schema import UniqueConstraint from sqlalchemy.schema import UniqueConstraint
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
@ -50,6 +50,7 @@ class Tag(Base):
uuid = Column(Unicode, unique=True, default=lambda: str(uuid.uuid4())) uuid = Column(Unicode, unique=True, default=lambda: str(uuid.uuid4()))
created = Column(DateTime, default=lambda: datetime.now()) created = Column(DateTime, default=lambda: datetime.now())
modified = Column(DateTime, default=lambda: datetime.now()) modified = Column(DateTime, default=lambda: datetime.now())
is_album = Column(Boolean)
title = Column(String, unique=True) title = Column(String, unique=True)
slug = Column(String, unique=True) slug = Column(String, unique=True)
description = Column(String) description = Column(String)

View File

@ -64,22 +64,20 @@ a {
color: rgb(75, 113, 151); color: rgb(75, 113, 151);
} }
.email-label-personal, .tag-icon {
.email-label-work,
.email-label-travel {
width: 15px; width: 15px;
height: 15px; height: 15px;
display: inline-block; display: inline-block;
margin-right: 0.5em; margin-right: 0.5em;
border-radius: 3px; border-radius: 3px;
} }
.email-label-personal { .tag-icon-mod-3-0 {
background: #ffc94c; background: #ffc94c;
} }
.email-label-work { .tag-icon-mod-3-1 {
background: #41ccb4; background: #41ccb4;
} }
.email-label-travel { .tag-icon-mod-3-2 {
background: #40c365; background: #40c365;
} }
@ -223,14 +221,13 @@ a {
} }
.tags-picker { .tags-picker {
ul { padding: 0;
}
li { li {
display: inline-block; display: inline-block;
padding-right: 15px; padding-right: 25px;
} }
input.submit-link { input.submit-link {
padding: 0;
border: 0; border: 0;
background: none; background: none;
color: @linkcolor; color: @linkcolor;

View File

@ -22,9 +22,9 @@
<li class="pure-menu-item"><a href="/albums" class="pure-menu-link">Foo</a></li> <li class="pure-menu-item"><a href="/albums" class="pure-menu-link">Foo</a></li>
<li class="pure-menu-item"><a href="/albums" class="pure-menu-link">Bar</a></li> <li class="pure-menu-item"><a href="/albums" class="pure-menu-link">Bar</a></li>
<li class="pure-menu-heading">Tags</li> <li class="pure-menu-heading">Tags</li>
<li class="pure-menu-item"><a href="/tag/personal" class="pure-menu-link"><span class="email-label-personal"></span>Personal</a></li> {% for tag in all_tags %}
<li class="pure-menu-item"><a href="/tag/work" class="pure-menu-link"><span class="email-label-work"></span>Work</a></li> <li class="pure-menu-item"><a href="/tag/{{ tag.uuid }}" class="pure-menu-link"><span class="tag-icon tag-icon-mod-3-{{ tag.id % 3 }}"></span>{{ tag.title }}</a></li>
<li class="pure-menu-item"><a href="/tag/travel" class="pure-menu-link"><span class="email-label-travel"></span>Travel</a></li> {% endfor %}
</ul> </ul>
</div> </div>
</div> </div>