From 4df913c7fefacc890b9709791b49bdd49ffeb3c7 Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Mon, 26 Feb 2024 22:51:35 +0100 Subject: [PATCH] nomination quota --- playlist/models/profile.py | 18 ++++++++++++++++++ playlist/static/style.css | 21 ++++++++++++++++++++- playlist/templates/Base.html | 1 + playlist/templates/Nominate.html | 15 +++++++++++++-- playlist/views.py | 7 +++++++ 5 files changed, 59 insertions(+), 3 deletions(-) diff --git a/playlist/models/profile.py b/playlist/models/profile.py index 3a23481..2b43b4b 100644 --- a/playlist/models/profile.py +++ b/playlist/models/profile.py @@ -3,6 +3,10 @@ from django.contrib.auth.models import User from .track import Track from django.db.models.signals import post_save from django.dispatch import receiver +from django.utils import timezone +from datetime import datetime, timedelta + +NOMINATIONS_PER_DAY = 10 class Background(models.Model): def __str__(self): @@ -17,6 +21,20 @@ class Profile(models.Model): background = models.ForeignKey(Background, null=True, on_delete=models.SET_NULL) last_voted = models.ForeignKey(Track, null=True, on_delete=models.SET_NULL) + quota = models.FloatField(default=10.0) + quota_last_updated = models.DateTimeField(null=False) + def update_quota(self): + elapsed = timezone.now() - self.quota_last_updated + if elapsed.seconds > 300: + noms_per_second = NOMINATIONS_PER_DAY/(60*60*24) + self.quota += noms_per_second * elapsed.seconds + print(f"Er zijn {elapsed.seconds}s voorbij, je nieuwe quota is {self.quota}") + self.quota_last_updated = timezone.now() + + def save(self, *args, **kwargs): + self.update_quota() + super().save(*args, **kwargs) + @receiver(post_save, sender=User) def create_user_profile(sender, instance, created, **kwargs): if created: diff --git a/playlist/static/style.css b/playlist/static/style.css index ed64511..9d983ee 100644 --- a/playlist/static/style.css +++ b/playlist/static/style.css @@ -70,7 +70,14 @@ input#spotify-input + input[type=submit]{ z-index: 100; top: calc(50% - 75px); left: calc(50% - 150px); - min-width: 300px; + width: 300px; +} + +.window.popup .title-bar-text { + height: 13px; + overflow:hidden; + text-overflow:ellipsis; + white-space:nowrap; } .window.popup.login { @@ -313,4 +320,16 @@ iframe { background-position: 50% 0; padding: 32px 0 4px 0; height: 50px; +} + +.progress-indicator { + height: 26px; + padding: 4px 3px; + width: 360px; +} + +.progress-indicator.segmented > .progress-indicator-bar { +} + +.status-bar-field { } \ No newline at end of file diff --git a/playlist/templates/Base.html b/playlist/templates/Base.html index 78cf566..4083629 100644 --- a/playlist/templates/Base.html +++ b/playlist/templates/Base.html @@ -38,6 +38,7 @@ + {% block status-bar %}{% endblock%} {% block clippy %}{% endblock %}