##// END OF EJS Templates
Version bump
Version bump

File last commit:

r1939:d78c60b2 default
r2019:bae74335 4.8.1 default
Show More
authors.py
60 lines | 1.9 KiB | text/x-python | PythonLexer
import os
import platform
import sys
from django.shortcuts import render
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_protect
import neboard
from boards.authors import authors
from boards.utils import cached_result
from boards.views.base import BaseBoardView
from boards.models import Post
PARAM_AUTHORS = 'authors'
PARAM_MEDIA_SIZE = 'media_size'
PARAM_POST_COUNT = 'post_count'
PARAM_POST_PER_DAY = 'post_per_day'
PARAM_POST_PER_WEEK = 'post_per_week'
PARAM_POST_PER_MONTH = 'post_per_month'
PARAM_PLATFORM = 'platform'
PARAM_PYTHON = 'python'
PARAM_HOSTS = 'hosts'
class AuthorsView(BaseBoardView):
@method_decorator(csrf_protect)
def get(self, request):
params = dict()
params[PARAM_AUTHORS] = authors
params[PARAM_MEDIA_SIZE] = self._get_directory_size(neboard.settings.MEDIA_ROOT)
params[PARAM_POST_COUNT] = Post.objects.count()
params[PARAM_PLATFORM] = platform.platform()
python_version = sys.version_info
params[PARAM_PYTHON] = '{}.{}.{}'.format(python_version.major,
python_version.minor, python_version.micro)
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)
params[PARAM_HOSTS] = self._get_host_list()
return render(request, 'boards/authors.html', params)
@cached_result()
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
@cached_result()
def _get_host_list(self):
return ['<a href="http://{}/">{}</a>'.format(host, host) for host in neboard.settings.ALLOWED_HOSTS if host != '*']