Пример #1
0
	def default(self):
		"""
		Default action fetches all the stats and renders a template using them
		"""
		stats = {}

		# get all the thumbnails
		stats["Database stats"] = [
			("Number of marked files", Photo.get_num_marked_photos(), "raw"),
			("Number of DB files", Photo.get_count_by_date(), "raw")
		]

		stats["File System stats"] = []
		for s in [Photo.SMALL_THUMB_SIZE, Photo.MEDIUM_THUMB_SIZE]:
			stats["File System stats"].extend(self._thumb_info(s))
			
		num_images = 0
		total_size = 0
		for root, dirs, files in os.walk(S.BASE_FS_PATH):
			for f in files:
				if util.is_image_file(f):
					num_images += 1
					total_size += os.path.getsize(os.path.join(root, f))
		stats["File System stats"].extend([
			("Number of source images", num_images, "raw"),
			("Disk space", total_size, "bytes")
		])

		return self.construct_response(Template.render("stats.html", {"stats": stats}))
Пример #2
0
    def default(self):
        """
		Default action fetches all the stats and renders a template using them
		"""
        stats = {}

        # get all the thumbnails
        stats["Database stats"] = [
            ("Number of marked files", Photo.get_num_marked_photos(), "raw"),
            ("Number of DB files", Photo.get_count_by_date(), "raw")
        ]

        stats["File System stats"] = []
        for s in [Photo.SMALL_THUMB_SIZE, Photo.MEDIUM_THUMB_SIZE]:
            stats["File System stats"].extend(self._thumb_info(s))

        num_images = 0
        total_size = 0
        for root, dirs, files in os.walk(S.BASE_FS_PATH):
            for f in files:
                if util.is_image_file(f):
                    num_images += 1
                    total_size += os.path.getsize(os.path.join(root, f))
        stats["File System stats"].extend([
            ("Number of source images", num_images, "raw"),
            ("Disk space", total_size, "bytes")
        ])

        return self.construct_response(
            Template.render("stats.html", {"stats": stats}))
Пример #3
0
	def get_photos_from_date(self):
		"""
		Fetches a list of photos which apply to the given filter

		This function should be able to handle listing directories (for instance,
		month directories in the year or days in each month) as well as actually
		rendering photos.
		"""
		year, month, day = self._get_id_from_path("").split(os.sep)

		offset = self._get_from_query("page", 1) - 1
		limit = self._get_from_query("limit", S.DEFAULT_PER_PAGE)

		num_photos = Photo.get_count_by_date(year=year, month=month, day=day)
		start_index = (offset * limit) + 1
		end_index = min(((offset + 1) * limit), num_photos)

		photos = Photo.get_by_date(year=year, month=month, day=day, limit=limit,
			offset=(offset * limit))
		tokens = {
			"photos": photos,
			"offset": offset,
			"limit": limit,
			"start_index": start_index,
			"end_index": end_index,
			"num_photos": num_photos
		}
		return self.construct_response(Template.render("photos/list.html", tokens))
Пример #4
0
    def get_photos_from_date(self):
        """
		Fetches a list of photos which apply to the given filter

		This function should be able to handle listing directories (for instance,
		month directories in the year or days in each month) as well as actually
		rendering photos.
		"""
        year, month, day = self._get_id_from_path("").split(os.sep)

        offset = self._get_from_query("page", 1) - 1
        limit = self._get_from_query("limit", S.DEFAULT_PER_PAGE)

        num_photos = Photo.get_count_by_date(year=year, month=month, day=day)
        start_index = (offset * limit) + 1
        end_index = min(((offset + 1) * limit), num_photos)

        photos = Photo.get_by_date(year=year,
                                   month=month,
                                   day=day,
                                   limit=limit,
                                   offset=(offset * limit))
        tokens = {
            "photos": photos,
            "offset": offset,
            "limit": limit,
            "start_index": start_index,
            "end_index": end_index,
            "num_photos": num_photos
        }
        return self.construct_response(
            Template.render("photos/list.html", tokens))