diff --git a/photoapp/daemon.py b/photoapp/daemon.py index 0b526ac..8deb294 100644 --- a/photoapp/daemon.py +++ b/photoapp/daemon.py @@ -22,6 +22,16 @@ class PhotosWeb(object): self.photo = PhotoView(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): return self.library.session() @@ -43,7 +53,7 @@ class PhotosWeb(object): s = self.session() page, pgsize = int(page), int(pgsize) 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 def monthly(self): @@ -53,7 +63,7 @@ class PhotosWeb(object): func.strftime('%m', PhotoSet.date).label('month')). \ 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 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) if 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') @@ -134,7 +144,7 @@ class PhotoView(object): s = self.master.session() 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) @@ -143,7 +153,7 @@ class PhotoView(object): s = self.master.session() photo = s.query(PhotoSet).filter(PhotoSet.uuid == uuid).first() 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 def tag_create(self, uuid, tag): diff --git a/photoapp/library.py b/photoapp/library.py index 6109e47..00ed025 100644 --- a/photoapp/library.py +++ b/photoapp/library.py @@ -84,9 +84,9 @@ class PhotoLibrary(object): return None if photo.uuid not in self._failed_thumbs_cache[style]: thumb_width, thumb_height, flip_ok = styles[style] - im_is_rotated = photo.orientation % 2 != 0 i_width = photo.width i_height = photo.height + im_is_rotated = photo.orientation % 2 != 0 or i_height > i_width if im_is_rotated and flip_ok: thumb_width, thumb_height = thumb_height, thumb_width diff --git a/photoapp/types.py b/photoapp/types.py index 1b01a65..a764a60 100644 --- a/photoapp/types.py +++ b/photoapp/types.py @@ -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.schema import UniqueConstraint from sqlalchemy.ext.declarative import declarative_base @@ -50,6 +50,7 @@ class Tag(Base): uuid = Column(Unicode, unique=True, default=lambda: str(uuid.uuid4())) created = Column(DateTime, default=lambda: datetime.now()) modified = Column(DateTime, default=lambda: datetime.now()) + is_album = Column(Boolean) title = Column(String, unique=True) slug = Column(String, unique=True) description = Column(String) diff --git a/styles/less/main.less b/styles/less/main.less index 4745847..9f07e69 100644 --- a/styles/less/main.less +++ b/styles/less/main.less @@ -64,22 +64,20 @@ a { color: rgb(75, 113, 151); } -.email-label-personal, -.email-label-work, -.email-label-travel { +.tag-icon { width: 15px; height: 15px; display: inline-block; margin-right: 0.5em; border-radius: 3px; } -.email-label-personal { +.tag-icon-mod-3-0 { background: #ffc94c; } -.email-label-work { +.tag-icon-mod-3-1 { background: #41ccb4; } -.email-label-travel { +.tag-icon-mod-3-2 { background: #40c365; } @@ -223,14 +221,13 @@ a { } .tags-picker { - ul { - - } + padding: 0; li { display: inline-block; - padding-right: 15px; + padding-right: 25px; } input.submit-link { + padding: 0; border: 0; background: none; color: @linkcolor; diff --git a/templates/page-top.html b/templates/page-top.html index 2fe1ae1..c513b63 100644 --- a/templates/page-top.html +++ b/templates/page-top.html @@ -22,9 +22,9 @@
  • Foo
  • Bar
  • Tags
  • -
  • Personal
  • -
  • Work
  • -
  • Travel
  • + {% for tag in all_tags %} +
  • {{ tag.title }}
  • + {% endfor %}