Example #1
0
	def _get_counts(self, album):
		# get photo counts
		photo_counts = s.execute("SELECT albums.id AS aid, COUNT(*) FROM albums JOIN "
					"photos ON album_id=albums.id "
					"WHERE albums.parent_id=%d GROUP BY photos.album_id;" % int(album.id)).fetchall()
		photo_counts = dict(photo_counts)

		# get album counts
		album_counts = s.execute("SELECT albums1.id AS aid, COUNT(*) AS count "
						"FROM albums albums1 JOIN albums albums2 ON "
						"albums2.parent_id=albums1.id "
						"WHERE albums1.parent_id=%d and (albums2.hidden=0 or %d) "
						"GROUP BY albums2.parent_id;" % (int(album.id), int(c.admin))).fetchall()
		album_counts = dict(album_counts)

		counts = {}
		for a in c.album.albums:
			counts[a.id] = (album_counts.get(a.id, 0), photo_counts.get(a.id, 0))
		return counts