diff --git a/Discussions/templates/boards.html b/Discussions/templates/boards.html new file mode 100644 index 0000000..ff51386 --- /dev/null +++ b/Discussions/templates/boards.html @@ -0,0 +1,76 @@ +{% extends "base.html" %} +{% block title %} + {{show.name}} Discussions - Episodes.Community +{% endblock %} +{% block content %} +
+

{{show.name}} Discussion Boards

+
+ {% if user.is_authenticated %} +  Create New Board + {% else %} + Log in to create boards + {% endif %} +
+
+
Board Name
+
Latest Reply
+
+ {% for board in boards %} +
+
+
+

{{board.title}}

+ Submitted {{board.timestamp}} by + {% if board.user.is_staff %} + + {% endif %} + {{board.user.display_name}} + +
+
+ No replies +
+
+
+ {% empty %} +

Nobody has started any discussions for this show!

+ {% endfor %} + + {% if boards.has_other_pages %} + + {% endif %} +
+{% endblock %} diff --git a/Discussions/urls.py b/Discussions/urls.py new file mode 100644 index 0000000..69472ff --- /dev/null +++ b/Discussions/urls.py @@ -0,0 +1,24 @@ +# Episodes.Community - Community-Driven TV Show Episode Link Sharing Site +# Copyright (C) 2018 Evert "Diamond" Prants , Taizo "Tsa6" Simpson +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from django.conf.urls import url + +from . import views + +urlpatterns = [ + url(r'^$', views.Boards.as_view()), +] + diff --git a/Discussions/views.py b/Discussions/views.py index f368b15..cc4b16c 100644 --- a/Discussions/views.py +++ b/Discussions/views.py @@ -13,7 +13,42 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . - +from django.template import RequestContext +from django.shortcuts import render, get_list_or_404, get_object_or_404 +from django.views import View +from django.views.generic.base import TemplateView +from django.contrib.auth.decorators import login_required +from django.conf import settings +from django.http import Http404, HttpResponseForbidden, HttpResponse, HttpResponseRedirect +from django.db.models import Case, When, Value, IntegerField, Count, F, Q +from django.contrib.auth.mixins import LoginRequiredMixin from django.shortcuts import render +from django.core.paginator import Paginator -# Create your views here. +from guardian.decorators import permission_required_or_403 + +from LandingPage.models import Show, DiscussionBoard, DiscussionReply, DiscussionVote + +class Boards(TemplateView): + + template_name = "boards.html" + + def get_context_data(self, abbr, **kwargs): + ctx = super().get_context_data() + show = get_object_or_404(Show, abbr=abbr) + + page = self.request.GET.get('page', 1) + + boards_list = DiscussionBoard.objects.filter(show=show) + paginator = Paginator(boards_list, getattr(settings, "DISCUSSIONS_PER_PAGE", 26)) + try: + boards = paginator.page(page) + except PageNotAnInteger: + boards = paginator.page(1) + except EmptyPage: + boards = paginator.page(paginator.num_pages) + + ctx['boards'] = boards + ctx['show'] = show + + return ctx diff --git a/EpisodesCommunity/settings.py b/EpisodesCommunity/settings.py index a78521c..e426da0 100644 --- a/EpisodesCommunity/settings.py +++ b/EpisodesCommunity/settings.py @@ -171,3 +171,5 @@ AUTH_TOKEN_ENDPOINT = oauth_options.get('token_endpoint','https://icynet.eu/oaut AUTH_CLIENT_ID = oauth_options.get('client_id') AUTH_B64 = base64.b64encode(bytearray('%s:%s'%(AUTH_CLIENT_ID,oauth_options.get('client_secret')),'utf-8')).decode("utf-8") AUTH_REDIRECT_URL = oauth_options.get('redirect_url') + +DISCUSSIONS_PER_PAGE = 26 diff --git a/EpisodesCommunity/urls.py b/EpisodesCommunity/urls.py index 38fc82b..1a6d679 100644 --- a/EpisodesCommunity/urls.py +++ b/EpisodesCommunity/urls.py @@ -36,6 +36,7 @@ from django.conf.urls.static import static urlpatterns = [ url(r'^admin/', admin.site.urls), + url(r'^show/(?P\w{1,16})/discuss', include('Discussions.urls')), url(r'^show/(?P\w{1,16})/', include('Show.urls')), url(r'^', include('LandingPage.urls')) ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)