Show - Add episode link submissions
This commit is contained in:
parent
f13c412f85
commit
a8d2961a79
@ -13,6 +13,29 @@ body {
|
|||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
color: #000;
|
color: #000;
|
||||||
}
|
}
|
||||||
|
input[type="submit"] {
|
||||||
|
font-size: 120%;
|
||||||
|
}
|
||||||
|
label {
|
||||||
|
width: 200px;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
input[type=text], input:not([type=submit]) {
|
||||||
|
padding: 5px;
|
||||||
|
font-size: 120%;
|
||||||
|
width: 280px;
|
||||||
|
border-radius: 5px;
|
||||||
|
border: 1px solid #b3b3b3;
|
||||||
|
background-color: #ffffff;
|
||||||
|
box-shadow: inset 2px 2px 5px #ddd;
|
||||||
|
}
|
||||||
|
.helptext {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
font-style: italic;
|
||||||
|
font-size: 80%;
|
||||||
|
cursor: help;
|
||||||
|
}
|
||||||
.unibar {
|
.unibar {
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
border-bottom: 1px solid #ddd;
|
border-bottom: 1px solid #ddd;
|
||||||
@ -169,6 +192,13 @@ a.episode .submission_cnt {
|
|||||||
.submission-list .submission.buried {
|
.submission-list .submission.buried {
|
||||||
opacity: 0.3;
|
opacity: 0.3;
|
||||||
}
|
}
|
||||||
|
.message.error {
|
||||||
|
width: fit-content;
|
||||||
|
padding: 10px;
|
||||||
|
background-color: #ffcaca;
|
||||||
|
border: 1px solid #b10000;
|
||||||
|
margin: 5px 0;
|
||||||
|
}
|
||||||
@media all and (max-width: 800px) {
|
@media all and (max-width: 800px) {
|
||||||
.logo {
|
.logo {
|
||||||
font-size: 5vw !important;
|
font-size: 5vw !important;
|
||||||
|
11
Show/forms.py
Normal file
11
Show/forms.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
from django import forms
|
||||||
|
from LandingPage.models import Submission
|
||||||
|
|
||||||
|
class SubmissionForm(forms.ModelForm):
|
||||||
|
class Meta():
|
||||||
|
model = Submission
|
||||||
|
fields = ('url','tags',)
|
||||||
|
help_texts = {
|
||||||
|
'url': 'URL to your episode',
|
||||||
|
'tags': 'Describe your link. Comma-separated list of keywords'
|
||||||
|
}
|
@ -18,7 +18,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<section class="submissions">
|
<section class="submissions">
|
||||||
<a href="/show/{{show.abbr}}" class="button"><< Show Index</a>
|
<a href="/show/{{show.abbr}}" class="button"><i class="fa fa-fw fa-home"></i> Show Index</a>
|
||||||
|
{% if request.session.user_id %}
|
||||||
|
<a href="/show/{{show.abbr}}/episode/{{episode.season.number}}/{{episode.episode}}/submit" class="button"><i class="fa fa-fw fa-plus"></i> Submit New Link</a>
|
||||||
|
{% endif %}
|
||||||
<h1>Watch <q>{{episode.name}}</q> From</h1>
|
<h1>Watch <q>{{episode.name}}</q> From</h1>
|
||||||
<div class="submission-list">
|
<div class="submission-list">
|
||||||
{% for sbm in submissions %}
|
{% for sbm in submissions %}
|
||||||
|
34
Show/templates/submit.html
Normal file
34
Show/templates/submit.html
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block title %}
|
||||||
|
Episode "{{episode.name}}" - S{{episode.season.number}}E{{episode.episode}} - {{show.name}} - Episodes.Community
|
||||||
|
{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<section class="show-details">
|
||||||
|
<div class="banner" style="background-image: url(/media/uploaded_resources/{{show.banner}});"></div>
|
||||||
|
<div class="banner-cover">
|
||||||
|
<div class="artwork">
|
||||||
|
<img src="/media/uploaded_resources/{{show.artwork}}">
|
||||||
|
</div>
|
||||||
|
<div class="details">
|
||||||
|
<h1>{{show.name}}</h1>
|
||||||
|
<p class="description">
|
||||||
|
{{show.description}}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<section class="submissions">
|
||||||
|
<a href="/show/{{show.abbr}}" class="button"><i class="fa fa-fw fa-home"></i> Show Index</a>
|
||||||
|
<a href="/show/{{show.abbr}}/episode/{{episode.season.number}}/{{episode.episode}}-{{episode.name|slugify}}" class="button">Back to Episode</a>
|
||||||
|
<h1>Submit a link</h1>
|
||||||
|
{% if error %}
|
||||||
|
<div class="message error">{{error}}</div>
|
||||||
|
{% endif %}
|
||||||
|
<form action="" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form }}
|
||||||
|
<input type="submit" value="Submit" />
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
{% endblock %}
|
@ -21,5 +21,6 @@ from . import views
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', views.IndexView.as_view()),
|
url(r'^$', views.IndexView.as_view()),
|
||||||
url(r'^episode/(?P<season>\d{1,4})/(?P<episode>\d{1,4})(-[\w-]+)?/?$', views.EpisodeView.as_view()),
|
url(r'^episode/(?P<season>\d{1,4})/(?P<episode>\d{1,4})(-[\w-]+)?/?$', views.EpisodeView.as_view()),
|
||||||
|
url(r'^episode/(?P<season>\d{1,4})/(?P<episode>\d{1,4})(-[\w-]+)?/submit$', views.SubmissionForm),
|
||||||
url(r'^vote/(?P<subid>\d+)/(?P<positive>[0-1])/?$', views.SubmissionVoteSubmit.as_view())
|
url(r'^vote/(?P<subid>\d+)/(?P<positive>[0-1])/?$', views.SubmissionVoteSubmit.as_view())
|
||||||
]
|
]
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from django.shortcuts import render
|
from django.template import RequestContext
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.views import View
|
from django.views import View
|
||||||
from django.views.generic.base import TemplateView
|
from django.views.generic.base import TemplateView
|
||||||
@ -14,6 +14,10 @@ from LandingPage.models import Season
|
|||||||
from LandingPage.models import Episode
|
from LandingPage.models import Episode
|
||||||
from LandingPage.models import Submission, SubmissionVote
|
from LandingPage.models import Submission, SubmissionVote
|
||||||
|
|
||||||
|
from . import forms
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
# Index page of a show
|
# Index page of a show
|
||||||
@ -50,7 +54,7 @@ class EpisodeView(TemplateView):
|
|||||||
show = Show.objects.filter(abbr=abbreviation).first()
|
show = Show.objects.filter(abbr=abbreviation).first()
|
||||||
|
|
||||||
# Get episode by season and episode number
|
# Get episode by season and episode number
|
||||||
episode = Episode.objects.filter(show=show,episode=episode).first()
|
episode = Episode.objects.filter(show=show,season__number=season,episode=episode).first()
|
||||||
|
|
||||||
# 404's
|
# 404's
|
||||||
if not show:
|
if not show:
|
||||||
@ -80,6 +84,64 @@ class EpisodeView(TemplateView):
|
|||||||
|
|
||||||
return ctx
|
return ctx
|
||||||
|
|
||||||
|
# Submission form GET and POST
|
||||||
|
def SubmissionForm(req, abbreviation, season, episode):
|
||||||
|
show = Show.objects.get(abbr=abbreviation)
|
||||||
|
episode = Episode.objects.filter(show=show,season__number=season,episode=episode).first()
|
||||||
|
|
||||||
|
# Check for login status
|
||||||
|
if not 'user_id' in req.session:
|
||||||
|
return HttpResponse('<h1>Error</h1><p>You need to be logged in to submit. Please <a href=/login>log in</a></p>', status=400)
|
||||||
|
|
||||||
|
user = User.objects.get(user_id=req.session['user_id'])
|
||||||
|
|
||||||
|
# 404's
|
||||||
|
if not show:
|
||||||
|
raise Http404("Show does not exist")
|
||||||
|
|
||||||
|
if not episode:
|
||||||
|
raise Http404("Episode does not exist")
|
||||||
|
|
||||||
|
form = forms.SubmissionForm()
|
||||||
|
|
||||||
|
# Request context
|
||||||
|
ctx = {
|
||||||
|
'form': form,
|
||||||
|
'show': show,
|
||||||
|
'episode': episode
|
||||||
|
}
|
||||||
|
|
||||||
|
# Handle POST
|
||||||
|
if req.method == 'POST':
|
||||||
|
form = forms.SubmissionForm(req.POST)
|
||||||
|
ctx['form'] = form
|
||||||
|
|
||||||
|
if form.is_valid():
|
||||||
|
form_data = form.cleaned_data
|
||||||
|
|
||||||
|
# Check if the URL has already been submitted
|
||||||
|
if Submission.objects.filter(episode=episode,url=form_data['url']).count() > 0:
|
||||||
|
ctx['error'] = 'This URL has already been submitted!'
|
||||||
|
return render(req, "submit.html", ctx)
|
||||||
|
|
||||||
|
# Check if there has been a submission by this user for this episode within the last 24 hours
|
||||||
|
if Submission.objects.filter(user=user,episode=episode,timestamp__gte=datetime.date.today() - datetime.timedelta(hours=24)).count() > 0:
|
||||||
|
ctx['error'] = 'You can only submit one link for an episode in 24 hours!'
|
||||||
|
return render(req, "submit.html", ctx)
|
||||||
|
|
||||||
|
# Have to do this because you can't add fields to a form
|
||||||
|
# If you know a better way of doing this, be my guest
|
||||||
|
new_submission = form.save(commit=False)
|
||||||
|
new_submission.user = user
|
||||||
|
new_submission.episode = episode
|
||||||
|
new_submission.save()
|
||||||
|
|
||||||
|
return HttpResponseRedirect('/show/%s/episode/%d/%d'%(abbreviation, episode.season.number, episode.episode))
|
||||||
|
else:
|
||||||
|
ctx['error'] = 'Invalid fields!'
|
||||||
|
|
||||||
|
return render(req, "submit.html", ctx)
|
||||||
|
|
||||||
# Vote request
|
# Vote request
|
||||||
# /show/{{abbr}}/vote/{{submission id}}/{{positive == 1}}
|
# /show/{{abbr}}/vote/{{submission id}}/{{positive == 1}}
|
||||||
class SubmissionVoteSubmit(View):
|
class SubmissionVoteSubmit(View):
|
||||||
|
Reference in New Issue
Block a user