authors.py
34 lines
| 950 B
| text/x-python
|
PythonLexer
neko259
|
r1420 | import os | ||
neko259
|
r551 | from django.shortcuts import render | ||
neko259
|
r1420 | import neboard | ||
neko259
|
r551 | from boards.authors import authors | ||
neko259
|
r1424 | from boards.utils import cached_result | ||
neko259
|
r551 | from boards.views.base import BaseBoardView | ||
neko259
|
r1420 | from boards.models import Post | ||
PARAM_AUTHORS = 'authors' | ||||
PARAM_MEDIA_SIZE = 'media_size' | ||||
PARAM_POST_COUNT = 'post_count' | ||||
neko259
|
r551 | |||
neko259
|
r561 | |||
neko259
|
r551 | class AuthorsView(BaseBoardView): | ||
def get(self, request): | ||||
neko259
|
r918 | params = dict() | ||
neko259
|
r1420 | params[PARAM_AUTHORS] = authors | ||
params[PARAM_MEDIA_SIZE] = self._get_directory_size(neboard.settings.MEDIA_ROOT) | ||||
params[PARAM_POST_COUNT] = Post.objects.count() | ||||
neko259
|
r551 | |||
neko259
|
r918 | return render(request, 'boards/authors.html', params) | ||
neko259
|
r1420 | |||
neko259
|
r1424 | @cached_result() | ||
neko259
|
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 | ||||