merging from rep in production

This commit is contained in:
oslomp
2019-02-15 17:41:40 +01:00
30 changed files with 733 additions and 180 deletions

10
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,10 @@
before_script:
- apt-get -qq update
- apt-get -qq install -y python3 python3-venv python3-pip
- python3 -m venv venv
- source venv/bin/activate
- pip install -r requirements.txt pylint
pylint:
script:
- pylint marietje/marietje marietje/metrics marietje/playerapi marietje/queues marietje/songs marietje/stats

View File

@ -111,7 +111,7 @@ def songs(request):
except EmptyPage:
songs = paginator.page(paginator.num_pages)
songs_dict = [song_to_dict(song, user=True) for song in songs.object_list]
songs_dict = [song_to_dict(song, include_user=True) for song in songs.object_list]
return JsonResponse({
'per_page': pagesize,
'current_page': page,

View File

@ -5,9 +5,6 @@ from django.utils.translation import ugettext_lazy as _
class AuthenticationForm(BaseAuthenticationForm):
def __init__(self, request=None, *args, **kwargs):
super(AuthenticationForm, self).__init__(request, *args, **kwargs)
def confirm_login_allowed(self, user):
if user.activation_token:
raise forms.ValidationError(

View File

@ -1,14 +1,14 @@
from django.db import models
from queues.models import Queue
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
from django.contrib.auth.hashers import make_password
from django.contrib.auth.models import PermissionsMixin
from django.contrib.auth.validators import ASCIIUsernameValidator, UnicodeUsernameValidator
from django.core.mail import send_mail
from django.db import models
from django.utils import six, timezone
from django.utils.translation import ugettext_lazy as _
from django.core.mail import send_mail
from marietje.utils import get_first_queue
from queues.models import Queue
class UserManager(BaseUserManager):

View File

@ -62,7 +62,7 @@ DATABASES = {
'PASSWORD': 'v8TzZwdAdSi7Tk5I',
'HOST': 'localhost',
'PORT': '3306',
'OPTIONS': { 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'" },
'OPTIONS': {'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"},
}
}
@ -95,12 +95,17 @@ CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': '/var/tmp/MarietjeDjango_cache/default',
'OPTIONS': { 'MAX_ENTRIES': 1000 },
'OPTIONS': {'MAX_ENTRIES': 1000},
},
'song_search': {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': '/var/tmp/MarietjeDjango_cache/song_search',
'OPTIONS': { 'MAX_ENTRIES': 1000 },
'OPTIONS': {'MAX_ENTRIES': 1000},
},
'userstats': {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': '/var/tmp/MarietjeDjango_cache/default',
'OPTIONS': {'MAX_ENTRIES': 1500},
},
'userstats': {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
@ -144,8 +149,8 @@ CONTACT_EMAIL = 'marietje@science.ru.nl'
STATS_TOP_COUNT = 50
STATS_REQUEST_IGNORE_USER_IDS = []
ISSUES_URL = 'https://gitlab.science.ru.nl/Marietje/MarietjeDjango/issues'
MERGE_REQUESTS_URL = 'https://gitlab.science.ru.nl/Marietje/MarietjeDjango/merge_requests'
ISSUES_URL = 'https://gitlab.science.ru.nl/dsprenkels/MarietjeDjango/issues'
MERGE_REQUESTS_URL = 'https://gitlab.science.ru.nl/dsprenkels/MarietjeDjango/merge_requests'
TRUSTED_IP_RANGES = [
'131.174.0.0/16', # RU wired
'145.116.136.0/22', # eduroam

View File

@ -23,10 +23,9 @@ footer {
}
.marietjequeue {
color: #777777;"
color: #777777;
}
.marietjequeuestart {
.marietjequeue-start {
border-top: 4px double #777777;
color: #777777;"
}

View File

@ -52,6 +52,9 @@ $(function () {
createAlert('danger', 'Please enter a message.');
return false
}
if (message == null) {
return false
}
$.post('/api/report', {id: songId, msg: message, csrfmiddlewaretoken: csrf_token}, function (result) {
if (result.success) {
createAlert('success', 'Thanks for your song report!');
@ -198,14 +201,15 @@ function renderQueue(playNextAt, now)
var requestedBy = song.requested_by;
var reqMarietje = requestedBy != 'Marietje';
var startMarietje = false
//checks if id is the last item and returns false if the next song is Marietje, while the current song is not.
//checks if id is the last item and returns false if the next song is Marietje, while the current song is not.
if(id === queue.length-1){
var requestNext = false
} else {
var requestNext = !((queue[id+1].requested_by === 'Marietje') && (requestedBy !== 'Marietje'))
}
//checks if id is the first item and returns false if the previous song is not Marietje, while the current song is.
//checks if id is the first item and returns false if the previous song is not Marietje, while the current song is.
if(id === 0){
var requestPrev = false
} else {
@ -226,7 +230,7 @@ function renderQueue(playNextAt, now)
var artist = song.song.artist.trim() === '' ? '?' : song.song.artist;
var title = song.song.title.trim() === '' ? '?' : song.song.title;
var marietjeclass = reqMarietje ? '' : ' class="marietjequeue"';
var marietjestartclass = startMarietje ? ' class="marietjequeuestart"' : '';
var marietjestartclass = startMarietje ? ' class="marietjequeue marietjequeue-start"' : '';
showTime = showTimeToPlay ? (timeToPlay < 0 ? '' : timeToPlay.secondsToMMSS()) : (playNextAt < now ? '' : playNextAt.timestampToHHMMSS())

View File

@ -1,10 +1,13 @@
import socket, struct, binascii
import binascii
import socket
import struct
from django.conf import settings
from queues.models import Queue, Playlist
from django.http import StreamingHttpResponse
from queues.models import Queue, Playlist
def song_to_dict(song, hash=False, user=False, replaygain=False):
def song_to_dict(song, include_hash=False, include_user=False, include_replaygain=False, **options):
data = {
'id': song.id,
'artist': song.artist,
@ -12,13 +15,13 @@ def song_to_dict(song, hash=False, user=False, replaygain=False):
'duration': song.duration,
}
if hash:
if include_hash:
data['hash'] = song.hash
if user is not None and song.user is not None and song.user.name:
if include_user is not None and song.user is not None and song.user.name:
data['uploader_name'] = song.user.name
if replaygain:
if include_replaygain:
data['rg_gain'] = song.rg_gain
data['rg_peak'] = song.rg_peak
@ -44,9 +47,9 @@ def send_to_bertha(file):
for chunk in file.chunks():
sock.sendall(chunk)
sock.shutdown(socket.SHUT_WR)
hash = binascii.hexlify(sock.recv(64))
song_hash = binascii.hexlify(sock.recv(64))
sock.close()
return hash
return song_hash
def get_first_queue():
@ -61,10 +64,10 @@ def get_first_queue():
return queue
def bertha_stream(hash):
def bertha_stream(song_hash):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(settings.BERTHA_HOST)
sock.sendall(struct.pack("<B", 2) + binascii.unhexlify(hash))
sock.sendall(struct.pack("<B", 2) + binascii.unhexlify(song_hash))
data = sock.recv(4096)
while data:
yield data
@ -72,7 +75,7 @@ def bertha_stream(hash):
sock.close()
def get_from_bertha(hash):
response = StreamingHttpResponse(bertha_stream(hash))
response['Content-Disposition'] = 'attachment; filename="{}"'.format(hash)
def get_from_bertha(song_hash):
response = StreamingHttpResponse(bertha_stream(song_hash))
response['Content-Disposition'] = 'attachment; filename="{}"'.format(song_hash)
return response

View File

@ -8,8 +8,7 @@ from django.core.mail import send_mail
from django.shortcuts import render, redirect, get_object_or_404
from django.urls import reverse
from marietje.utils import get_first_queue
from .forms import RegistrationForm, ResetPasswordForm
from .forms import ResetPasswordForm
def register(request):

View File

@ -1,3 +0,0 @@
from django.contrib import admin
# Register your models here.

View File

@ -1,3 +0,0 @@
from django.db import models
# Create your models here.

View File

@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View File

@ -1,4 +1,3 @@
from django.db.models import Count, Q
from django.http import HttpResponse
from django.db.utils import OperationalError
@ -16,13 +15,12 @@ queue_users_gauge = Gauge('marietje_queue_users', 'Users holding a queue at some
try:
for queue in Queue.objects.all():
def _get_queue_length():
return (PlaylistSong.objects.filter(playlist=queue.playlist_id, state=0)
.count())
return PlaylistSong.objects.filter(playlist=queue.playlist_id, state=0).count()
def _get_queue_duration():
playlist_songs = (PlaylistSong.objects.filter(playlist=queue.playlist_id, state=0)
.select_related('song')
.all())
.select_related('song')
.all())
return sum(ps.song.duration for ps in playlist_songs)
def _get_queue_distinct_users():
@ -31,7 +29,7 @@ try:
# that much of confidence that it would also work on mysql.
# Furtermore, we do not expect the queue to be very long at any moment.
return len(set(PlaylistSong.objects.filter(playlist=queue.playlist_id, state=0)
.values_list('user')))
.values_list('user')))
queue_length_gauge.labels(name=queue).set_function(_get_queue_length)
queue_duration_gauge.labels(name=queue).set_function(_get_queue_duration)

View File

@ -1,3 +0,0 @@
from django.contrib import admin
# Register your models here.

View File

@ -1,3 +0,0 @@
from django.db import models
# Create your models here.

View File

@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View File

@ -14,16 +14,16 @@ from .decorators import token_required
@csrf_exempt
@token_required
def queue(request):
queue = get_object_or_404(Queue, id=request.POST.get('queue'))
current_queue = get_object_or_404(Queue, id=request.POST.get('queue'))
commands = queue.queuecommand_set.filter(executed=False)
commands = current_queue.queuecommand_set.filter(executed=False)
for command in commands:
command.executed = True
command.save()
return JsonResponse({
'current_song': playlist_song_to_dict(queue.current_song(), hash=True, replaygain=True),
'queue': [playlist_song_to_dict(playlist_song, hash=True, replaygain=True) for playlist_song in queue.queue()[:1]],
'current_song': playlist_song_to_dict(current_queue.current_song(), include_hash=True, include_replaygain=True),
'queue': [playlist_song_to_dict(playlist_song, include_hash=True, include_replaygain=True) for playlist_song in current_queue.queue()[:1]],
'commands': [command.command for command in commands]
})
@ -31,9 +31,9 @@ def queue(request):
@csrf_exempt
@token_required
def play(request):
queue = get_object_or_404(Queue, id=request.POST.get('queue'))
queue.started_at = timezone.now()
queue.save()
current_queue = get_object_or_404(Queue, id=request.POST.get('queue'))
current_queue.started_at = timezone.now()
current_queue.save()
current_song = queue.current_song()
current_song.played_at = queue.started_at
current_song.save()
@ -41,11 +41,12 @@ def play(request):
return JsonResponse({})
# pylint: disable=redefined-builtin
@csrf_exempt
@token_required
def next(request):
queue = get_object_or_404(Queue, id=request.POST.get('queue'))
player_song = queue.current_song()
current_queue = get_object_or_404(Queue, id=request.POST.get('queue'))
player_song = current_queue.current_song()
player_song.state = 2
player_song.save()
return JsonResponse({})

View File

@ -1,7 +1,5 @@
import time
from django.db import models
from django.db.models import Q, Max
from django.db.models import Q
from django.conf import settings
from django.utils import timezone
@ -99,7 +97,7 @@ class Queue(models.Model):
def current_song(self):
songs = self.get_songs()
if len(songs) < 1:
if not songs:
return None
song = songs[0]
if song.state != 1:
@ -136,7 +134,8 @@ class Queue(models.Model):
playlist_song.save()
# If the song was auto-queue'd, then remove it from the auto-queue
autolist_songs = PlaylistSong.objects.filter(playlist=self.random_playlist, state=0, song=song).delete()
autolist_songs = PlaylistSong.objects.filter(playlist=self.random_playlist, state=0, song=song)
autolist_songs.delete()
return None

View File

@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View File

@ -1,8 +1,2 @@
from django.conf.urls import url
from . import views
app_name = 'queue'
urlpatterns = [
]
urlpatterns = []

View File

@ -13,7 +13,8 @@ class SongAdmin(admin.ModelAdmin):
search_fields = ('artist', 'title', 'user__name')
inlines = [ReportNoteInline]
def reports(self, song):
@staticmethod
def reports(song):
return ReportNote.objects.filter(song=song).count()
@staticmethod
@ -31,3 +32,4 @@ class SongAdmin(admin.ModelAdmin):
class ReportNoteAdmin(admin.ModelAdmin):
list_display = ('song', 'note', 'user')
search_fields = ('song__artist', 'song__title', 'user__name')
readonly_fields = ('song',)

View File

@ -43,7 +43,8 @@ class Song(models.Model):
return self.artist + ' - ' + self.title
class ReportNote(models.Model):
song = models.ForeignKey(Song,
song = models.ForeignKey(
Song,
on_delete=models.CASCADE,
blank=False,
null=False,
@ -54,7 +55,9 @@ class ReportNote(models.Model):
blank=True,
null=True,
db_index=True)
note = models.TextField(verbose_name='reason', blank=True,
note = models.TextField(
verbose_name='reason',
blank=True,
help_text='reason for edit request')
def __str__(self):

View File

@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View File

@ -1,5 +1,5 @@
from django.shortcuts import render, get_object_or_404, redirect
from django.contrib.auth.decorators import login_required, permission_required
from django.contrib.auth.decorators import login_required
from .models import Song
@ -14,8 +14,8 @@ def manage(request):
@login_required
def edit(request, id):
song = get_object_or_404(Song, pk=id, user=request.user)
def edit(request, song_id):
song = get_object_or_404(Song, pk=song_id, user=request.user)
if not request.POST:
return render(request, 'songs/edit.html', {'song': song})

View File

@ -1,3 +0,0 @@
from django.contrib import admin
# Register your models here.

View File

@ -1,3 +0,0 @@
from django.db import models
# Create your models here.

View File

@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View File

@ -1,9 +1,8 @@
from datetime import datetime, timedelta, time
from datetime import datetime, timedelta
from django.core.cache import caches
from django.conf import settings
from django.db.models import Count, Q, Sum, When, Case
from django.shortcuts import render
from django.db.models import Count, Q, Sum
from django.utils import timezone
from queues.models import PlaylistSong
@ -30,74 +29,62 @@ def recache_user_stats():
return new_stats
def time_convert(time):
try:
for tr in time:
tr['duration'] = str(round(tr['total'] / 86400, 2)) + ' days'
avg_dur_sec = tr['avg_dur'] % 60
avg_dur_min = int((tr['avg_dur'] - avg_dur_sec) / 60)
tr['avg_dur'] = '{}:{}'.format(avg_dur_min, avg_dur_sec)
return time
except:
avg_dur_sec = round(time % 60)
avg_dur_min = int(round((time - avg_dur_sec) / 60))
return ('{} minutes and {} seconds'.format(avg_dur_min, avg_dur_sec))
def calculate_uploaders(requests_uploader, most_requested_uploaders):
for x in requests_uploader:
def best_uploaders_list(requests_uploader, most_requested_uploaders):
for requests in requests_uploader:
a = len(most_requested_uploaders)
b = 0
while b <= a:
if b == a:
adding_list_item(most_requested_uploaders, x)
elif x['song__user__id'] == most_requested_uploaders[b]['id']:
if x['song__user__name'] == x['user__name']:
most_requested_uploaders[b]['own_total'] = x['total']
adding_list_item(most_requested_uploaders, requests)
elif requests[
'song__user__id'] == most_requested_uploaders[b]['id']:
if requests['song__user__name'] == requests['user__name']:
most_requested_uploaders[b][
'own_total'] = requests['total']
else:
most_requested_uploaders[b]['total'] += x['total']
most_requested_uploaders[b]['total'] += requests['total']
break
b += 1
return
def adding_list_item(list, x):
list.append({
'id': x['song__user__id'],
'name': x['song__user__name'],
def adding_list_item(most_requested_list, requests):
# adds a single item to the best_uploaders list
most_requested_list.append({
'id': requests['song__user__id'],
'name': requests['song__user__name'],
'total': 0,
'own_total': 0
})
if x['song__user__id'] == x['user__id']:
list[-1]['own_total']: x['total']
if requests['song__user__id'] == requests['user__id']:
most_requested_list[-1]['own_total'] = requests['total']
else:
list[-1]['_total']: x['total']
return
most_requested_list[-1]['total'] = requests['total']
def compute_stats():
# We want to grab the time now, because otherwise we would be reporting a minute too late
last_updated = datetime.now()
stats = {}
total_uploads = Song.objects.filter(deleted=False).exclude(
stats['total_uploads'] = Song.objects.filter(deleted=False).exclude(
user_id=None).count()
upload_stats = Song.objects.filter(deleted=False).exclude(
stats['upload_stats'] = Song.objects.filter(deleted=False).exclude(
user_id=None).values(
'user__id', 'user__name').annotate(total=Count('id')).order_by(
'-total', 'user__name')[:settings.STATS_TOP_COUNT]
total_requests = PlaylistSong.objects.filter(state=2).exclude(
stats['total_requests'] = PlaylistSong.objects.filter(state=2).exclude(
Q(user_id=None)
| Q(user_id__in=settings.STATS_REQUEST_IGNORE_USER_IDS)).count()
request_stats = PlaylistSong.objects.filter(state=2).exclude(
stats['request_stats'] = PlaylistSong.objects.filter(state=2).exclude(
Q(user_id=None)
| Q(user_id__in=settings.STATS_REQUEST_IGNORE_USER_IDS)).values(
'user__id', 'user__name').annotate(total=Count('id')).order_by(
'-total', 'user__name')[:settings.STATS_TOP_COUNT]
unique_request_stats = PlaylistSong.objects.filter(state=2).exclude(
stats['unique_request_stats'] = PlaylistSong.objects.filter(state=2).exclude(
Q(user_id=None)
| Q(user_id__in=settings.STATS_REQUEST_IGNORE_USER_IDS)).values(
'user__id', 'user__name').annotate(
@ -105,26 +92,26 @@ def compute_stats():
unique_requests=Count('song__id', distinct=True)).order_by(
'-unique_requests')[:settings.STATS_TOP_COUNT]
total_unique_requests = PlaylistSong.objects.filter(state=2).exclude(
stats['total_unique_requests'] = PlaylistSong.objects.filter(state=2).exclude(
Q(user_id=None)
| Q(user_id__in=settings.STATS_REQUEST_IGNORE_USER_IDS)).aggregate(
total=Count('song__id', distinct=True))
most_played_songs = PlaylistSong.objects.filter(state=2).exclude(
stats['most_played_songs'] = PlaylistSong.objects.filter(state=2).exclude(
Q(user_id=None)
| Q(user_id__in=settings.STATS_REQUEST_IGNORE_USER_IDS)).values(
'song__artist',
'song__title').annotate(total=Count('id')).order_by(
'-total', 'song__artist')[:settings.STATS_TOP_COUNT]
most_played_songs_14_days = PlaylistSong.objects.filter(
state=2, played_at__gte=timezone.now() - timedelta(days=14)).exclude(
user_id=None).values(
'song__artist',
'song__title').annotate(total=Count('id')).order_by(
'-total', 'song__artist')[:settings.STATS_TOP_COUNT]
stats['most_played_songs_14_days'] = PlaylistSong.objects.filter(
state=2, played_at__gte=timezone.now() -
timedelta(days=14)).exclude(user_id=None).values(
'song__artist',
'song__title').annotate(total=Count('id')).order_by(
'-total', 'song__artist')[:settings.STATS_TOP_COUNT]
time_requested = PlaylistSong.objects.filter(state=2).exclude(
stats['time_requested'] = PlaylistSong.objects.filter(state=2).exclude(
Q(user_id=None)
| Q(user_id__in=settings.STATS_REQUEST_IGNORE_USER_IDS)).values(
'user__id', 'user__name').annotate(
@ -132,18 +119,16 @@ def compute_stats():
avg_dur=Sum('song__duration') /
Count('id')).order_by('-total')[:settings.STATS_TOP_COUNT]
total_time_requested = PlaylistSong.objects.all().filter(state=2).exclude(
stats['total_time_requested'] = PlaylistSong.objects.all().filter(state=2).exclude(
Q(user_id=None)
| Q(user_id__in=settings.STATS_REQUEST_IGNORE_USER_IDS)).aggregate(
total=Sum('song__duration'))
total_time_overall = 0
count = 0
for x in list(time_requested):
total_time_overall += x['avg_dur']
count += 1
total_average = total_time_overall / count
total_average = time_convert(total_average)
total_time_overall = sum(x['avg_dur'] for x in list(stats['time_requested']))
total_average = total_time_overall / len(stats['time_requested'])
avg_dur_min, avg_dur_sec = divmod(total_average, 60)
total_average = '{} minutes and {} seconds'.format(
avg_dur_min, avg_dur_sec)
requests_uploader = PlaylistSong.objects.filter(state=2).exclude(
Q(user_id=None)
@ -152,20 +137,34 @@ def compute_stats():
'user__id').annotate(total=Count('song__user__name'))
most_requested_uploaders = []
calculate_uploaders(list(requests_uploader), most_requested_uploaders)
best_uploaders_list(list(requests_uploader), most_requested_uploaders)
for time in list(stats['time_requested']):
# converts total time and average time in respectively days and minutes, seconds
time['duration'] = str(round(time['total'] / 86400, 2)) + ' days'
avg_dur_min, avg_dur_sec = divmod(time['avg_dur'], 60)
if avg_dur_sec < 10:
avg_dur_sec = '0' + str(avg_dur_sec)
time['avg_dur'] = '{}:{}'.format(avg_dur_min, avg_dur_sec)
# Convert requested time to days
time_requested = list(stats['time_requested'])
for tr in time_requested:
tr['duration'] = str(round(tr['total'] / 86400, 2)) + ' days'
return {
'last_updated': last_updated,
'total_uploads': total_uploads,
'upload_stats': list(upload_stats),
'total_requests': total_requests,
'request_stats': list(request_stats),
'unique_request_stats': list(unique_request_stats),
'total_unique_requests': total_unique_requests,
'most_played_songs': list(most_played_songs),
'most_played_songs_14_days': list(most_played_songs_14_days),
'time_requested': time_convert(list(time_requested)),
'total_time_requested': str(round(float(total_time_requested['total']) / 86400, 2)) + ' days',
'total_uploads': stats['total_uploads'],
'upload_stats': list(stats['upload_stats']),
'total_requests': stats['total_requests'],
'request_stats': list(stats['request_stats']),
'unique_request_stats': list(stats['unique_request_stats']),
'total_unique_requests': stats['total_unique_requests'],
'most_played_songs': list(stats['most_played_songs']),
'most_played_songs_14_days': list(stats['most_played_songs_14_days']),
'time_requested': stats['time_requested'],
'total_time_requested': str(round(float(
stats['total_time_requested']['total']) / 86400, 2)) + ' days',
'stats_top_count': settings.STATS_TOP_COUNT,
'most_requested_uploaders': list(most_requested_uploaders),
'total_average': total_average,
@ -228,4 +227,4 @@ def user_stats(request):
'stats_top_count': settings.STATS_TOP_COUNT,
'total_played_uploads': total_played_uploads,
'total_played_user_uploads': total_played_user_uploads,
}
}

View File

@ -2,34 +2,33 @@ from datetime import datetime, timedelta
from django.core.cache import caches
from django.shortcuts import render
from stats.utils import user_stats
from django.http import JsonResponse, HttpResponseForbidden
def stats(request):
stats = caches['default'].get('stats')
stats_data = caches['default'].get('stats')
status = 503
current_age = None
current_age_text = None
if stats:
if stats_data:
status = 200
current_age_text = age_text(stats['last_updated'])
current_age_text = age_text(stats_data['last_updated'])
data = {'stats': stats, 'current_age': current_age, 'current_age_text': current_age_text}
data = {'stats': stats_data, 'current_age': current_age, 'current_age_text': current_age_text}
return render(request, 'stats/stats.html', data, status=status)
def user_stats(request):
stats = caches['userstats'].get('userstats_{}'.format(request.user.id))
stats_data = caches['default'].get('userstats_{}'.format(request.user.id))
status = 503
current_age = None
current_age_text = None
if stats:
if stats_data:
status = 200
current_age_text = age_text(stats['last_updated'])
current_age_text = age_text(stats_data['last_updated'])
data = {'stats': stats, 'current_age': current_age, 'current_age_text': current_age_text}
data = {'stats': stats_data, 'current_age': current_age, 'current_age_text': current_age_text}
return render(request, 'stats/user.html', data, status=status)
def age_text(last_updated):
@ -40,7 +39,6 @@ def age_text(last_updated):
hourstr = "hour" if hours == 1 else "hours"
if current_age < timedelta(hours=1):
return 'Stats were updated {:.0f} {} ago.'.format(minutes, minutestr)
else:
return 'Stats were updated {:.0f} {} and {:.0f} {} ago.'.format(
hours, hourstr, minutes, minutestr)
return 'Stats were updated {:.0f} {} and {:.0f} {} ago.'.format(
hours, hourstr, minutes, minutestr)

575
pylintrc Normal file
View File

@ -0,0 +1,575 @@
[MASTER]
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code.
extension-pkg-whitelist=
# Add files or directories to the blacklist. They should be base names, not
# paths.
ignore=migrations
# Add files or directories matching the regex patterns to the blacklist. The
# regex matches against base names, not paths.
ignore-patterns=
# Python code to execute, usually for sys.path manipulation such as
# pygtk.require().
#init-hook=
# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the
# number of processors available to use.
jobs=1
# Control the amount of potential inferred values when inferring a single
# object. This can help the performance when dealing with large functions or
# complex, nested conditions.
limit-inference-results=100
# List of plugins (as comma separated values of python modules names) to load,
# usually to register additional checkers.
load-plugins=
# Pickle collected data for later comparisons.
persistent=yes
# Specify a configuration file.
#rcfile=
# When enabled, pylint would attempt to guess common misconfiguration and emit
# user-friendly hints instead of false-positive error messages.
suggestion-mode=yes
# Allow loading of arbitrary C extensions. Extensions are imported into the
# active Python interpreter and may run arbitrary code.
unsafe-load-any-extension=no
[MESSAGES CONTROL]
# Only show warnings with the listed confidence levels. Leave empty to show
# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED.
confidence=
# Disable the message, report, category or checker with the given id(s). You
# can either give multiple identifiers separated by comma (,) or put this
# option multiple times (only on the command line, not in the configuration
# file where it should appear only once). You can also use "--disable=all" to
# disable everything first and then reenable specific checks. For example, if
# you want to run only the similarities checker, you can use "--disable=all
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use "--disable=all --enable=classes
# --disable=W".
disable=missing-docstring,
line-too-long,
no-member,
parameter-unpacking,
unpacking-in-except,
backtick,
long-suffix,
old-ne-operator,
old-octal-literal,
import-star-module-level,
non-ascii-bytes-literal,
raw-checker-failed,
bad-inline-option,
locally-disabled,
file-ignored,
suppressed-message,
useless-suppression,
deprecated-pragma,
use-symbolic-message-instead,
apply-builtin,
basestring-builtin,
buffer-builtin,
cmp-builtin,
coerce-builtin,
execfile-builtin,
file-builtin,
long-builtin,
raw_input-builtin,
reduce-builtin,
standarderror-builtin,
unicode-builtin,
xrange-builtin,
coerce-method,
delslice-method,
getslice-method,
setslice-method,
no-absolute-import,
old-division,
dict-iter-method,
dict-view-method,
next-method-called,
metaclass-assignment,
indexing-exception,
raising-string,
reload-builtin,
oct-method,
hex-method,
nonzero-method,
cmp-method,
input-builtin,
round-builtin,
intern-builtin,
unichr-builtin,
map-builtin-not-iterating,
zip-builtin-not-iterating,
range-builtin-not-iterating,
filter-builtin-not-iterating,
using-cmp-argument,
eq-without-hash,
div-method,
idiv-method,
rdiv-method,
exception-message-attribute,
invalid-str-codec,
sys-max-int,
bad-python3-import,
deprecated-string-function,
deprecated-str-translate-call,
deprecated-itertools-function,
deprecated-types-field,
next-method-defined,
dict-items-not-iterating,
dict-keys-not-iterating,
dict-values-not-iterating,
deprecated-operator-function,
deprecated-urllib-function,
xreadlines-attribute,
deprecated-sys-function,
exception-escape,
comprehension-escape,
# Extra added specifically for this project
access-member-before-definition,
arguments-differ,
attribute-defined-outside-init,
cell-var-from-loop,
duplicate-code,
invalid-name,
missing-format-attribute,
too-few-public-methods,
unused-argument,
# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
# multiple time (only on the command line, not in the configuration file where
# it should appear only once). See also the "--disable" option for examples.
enable=c-extension-no-member
[REPORTS]
# Python expression which should return a note less than 10 (10 is the highest
# note). You have access to the variables errors warning, statement which
# respectively contain the number of errors / warnings messages and the total
# number of statements analyzed. This is used by the global evaluation report
# (RP0004).
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
# Template used to display messages. This is a python new-style format string
# used to format the message information. See doc for all details.
#msg-template=
# Set the output format. Available formats are text, parseable, colorized, json
# and msvs (visual studio). You can also give a reporter class, e.g.
# mypackage.mymodule.MyReporterClass.
output-format=text
# Tells whether to display a full report or only the messages.
reports=no
# Activate the evaluation score.
score=yes
[REFACTORING]
# Maximum number of nested blocks for function / method body
max-nested-blocks=5
# Complete name of functions that never returns. When checking for
# inconsistent-return-statements if a never returning function is called then
# it will be considered as an explicit return statement and no message will be
# printed.
never-returning-functions=sys.exit
[VARIABLES]
# List of additional names supposed to be defined in builtins. Remember that
# you should avoid defining new builtins when possible.
additional-builtins=
# Tells whether unused global variables should be treated as a violation.
allow-global-unused-variables=yes
# List of strings which can identify a callback function by name. A callback
# name must start or end with one of those strings.
callbacks=cb_,
_cb
# A regular expression matching the name of dummy variables (i.e. expected to
# not be used).
dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_
# Argument names that match this expression will be ignored. Default to name
# with leading underscore.
ignored-argument-names=_.*|^ignored_|^unused_
# Tells whether we should check for unused import in __init__ files.
init-import=no
# List of qualified module names which can have objects that can redefine
# builtins.
redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io
[TYPECHECK]
# List of decorators that produce context managers, such as
# contextlib.contextmanager. Add to this list to register other decorators that
# produce valid context managers.
contextmanager-decorators=contextlib.contextmanager
# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E1101 when accessed. Python regular
# expressions are accepted.
generated-members=
# Tells whether missing members accessed in mixin class should be ignored. A
# mixin class is detected if its name ends with "mixin" (case insensitive).
ignore-mixin-members=yes
# Tells whether to warn about missing members when the owner of the attribute
# is inferred to be None.
ignore-none=yes
# This flag controls whether pylint should warn about no-member and similar
# checks whenever an opaque object is returned when inferring. The inference
# can return multiple potential results while evaluating a Python object, but
# some branches might not be evaluated, which results in partial inference. In
# that case, it might be useful to still emit no-member and other checks for
# the rest of the inferred objects.
ignore-on-opaque-inference=yes
# List of class names for which member attributes should not be checked (useful
# for classes with dynamically set attributes). This supports the use of
# qualified names.
ignored-classes=optparse.Values,thread._local,_thread._local
# List of module names for which member attributes should not be checked
# (useful for modules/projects where namespaces are manipulated during runtime
# and thus existing member attributes cannot be deduced by static analysis. It
# supports qualified module names, as well as Unix pattern matching.
ignored-modules=
# Show a hint with possible names when a member name was not found. The aspect
# of finding the hint is based on edit distance.
missing-member-hint=yes
# The minimum edit distance a name should have in order to be considered a
# similar match for a missing member name.
missing-member-hint-distance=1
# The total number of similar names that should be taken in consideration when
# showing a hint for a missing member.
missing-member-max-choices=1
[SPELLING]
# Limits count of emitted suggestions for spelling mistakes.
max-spelling-suggestions=4
# Spelling dictionary name. Available dictionaries: none. To make it working
# install python-enchant package..
spelling-dict=
# List of comma separated words that should not be checked.
spelling-ignore-words=
# A path to a file that contains private dictionary; one word per line.
spelling-private-dict-file=
# Tells whether to store unknown words to indicated private dictionary in
# --spelling-private-dict-file option instead of raising a message.
spelling-store-unknown-words=no
[SIMILARITIES]
# Ignore comments when computing similarities.
ignore-comments=yes
# Ignore docstrings when computing similarities.
ignore-docstrings=yes
# Ignore imports when computing similarities.
ignore-imports=no
# Minimum lines number of a similarity.
min-similarity-lines=4
[MISCELLANEOUS]
# List of note tags to take in consideration, separated by a comma.
notes=FIXME,
XXX,
TODO
[LOGGING]
# Format style used to check logging format string. `old` means using %
# formatting, while `new` is for `{}` formatting.
logging-format-style=old
# Logging modules to check that the string format arguments are in logging
# function parameter format.
logging-modules=logging
[FORMAT]
# Expected format of line ending, e.g. empty (any line ending), LF or CRLF.
expected-line-ending-format=
# Regexp for a line that is allowed to be longer than the limit.
ignore-long-lines=^\s*(# )?<?https?://\S+>?$
# Number of spaces of indent required inside a hanging or continued line.
indent-after-paren=4
# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
# tab).
indent-string=' '
# Maximum number of characters on a single line.
max-line-length=100
# Maximum number of lines in a module.
max-module-lines=1000
# List of optional constructs for which whitespace checking is disabled. `dict-
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
# `empty-line` allows space-only lines.
no-space-check=trailing-comma,
dict-separator
# Allow the body of a class to be on the same line as the declaration if body
# contains single statement.
single-line-class-stmt=no
# Allow the body of an if to be on the same line as the test if there is no
# else.
single-line-if-stmt=no
[BASIC]
# Naming style matching correct argument names.
argument-naming-style=snake_case
# Regular expression matching correct argument names. Overrides argument-
# naming-style.
#argument-rgx=
# Naming style matching correct attribute names.
attr-naming-style=snake_case
# Regular expression matching correct attribute names. Overrides attr-naming-
# style.
#attr-rgx=
# Bad variable names which should always be refused, separated by a comma.
bad-names=foo,
bar,
baz,
toto,
tutu,
tata,
blah,
bla
# Naming style matching correct class attribute names.
class-attribute-naming-style=any
# Regular expression matching correct class attribute names. Overrides class-
# attribute-naming-style.
#class-attribute-rgx=
# Naming style matching correct class names.
class-naming-style=PascalCase
# Regular expression matching correct class names. Overrides class-naming-
# style.
#class-rgx=
# Naming style matching correct constant names.
const-naming-style=UPPER_CASE
# Regular expression matching correct constant names. Overrides const-naming-
# style.
#const-rgx=
# Minimum line length for functions/classes that require docstrings, shorter
# ones are exempt.
docstring-min-length=50
# Naming style matching correct function names.
function-naming-style=snake_case
# Regular expression matching correct function names. Overrides function-
# naming-style.
#function-rgx=
# Good variable names which should always be accepted, separated by a comma.
good-names=i,
j,
k,
ex,
Run,
x, y, z,
_
# Include a hint for the correct naming format with invalid-name.
include-naming-hint=no
# Naming style matching correct inline iteration names.
inlinevar-naming-style=any
# Regular expression matching correct inline iteration names. Overrides
# inlinevar-naming-style.
#inlinevar-rgx=
# Naming style matching correct method names.
method-naming-style=snake_case
# Regular expression matching correct method names. Overrides method-naming-
# style.
#method-rgx=
# Naming style matching correct module names.
module-naming-style=snake_case
# Regular expression matching correct module names. Overrides module-naming-
# style.
#module-rgx=
# Colon-delimited sets of names that determine each other's naming style when
# the name regexes allow several styles.
name-group=
# Regular expression which should only match function or class names that do
# not require a docstring.
no-docstring-rgx=^_
# List of decorators that produce properties, such as abc.abstractproperty. Add
# to this list to register other decorators that produce valid properties.
# These decorators are taken in consideration only for invalid-name.
property-classes=abc.abstractproperty
# Naming style matching correct variable names.
variable-naming-style=snake_case
# Regular expression matching correct variable names. Overrides variable-
# naming-style.
#variable-rgx=
[IMPORTS]
# Allow wildcard imports from modules that define __all__.
allow-wildcard-with-all=no
# Analyse import fallback blocks. This can be used to support both Python 2 and
# 3 compatible code, which means that the block might have code that exists
# only in one or another interpreter, leading to false positives when analysed.
analyse-fallback-blocks=no
# Deprecated modules which should not be used, separated by a comma.
deprecated-modules=optparse,tkinter.tix
# Create a graph of external dependencies in the given file (report RP0402 must
# not be disabled).
ext-import-graph=
# Create a graph of every (i.e. internal and external) dependencies in the
# given file (report RP0402 must not be disabled).
import-graph=
# Create a graph of internal dependencies in the given file (report RP0402 must
# not be disabled).
int-import-graph=
# Force import order to recognize a module as part of the standard
# compatibility libraries.
known-standard-library=
# Force import order to recognize a module as part of a third party library.
known-third-party=enchant
[DESIGN]
# Maximum number of arguments for function / method.
max-args=5
# Maximum number of attributes for a class (see R0902).
max-attributes=7
# Maximum number of boolean expressions in an if statement.
max-bool-expr=5
# Maximum number of branch for function / method body.
max-branches=12
# Maximum number of locals for function / method body.
max-locals=15
# Maximum number of parents for a class (see R0901).
max-parents=7
# Maximum number of public methods for a class (see R0904).
max-public-methods=20
# Maximum number of return / yield for function / method body.
max-returns=6
# Maximum number of statements in function / method body.
max-statements=50
# Minimum number of public methods for a class (see R0903).
min-public-methods=2
[CLASSES]
# List of method names used to declare (i.e. assign) instance attributes.
defining-attr-methods=__init__,
__new__,
setUp
# List of member names, which should be excluded from the protected access
# warning.
exclude-protected=_asdict,
_fields,
_replace,
_source,
_make
# List of valid names for the first argument in a class method.
valid-classmethod-first-arg=cls
# List of valid names for the first argument in a metaclass class method.
valid-metaclass-classmethod-first-arg=cls
[EXCEPTIONS]
# Exceptions that will emit a warning when being caught. Defaults to
# "Exception".
overgeneral-exceptions=Exception