48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
from django.shortcuts import render
|
|
from django.shortcuts import render
|
|
from django.views import View
|
|
from django.views.generic.base import TemplateView
|
|
from django.conf import settings
|
|
from django.http import HttpResponse
|
|
from django.http import HttpResponseRedirect
|
|
|
|
from LandingPage.models import Show
|
|
from LandingPage.models import Season
|
|
from LandingPage.models import Episode
|
|
from LandingPage.models import Submission
|
|
|
|
# Create your views here.
|
|
|
|
class IndexView(TemplateView):
|
|
template_name = "show.html"
|
|
|
|
def get_context_data(self, abbreviation, **kwargs):
|
|
ctx = super().get_context_data()
|
|
ctx['show'] = Show.objects.filter(abbr=abbreviation).first()
|
|
ctx['seasons'] = Season.objects.filter(show=ctx['show'])
|
|
ctx['episodes'] = Episode.objects.filter(show=ctx['show']).count()
|
|
return ctx
|
|
|
|
class EpisodeView(TemplateView):
|
|
template_name = "episode.html"
|
|
|
|
def get_context_data(self, abbreviation, season, episode, **kwargs):
|
|
ctx = super().get_context_data()
|
|
ctx['show'] = Show.objects.filter(abbr=abbreviation).first()
|
|
ctx['episode'] = Episode.objects.filter(show=ctx['show'],episode=episode).first()
|
|
|
|
if not ctx['episode']:
|
|
return ctx
|
|
|
|
# If you're smarter than me, maybe you can compress the next 8 lines into fewer ones by some django magic I'm not aware of
|
|
submissions = ctx['episode'].submissions.all()
|
|
|
|
for sbm in submissions:
|
|
sbm.positives = sbm.votes.filter(positive=True).count()
|
|
sbm.negatives = sbm.votes.count() - sbm.positives
|
|
|
|
# sorts by "score", TODO: less bullshit
|
|
ctx['submissions'] = reversed(sorted(submissions, key=lambda x: x.positives - x.negatives))
|
|
|
|
return ctx
|