Exemplo n.º 1
0
	def _find_adj_photos(self, s, aid, pid):
		photos_q = s.query(Photo).filter(Photo.album_id == aid)

		cur_album = s.query(Album).filter(Album.id == aid).first()

		if cur_album.sort_by == utils.SORT_BY_DATE:
			photos_q = photos_q.order_by(Photo.created)
		elif cur_album.sort_by == utils.SORT_BY_DATE_DESC:
			photos_q = photos_q.order_by(Photo.created.desc())

		photos = photos_q.all()

		photo_ids = map(lambda x: x.id, photos)
		cur_idx = photo_ids.index(long(pid))

		if cur_idx == 0:
			prev = None
			first = None
		else:
			prev = photos[cur_idx - 1]
			first = photos[0]

		if cur_idx == len(photo_ids) - 1:
			next = None
			last = None
		else:
			next = photos[cur_idx + 1]
			last = photos[len(photo_ids) - 1]

		return (cur_idx + 1, len(photos), first, prev, next, last)
Exemplo n.º 2
0
	def show_photos(self, aid, page = 0):
		c.u = utils
		c.album = s.query(Album).filter(Album.id == aid).first()
		if not c.album:
			abort(404)

		c.photos = self._get_photos(aid, page, "show_photos", 10)[1]

		return render("/photo-all.mako")
Exemplo n.º 3
0
	def album_del(self, aid):
		album = s.query(Album).filter(Album.id == aid).first()
		if not album:
			abort(404)

		s.delete(album)
		s.commit()

		redirect(url(controller = "album",
					action = "show_first_page", aid = album.parent_id))
Exemplo n.º 4
0
	def album_edit(self, aid):
		c.u = utils
		c.aid = aid
		c.new_album = False

		c.album = s.query(Album).filter(Album.id == aid).first()
		if not c.album:
			abort(404)

		return render('album_edit.mako')
Exemplo n.º 5
0
	def index(self, aid, pid):
		photo_q = s.query(Photo)
		c.photo = photo_q.filter_by(album_id=aid, id=pid).first()

		if c.photo is None:
			abort(404)

		(c.idx, c.all, c.first, c.prev, c.next, c.last) = self._find_adj_photos(s, aid, pid)

		return render('/photo.mako')
Exemplo n.º 6
0
	def show_page(self, aid, page):
		c.u = utils
		c.album = s.query(Album).filter(Album.id == aid).first()
		if not c.album:
			abort(404)

		c.albums = self._get_albums(aid, page)
		c.photos = self._get_photos(aid, page, "show_page", 16)[1]

		c.counts = self._get_counts(c.album)

		return render("/album.mako")
Exemplo n.º 7
0
	def photo_del_submit(self, aid, pid):
		photo_q = s.query(Photo)
		photo_obj = photo_q.filter_by(album_id=aid, id=pid).first()
		if photo_obj is None:
			c.name = pid
			return render('/photo_not_found.mako')

		s.delete(photo_obj)
		s.commit()

		redirect(url(controller = "album",
					action = "show_first_page", aid = aid))
Exemplo n.º 8
0
	def photo_edit_submit(self, aid, pid):
		if request.params.get("Cancel"):
			redirect(url(controller="album",
						action = "show_first_page", aid = aid))

		photo = s.query(Photo).filter_by(album_id=aid, id=pid)[0]

		photo.display_name = request.params.get("title")
		photo.hidden = bool(request.params.get("hide_photo", 0))

		s.commit()

		redirect(url(controller="album",
					action = "show_first_page", aid = aid))
Exemplo n.º 9
0
	def _get_albums(self, aid, page):
		"""
		Return Page for albums
		"""
		albums_q = s.query(Album).filter(Album.parent_id == aid)
		# hide albums only for guests
		if not c.admin:
			albums_q = albums_q.filter(Album.hidden == False)

		def _get_page_url(page, partial=None):
			return url(controller = "album", action = "show_page",
							aid = aid, page = page)
					
		return Page(albums_q, page = page,
			items_per_page = 8, url = _get_page_url)
Exemplo n.º 10
0
	def get_photo_ajax(self, aid, pid):
		pid = int(pid)
		c.u = utils

		c.album = s.query(Album).filter(Album.id == aid).first()
		if not c.album:
			abort(404)

		all_ph, c.photos = self._get_photos(aid, 1, "show_page", 16)

		try:
			c.pnav = PhotosNav(all_ph, pid)
		except PhotosNavError:
			abort(404)

		return render("/album-getphoto.mako")
Exemplo n.º 11
0
	def show_photo(self, aid, page, pid):
		pid = int(pid)
		c.u = utils
		c.album = s.query(Album).filter(Album.id == aid).first()
		if not c.album:
			abort(404)

		c.albums = self._get_albums(aid, page)
		all_ph, c.photos = self._get_photos(aid, page, "show_page", 16)

		try:
			c.pnav = PhotosNav(all_ph, pid)
		except PhotosNavError:
			abort(404)

		c.photo = c.pnav.photo
		c.counts = self._get_counts(c.album)

		return render("/album.mako")
Exemplo n.º 12
0
	def _get_photos(self, aid, page, act, items_per_page):
		"""
		Return Page for photos
		"""
		photos_q = s.query(Photo).filter(Photo.album_id == aid)
		# hide photos only for guests
		if not c.admin:
			photos_q = photos_q.filter(Photo.hidden == False)
		if c.album.sort_by == utils.SORT_BY_DATE:
			photos_q = photos_q.order_by(Photo.created)
		elif c.album.sort_by == utils.SORT_BY_DATE_DESC:
			photos_q = photos_q.order_by(Photo.created.desc())

		def _get_page_url(page, partial=None):
			return url(controller = "album", action = act,
						aid = aid, page = page)
		all_photos = photos_q.all()
		return (all_photos, Page(all_photos, page = page,
			items_per_page = items_per_page, url = _get_page_url))
Exemplo n.º 13
0
	def album_edit_submit(self, aid):
		if request.params.get("Cancel"):
			redirect(url(controller="album"))

		if request.params.get("new_album"):
			album = Album(parent_id = aid)
			s.add(album)
			s.commit()

		else:
			album = s.query(Album).filter(Album.id == aid).first()
			if not album:
				abort(404)

		album.name = request.params.get("name")
		album.display_name = request.params.get("title")
		album.descr = request.params.get("description")
		album.hidden = bool(request.params.get("hide_album", 0))
		album.sort_by = int(request.params.get("sort_by", 1))

		new_thumb = request.params.get('album_thumbnail')
		print new_thumb, repr(new_thumb)
		if type(new_thumb) is types.InstanceType:
			old_preview = album.preview

			# add preview
			name = new_thumb.filename.lstrip(os.sep)
			preview = Photo(name, album.id, new_thumb.file.read())
			new_thumb.file.close()
			preview.hidden = True
			s.add(preview)
			s.commit()

			album.preview_id = preview.id
			if old_preview:
				s.delete(old_preview)

		s.commit()

		redirect(url(controller = "album",
				action = "show_first_page", aid = aid))
Exemplo n.º 14
0
	def photo_edit(self, aid, pid):
		c.photo = s.query(Photo).filter_by(album_id=aid, id=pid)[0]
		
		return render('/photo_edit.mako')