Store progress in Session model

main
Luca 2 years ago
parent 2a4f45153b
commit 32ff248be0

@ -0,0 +1,18 @@
# Generated by Django 4.1.4 on 2022-12-17 18:17
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("core", "0002_session"),
]
operations = [
migrations.AddField(
model_name="session",
name="offset",
field=models.PositiveIntegerField(default=0),
),
]

@ -21,4 +21,5 @@ def session_token():
class Session(models.Model):
token = models.CharField(max_length=43, default=session_token, primary_key=True)
offset = models.PositiveIntegerField(default=0)
playlist = models.ForeignKey(Playlist, on_delete=models.CASCADE)

@ -127,6 +127,10 @@ def view_artist(request, playlist, offset):
try:
session = Session.objects.get(pk=request.session['session'])
session_url = get_absolute_join_session_url(request, session)
if session.offset < offset:
session.offset = offset
session.save()
except Session.DoesNotExist:
del request.session['session']

@ -22,7 +22,10 @@ def join_session(request, session):
def artist(request, playlist, offset=None):
session = get_object_or_404(Session, pk=request.session.get('session'))
offset = offset or 0
offset = offset if offset != None else session.offset
if offset > session.offset:
return redirect('artist', playlist, session.offset)
artists = session.playlist.artist_set
artist = artists.order_by('id')[offset]

Loading…
Cancel
Save