authors.py
41 lines
| 1.3 KiB
| text/x-python
|
PythonLexer
|
r1420 | import os | ||
|
r551 | from django.shortcuts import render | ||
|
r1420 | import neboard | ||
|
r551 | from boards.authors import authors | ||
|
r1424 | from boards.utils import cached_result | ||
|
r551 | from boards.views.base import BaseBoardView | ||
|
r1420 | from boards.models import Post | ||
PARAM_AUTHORS = 'authors' | ||||
PARAM_MEDIA_SIZE = 'media_size' | ||||
PARAM_POST_COUNT = 'post_count' | ||||
|
r1618 | PARAM_POST_PER_DAY = 'post_per_day' | ||
PARAM_POST_PER_WEEK = 'post_per_week' | ||||
PARAM_POST_PER_MONTH = 'post_per_month' | ||||
|
r551 | |||
|
r561 | |||
|
r551 | class AuthorsView(BaseBoardView): | ||
def get(self, request): | ||||
|
r918 | params = dict() | ||
|
r1420 | params[PARAM_AUTHORS] = authors | ||
params[PARAM_MEDIA_SIZE] = self._get_directory_size(neboard.settings.MEDIA_ROOT) | ||||
params[PARAM_POST_COUNT] = Post.objects.count() | ||||
|
r551 | |||
|
r1618 | params[PARAM_POST_PER_DAY] = Post.objects.get_post_per_days(1) | ||
params[PARAM_POST_PER_WEEK] = Post.objects.get_post_per_days(7) | ||||
params[PARAM_POST_PER_MONTH] = Post.objects.get_post_per_days(30) | ||||
|
r918 | return render(request, 'boards/authors.html', params) | ||
|
r1420 | |||
|
r1424 | @cached_result() | ||
|
r1420 | def _get_directory_size(self, directory): | ||
total_size = 0 | ||||
for dirpath, dirnames, filenames in os.walk(directory): | ||||
for f in filenames: | ||||
fp = os.path.join(dirpath, f) | ||||
total_size += os.path.getsize(fp) | ||||
return total_size | ||||