mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2026-03-24 11:54:45 +01:00
fix all pylint complaints
This commit is contained in:
@ -8,4 +8,3 @@ before_script:
|
|||||||
pylint:
|
pylint:
|
||||||
script:
|
script:
|
||||||
- pylint marietje/marietje marietje/metrics marietje/playerapi marietje/queues marietje/songs marietje/stats
|
- pylint marietje/marietje marietje/metrics marietje/playerapi marietje/queues marietje/songs marietje/stats
|
||||||
allow_failure: yes
|
|
||||||
|
|||||||
@ -111,7 +111,7 @@ def songs(request):
|
|||||||
except EmptyPage:
|
except EmptyPage:
|
||||||
songs = paginator.page(paginator.num_pages)
|
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({
|
return JsonResponse({
|
||||||
'per_page': pagesize,
|
'per_page': pagesize,
|
||||||
'current_page': page,
|
'current_page': page,
|
||||||
@ -170,7 +170,7 @@ def queue(request):
|
|||||||
queue = request.user.queue
|
queue = request.user.queue
|
||||||
return JsonResponse({
|
return JsonResponse({
|
||||||
'current_song': playlist_song_to_dict(queue.current_song()),
|
'current_song': playlist_song_to_dict(queue.current_song()),
|
||||||
'queue': [playlist_song_to_dict(playlist_song, user=request.user) for playlist_song in queue.queue()],
|
'queue': [playlist_song_to_dict(playlist_song, include_user=request.user) for playlist_song in queue.queue()],
|
||||||
'started_at': 0 if queue.started_at is None else int(queue.started_at.timestamp()),
|
'started_at': 0 if queue.started_at is None else int(queue.started_at.timestamp()),
|
||||||
'current_time': int(time.time())
|
'current_time': int(time.time())
|
||||||
})
|
})
|
||||||
|
|||||||
@ -5,9 +5,6 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
|
|
||||||
|
|
||||||
class AuthenticationForm(BaseAuthenticationForm):
|
class AuthenticationForm(BaseAuthenticationForm):
|
||||||
def __init__(self, request=None, *args, **kwargs):
|
|
||||||
super(AuthenticationForm, self).__init__(request, *args, **kwargs)
|
|
||||||
|
|
||||||
def confirm_login_allowed(self, user):
|
def confirm_login_allowed(self, user):
|
||||||
if user.activation_token:
|
if user.activation_token:
|
||||||
raise forms.ValidationError(
|
raise forms.ValidationError(
|
||||||
|
|||||||
@ -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.base_user import AbstractBaseUser, BaseUserManager
|
||||||
from django.contrib.auth.hashers import make_password
|
from django.contrib.auth.hashers import make_password
|
||||||
from django.contrib.auth.models import PermissionsMixin
|
from django.contrib.auth.models import PermissionsMixin
|
||||||
from django.contrib.auth.validators import ASCIIUsernameValidator, UnicodeUsernameValidator
|
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 import six, timezone
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.core.mail import send_mail
|
|
||||||
|
|
||||||
from marietje.utils import get_first_queue
|
from marietje.utils import get_first_queue
|
||||||
|
from queues.models import Queue
|
||||||
|
|
||||||
|
|
||||||
class UserManager(BaseUserManager):
|
class UserManager(BaseUserManager):
|
||||||
|
|||||||
@ -62,7 +62,7 @@ DATABASES = {
|
|||||||
'PASSWORD': 'v8TzZwdAdSi7Tk5I',
|
'PASSWORD': 'v8TzZwdAdSi7Tk5I',
|
||||||
'HOST': 'localhost',
|
'HOST': 'localhost',
|
||||||
'PORT': '3306',
|
'PORT': '3306',
|
||||||
'OPTIONS': { 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'" },
|
'OPTIONS': {'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,12 +95,12 @@ CACHES = {
|
|||||||
'default': {
|
'default': {
|
||||||
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
|
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
|
||||||
'LOCATION': '/var/tmp/MarietjeDjango_cache/default',
|
'LOCATION': '/var/tmp/MarietjeDjango_cache/default',
|
||||||
'OPTIONS': { 'MAX_ENTRIES': 1000 },
|
'OPTIONS': {'MAX_ENTRIES': 1000},
|
||||||
},
|
},
|
||||||
'song_search': {
|
'song_search': {
|
||||||
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
|
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
|
||||||
'LOCATION': '/var/tmp/MarietjeDjango_cache/song_search',
|
'LOCATION': '/var/tmp/MarietjeDjango_cache/song_search',
|
||||||
'OPTIONS': { 'MAX_ENTRIES': 1000 },
|
'OPTIONS': {'MAX_ENTRIES': 1000},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,13 @@
|
|||||||
import socket, struct, binascii
|
import binascii
|
||||||
|
import socket
|
||||||
|
import struct
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from queues.models import Queue, Playlist
|
|
||||||
from django.http import StreamingHttpResponse
|
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):
|
||||||
data = {
|
data = {
|
||||||
'id': song.id,
|
'id': song.id,
|
||||||
'artist': song.artist,
|
'artist': song.artist,
|
||||||
@ -12,13 +15,13 @@ def song_to_dict(song, hash=False, user=False, replaygain=False):
|
|||||||
'duration': song.duration,
|
'duration': song.duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
if hash:
|
if include_hash:
|
||||||
data['hash'] = song.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
|
data['uploader_name'] = song.user.name
|
||||||
|
|
||||||
if replaygain:
|
if include_replaygain:
|
||||||
data['rg_gain'] = song.rg_gain
|
data['rg_gain'] = song.rg_gain
|
||||||
data['rg_peak'] = song.rg_peak
|
data['rg_peak'] = song.rg_peak
|
||||||
|
|
||||||
@ -44,9 +47,9 @@ def send_to_bertha(file):
|
|||||||
for chunk in file.chunks():
|
for chunk in file.chunks():
|
||||||
sock.sendall(chunk)
|
sock.sendall(chunk)
|
||||||
sock.shutdown(socket.SHUT_WR)
|
sock.shutdown(socket.SHUT_WR)
|
||||||
hash = binascii.hexlify(sock.recv(64))
|
song_hash = binascii.hexlify(sock.recv(64))
|
||||||
sock.close()
|
sock.close()
|
||||||
return hash
|
return song_hash
|
||||||
|
|
||||||
|
|
||||||
def get_first_queue():
|
def get_first_queue():
|
||||||
@ -61,10 +64,10 @@ def get_first_queue():
|
|||||||
return queue
|
return queue
|
||||||
|
|
||||||
|
|
||||||
def bertha_stream(hash):
|
def bertha_stream(song_hash):
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
sock.connect(settings.BERTHA_HOST)
|
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)
|
data = sock.recv(4096)
|
||||||
while data:
|
while data:
|
||||||
yield data
|
yield data
|
||||||
@ -72,7 +75,7 @@ def bertha_stream(hash):
|
|||||||
sock.close()
|
sock.close()
|
||||||
|
|
||||||
|
|
||||||
def get_from_bertha(hash):
|
def get_from_bertha(song_hash):
|
||||||
response = StreamingHttpResponse(bertha_stream(hash))
|
response = StreamingHttpResponse(bertha_stream(song_hash))
|
||||||
response['Content-Disposition'] = 'attachment; filename="{}"'.format(hash)
|
response['Content-Disposition'] = 'attachment; filename="{}"'.format(song_hash)
|
||||||
return response
|
return response
|
||||||
|
|||||||
@ -8,8 +8,7 @@ from django.core.mail import send_mail
|
|||||||
from django.shortcuts import render, redirect, get_object_or_404
|
from django.shortcuts import render, redirect, get_object_or_404
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from marietje.utils import get_first_queue
|
from .forms import ResetPasswordForm
|
||||||
from .forms import RegistrationForm, ResetPasswordForm
|
|
||||||
|
|
||||||
|
|
||||||
def register(request):
|
def register(request):
|
||||||
|
|||||||
@ -1,3 +0,0 @@
|
|||||||
from django.contrib import admin
|
|
||||||
|
|
||||||
# Register your models here.
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
from django.db import models
|
|
||||||
|
|
||||||
# Create your models here.
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
# Create your tests here.
|
|
||||||
@ -1,4 +1,3 @@
|
|||||||
from django.db.models import Count, Q
|
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.db.utils import OperationalError
|
from django.db.utils import OperationalError
|
||||||
|
|
||||||
@ -16,8 +15,7 @@ queue_users_gauge = Gauge('marietje_queue_users', 'Users holding a queue at some
|
|||||||
try:
|
try:
|
||||||
for queue in Queue.objects.all():
|
for queue in Queue.objects.all():
|
||||||
def _get_queue_length():
|
def _get_queue_length():
|
||||||
return (PlaylistSong.objects.filter(playlist=queue.playlist_id, state=0)
|
return PlaylistSong.objects.filter(playlist=queue.playlist_id, state=0).count()
|
||||||
.count())
|
|
||||||
|
|
||||||
def _get_queue_duration():
|
def _get_queue_duration():
|
||||||
playlist_songs = (PlaylistSong.objects.filter(playlist=queue.playlist_id, state=0)
|
playlist_songs = (PlaylistSong.objects.filter(playlist=queue.playlist_id, state=0)
|
||||||
|
|||||||
@ -1,3 +0,0 @@
|
|||||||
from django.contrib import admin
|
|
||||||
|
|
||||||
# Register your models here.
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
from django.db import models
|
|
||||||
|
|
||||||
# Create your models here.
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
# Create your tests here.
|
|
||||||
@ -14,16 +14,16 @@ from .decorators import token_required
|
|||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
@token_required
|
@token_required
|
||||||
def queue(request):
|
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:
|
for command in commands:
|
||||||
command.executed = True
|
command.executed = True
|
||||||
command.save()
|
command.save()
|
||||||
|
|
||||||
return JsonResponse({
|
return JsonResponse({
|
||||||
'current_song': playlist_song_to_dict(queue.current_song(), hash=True, replaygain=True),
|
'current_song': playlist_song_to_dict(current_queue.current_song(), include_hash=True, include_replaygain=True),
|
||||||
'queue': [playlist_song_to_dict(playlist_song, hash=True, replaygain=True) for playlist_song in queue.queue()[:1]],
|
'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]
|
'commands': [command.command for command in commands]
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -31,9 +31,9 @@ def queue(request):
|
|||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
@token_required
|
@token_required
|
||||||
def play(request):
|
def play(request):
|
||||||
queue = get_object_or_404(Queue, id=request.POST.get('queue'))
|
current_queue = get_object_or_404(Queue, id=request.POST.get('queue'))
|
||||||
queue.started_at = timezone.now()
|
current_queue.started_at = timezone.now()
|
||||||
queue.save()
|
current_queue.save()
|
||||||
current_song = queue.current_song()
|
current_song = queue.current_song()
|
||||||
current_song.played_at = queue.started_at
|
current_song.played_at = queue.started_at
|
||||||
current_song.save()
|
current_song.save()
|
||||||
@ -41,11 +41,12 @@ def play(request):
|
|||||||
return JsonResponse({})
|
return JsonResponse({})
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable=redefined-builtin
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
@token_required
|
@token_required
|
||||||
def next(request):
|
def next(request):
|
||||||
queue = get_object_or_404(Queue, id=request.POST.get('queue'))
|
current_queue = get_object_or_404(Queue, id=request.POST.get('queue'))
|
||||||
player_song = queue.current_song()
|
player_song = current_queue.current_song()
|
||||||
player_song.state = 2
|
player_song.state = 2
|
||||||
player_song.save()
|
player_song.save()
|
||||||
return JsonResponse({})
|
return JsonResponse({})
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
import time
|
|
||||||
|
|
||||||
from django.db import models
|
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.conf import settings
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
@ -99,7 +97,7 @@ class Queue(models.Model):
|
|||||||
|
|
||||||
def current_song(self):
|
def current_song(self):
|
||||||
songs = self.get_songs()
|
songs = self.get_songs()
|
||||||
if len(songs) < 1:
|
if not songs:
|
||||||
return None
|
return None
|
||||||
song = songs[0]
|
song = songs[0]
|
||||||
if song.state != 1:
|
if song.state != 1:
|
||||||
@ -136,7 +134,8 @@ class Queue(models.Model):
|
|||||||
playlist_song.save()
|
playlist_song.save()
|
||||||
|
|
||||||
# If the song was auto-queue'd, then remove it from the auto-queue
|
# 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
|
return None
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +0,0 @@
|
|||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
# Create your tests here.
|
|
||||||
@ -1,8 +1,2 @@
|
|||||||
from django.conf.urls import url
|
|
||||||
|
|
||||||
from . import views
|
|
||||||
|
|
||||||
app_name = 'queue'
|
app_name = 'queue'
|
||||||
|
urlpatterns = []
|
||||||
urlpatterns = [
|
|
||||||
]
|
|
||||||
|
|||||||
@ -13,7 +13,8 @@ class SongAdmin(admin.ModelAdmin):
|
|||||||
search_fields = ('artist', 'title', 'user__name')
|
search_fields = ('artist', 'title', 'user__name')
|
||||||
inlines = [ReportNoteInline]
|
inlines = [ReportNoteInline]
|
||||||
|
|
||||||
def reports(self, song):
|
@staticmethod
|
||||||
|
def reports(song):
|
||||||
return ReportNote.objects.filter(song=song).count()
|
return ReportNote.objects.filter(song=song).count()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@ -43,7 +43,8 @@ class Song(models.Model):
|
|||||||
return self.artist + ' - ' + self.title
|
return self.artist + ' - ' + self.title
|
||||||
|
|
||||||
class ReportNote(models.Model):
|
class ReportNote(models.Model):
|
||||||
song = models.ForeignKey(Song,
|
song = models.ForeignKey(
|
||||||
|
Song,
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
blank=False,
|
blank=False,
|
||||||
null=False,
|
null=False,
|
||||||
@ -54,7 +55,9 @@ class ReportNote(models.Model):
|
|||||||
blank=True,
|
blank=True,
|
||||||
null=True,
|
null=True,
|
||||||
db_index=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')
|
help_text='reason for edit request')
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|||||||
@ -1,3 +0,0 @@
|
|||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
# Create your tests here.
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
from django.shortcuts import render, get_object_or_404, redirect
|
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
|
from .models import Song
|
||||||
|
|
||||||
|
|
||||||
@ -14,8 +14,8 @@ def manage(request):
|
|||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def edit(request, id):
|
def edit(request, song_id):
|
||||||
song = get_object_or_404(Song, pk=id, user=request.user)
|
song = get_object_or_404(Song, pk=song_id, user=request.user)
|
||||||
if not request.POST:
|
if not request.POST:
|
||||||
return render(request, 'songs/edit.html', {'song': song})
|
return render(request, 'songs/edit.html', {'song': song})
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +0,0 @@
|
|||||||
from django.contrib import admin
|
|
||||||
|
|
||||||
# Register your models here.
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
from django.db import models
|
|
||||||
|
|
||||||
# Create your models here.
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
# Create your tests here.
|
|
||||||
@ -1,9 +1,8 @@
|
|||||||
from datetime import datetime, timedelta, time
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from django.core.cache import caches
|
from django.core.cache import caches
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db.models import Count, Q, Sum
|
from django.db.models import Count, Q, Sum
|
||||||
from django.shortcuts import render
|
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
from queues.models import PlaylistSong
|
from queues.models import PlaylistSong
|
||||||
@ -27,11 +26,6 @@ def recache_user_stats():
|
|||||||
caches['default'].set(cacheloc, new_stats, 48 * 3600)
|
caches['default'].set(cacheloc, new_stats, 48 * 3600)
|
||||||
return new_stats
|
return new_stats
|
||||||
|
|
||||||
def to_days(time):
|
|
||||||
for tr in time:
|
|
||||||
tr['duration'] = str(round(tr['total'] / 86400, 2)) + ' days'
|
|
||||||
return time
|
|
||||||
|
|
||||||
def compute_stats():
|
def compute_stats():
|
||||||
# We want to grab the time now, because otherwise we would be reporting a minute too late
|
# We want to grab the time now, because otherwise we would be reporting a minute too late
|
||||||
last_updated = datetime.now()
|
last_updated = datetime.now()
|
||||||
@ -98,6 +92,11 @@ def compute_stats():
|
|||||||
'song__user__id', 'song__user__name').annotate(total=Count(
|
'song__user__id', 'song__user__name').annotate(total=Count(
|
||||||
'song__user__id')).order_by('-total')[:settings.STATS_TOP_COUNT]
|
'song__user__id')).order_by('-total')[:settings.STATS_TOP_COUNT]
|
||||||
|
|
||||||
|
# Convert requested time to days
|
||||||
|
time_requested = list(time_requested)
|
||||||
|
for tr in time_requested:
|
||||||
|
tr['duration'] = str(round(tr['total'] / 86400, 2)) + ' days'
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'last_updated': last_updated,
|
'last_updated': last_updated,
|
||||||
'total_uploads': total_uploads,
|
'total_uploads': total_uploads,
|
||||||
@ -108,7 +107,7 @@ def compute_stats():
|
|||||||
'total_unique_requests': total_unique_requests,
|
'total_unique_requests': total_unique_requests,
|
||||||
'most_played_songs': list(most_played_songs),
|
'most_played_songs': list(most_played_songs),
|
||||||
'most_played_songs_14_days': list(most_played_songs_14_days),
|
'most_played_songs_14_days': list(most_played_songs_14_days),
|
||||||
'time_requested': to_days(list(time_requested)),
|
'time_requested': time_requested,
|
||||||
'total_time_requested': str(round(float(total_time_requested['total']) / 86400, 2)) + ' days',
|
'total_time_requested': str(round(float(total_time_requested['total']) / 86400, 2)) + ' days',
|
||||||
'stats_top_count': settings.STATS_TOP_COUNT,
|
'stats_top_count': settings.STATS_TOP_COUNT,
|
||||||
'most_requested_uploaders': list(most_requested_uploaders),
|
'most_requested_uploaders': list(most_requested_uploaders),
|
||||||
@ -167,4 +166,3 @@ def user_stats(request):
|
|||||||
'stats_top_count': settings.STATS_TOP_COUNT,
|
'stats_top_count': settings.STATS_TOP_COUNT,
|
||||||
'total_played_uploads': total_played_uploads['newtotal'],
|
'total_played_uploads': total_played_uploads['newtotal'],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,34 +2,32 @@ from datetime import datetime, timedelta
|
|||||||
|
|
||||||
from django.core.cache import caches
|
from django.core.cache import caches
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from stats.utils import user_stats
|
|
||||||
from django.http import JsonResponse, HttpResponseForbidden
|
|
||||||
|
|
||||||
|
|
||||||
def stats(request):
|
def stats(request):
|
||||||
stats = caches['default'].get('stats')
|
stats_data = caches['default'].get('stats')
|
||||||
status = 503
|
status = 503
|
||||||
current_age = None
|
current_age = None
|
||||||
current_age_text = None
|
current_age_text = None
|
||||||
|
|
||||||
if stats:
|
if stats_data:
|
||||||
status = 200
|
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)
|
return render(request, 'stats/stats.html', data, status=status)
|
||||||
|
|
||||||
def user_stats(request):
|
def user_stats(request):
|
||||||
stats = caches['default'].get('userstats_{}'.format(request.user.id))
|
stats_data = caches['default'].get('userstats_{}'.format(request.user.id))
|
||||||
status = 503
|
status = 503
|
||||||
current_age = None
|
current_age = None
|
||||||
current_age_text = None
|
current_age_text = None
|
||||||
|
|
||||||
if stats:
|
if stats_data:
|
||||||
status = 200
|
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)
|
return render(request, 'stats/user.html', data, status=status)
|
||||||
|
|
||||||
def age_text(last_updated):
|
def age_text(last_updated):
|
||||||
@ -40,7 +38,6 @@ def age_text(last_updated):
|
|||||||
hourstr = "hour" if hours == 1 else "hours"
|
hourstr = "hour" if hours == 1 else "hours"
|
||||||
if current_age < timedelta(hours=1):
|
if current_age < timedelta(hours=1):
|
||||||
return 'Stats were updated {:.0f} {} ago.'.format(minutes, minutestr)
|
return 'Stats were updated {:.0f} {} ago.'.format(minutes, minutestr)
|
||||||
else:
|
|
||||||
return 'Stats were updated {:.0f} {} and {:.0f} {} ago.'.format(
|
return 'Stats were updated {:.0f} {} and {:.0f} {} ago.'.format(
|
||||||
hours, hourstr, minutes, minutestr)
|
hours, hourstr, minutes, minutestr)
|
||||||
|
|
||||||
|
|||||||
12
pylintrc
12
pylintrc
@ -139,7 +139,17 @@ disable=missing-docstring,
|
|||||||
xreadlines-attribute,
|
xreadlines-attribute,
|
||||||
deprecated-sys-function,
|
deprecated-sys-function,
|
||||||
exception-escape,
|
exception-escape,
|
||||||
comprehension-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
|
# 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
|
# either give multiple identifier separated by comma (,) or put this option
|
||||||
|
|||||||
Reference in New Issue
Block a user