From f9ba48ddfb77a0ba5be11f566d83a85e100e11c4 Mon Sep 17 00:00:00 2001 From: Stephan Telling Date: Sun, 4 Mar 2018 15:48:57 +0100 Subject: [PATCH] cleanup in program/ --- src/program/consumers.py | 9 ++++++++- src/program/mixins.py | 22 ++++++++++++++++------ src/program/models.py | 5 ----- src/program/tests.py | 3 --- src/program/views.py | 17 +++++++---------- 5 files changed, 31 insertions(+), 25 deletions(-) delete mode 100644 src/program/tests.py diff --git a/src/program/consumers.py b/src/program/consumers.py index 4c659066..06713545 100644 --- a/src/program/consumers.py +++ b/src/program/consumers.py @@ -1,7 +1,14 @@ from channels.generic.websockets import JsonWebsocketConsumer from camps.models import Camp -from .models import Event, EventInstance, Favorite, EventLocation, EventType, Speaker +from .models import ( + Event, + EventInstance, + Favorite, + EventLocation, + EventType, + Speaker +) class ScheduleConsumer(JsonWebsocketConsumer): diff --git a/src/program/mixins.py b/src/program/mixins.py index 79a837ab..9cf00b5f 100644 --- a/src/program/mixins.py +++ b/src/program/mixins.py @@ -3,8 +3,9 @@ from django.shortcuts import redirect from django.urls import reverse from . import models from django.contrib import messages -import sys, mimetypes from django.http import Http404, HttpResponse +import sys +import mimetypes class EnsureCFSOpenMixin(SingleObjectMixin): @@ -12,7 +13,9 @@ class EnsureCFSOpenMixin(SingleObjectMixin): # do not permit editing if call for speakers is not open if not self.camp.call_for_speakers_open: messages.error(request, "The Call for Speakers is not open.") - return redirect(reverse('proposal_list', kwargs={'camp_slug': self.camp.slug})) + return redirect( + reverse('proposal_list', kwargs={'camp_slug': self.camp.slug}) + ) # alright, continue with the request return super().dispatch(request, *args, **kwargs) @@ -23,8 +26,10 @@ class CreateProposalMixin(SingleObjectMixin): # set camp and user before saving form.instance.camp = self.camp form.instance.user = self.request.user - speaker = form.save() - return redirect(reverse('proposal_list', kwargs={'camp_slug': self.camp.slug})) + form.save() + return redirect( + reverse('proposal_list', kwargs={'camp_slug': self.camp.slug}) + ) class EnsureUnapprovedProposalMixin(SingleObjectMixin): @@ -54,7 +59,9 @@ class EnsureUserOwnsProposalMixin(SingleObjectMixin): # make sure that this proposal belongs to the logged in user if self.get_object().user.username != request.user.username: messages.error(request, "No thanks") - return redirect(reverse('proposal_list', kwargs={'camp_slug': self.camp.slug})) + return redirect( + reverse('proposal_list', kwargs={'camp_slug': self.camp.slug}) + ) # alright, continue with the request return super().dispatch(request, *args, **kwargs) @@ -83,7 +90,10 @@ class PictureViewMixin(SingleObjectMixin): def get_picture_response(self, path): if 'runserver' in sys.argv or 'runserver_plus' in sys.argv: # this is a local devserver situation, guess mimetype from extension and return picture directly - response = HttpResponse(self.picture, content_type=mimetypes.types_map[".%s" % self.picture.name.split(".")[-1]]) + response = HttpResponse( + self.picture, + content_type=mimetypes.types_map[".%s" % self.picture.name.split(".")[-1]] + ) else: # make nginx serve the picture using X-Accel-Redirect # (this works for nginx only, other webservers use x-sendfile) diff --git a/src/program/models.py b/src/program/models.py index b34bed8a..43a0c8eb 100644 --- a/src/program/models.py +++ b/src/program/models.py @@ -1,7 +1,6 @@ import uuid import os import icalendar -import CommonMark import logging from datetime import timedelta @@ -10,12 +9,9 @@ from django.contrib.postgres.fields import DateTimeRangeField from django.contrib import messages from django.db import models from django.core.exceptions import ObjectDoesNotExist, ValidationError -from django.dispatch import receiver from django.utils.text import slugify from django.conf import settings from django.core.urlresolvers import reverse_lazy -from django.core.exceptions import ValidationError -from django.core.urlresolvers import reverse_lazy, reverse from django.core.files.storage import FileSystemStorage from django.urls import reverse from django.apps import apps @@ -644,7 +640,6 @@ class Speaker(CampRelatedModel): def get_large_picture_url(self): return self.get_picture_url('large') - def serialize(self): data = { 'name': self.name, diff --git a/src/program/tests.py b/src/program/tests.py deleted file mode 100644 index 7ce503c2..00000000 --- a/src/program/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/src/program/views.py b/src/program/views.py index acb08112..c6c7ec3b 100644 --- a/src/program/views.py +++ b/src/program/views.py @@ -1,4 +1,3 @@ -import datetime import logging import os @@ -12,7 +11,6 @@ from django.contrib.admin.views.decorators import staff_member_required from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib import messages from django.urls import reverse -from django.db.models import Q from django.template import Engine, Context import icalendar @@ -34,7 +32,7 @@ from . import models logger = logging.getLogger("bornhack.%s" % __name__) -############## ical calendar ######################################################## +# ical calendar class ICSView(CampViewMixin, View): @@ -90,7 +88,7 @@ class ICSView(CampViewMixin, View): return response -############## proposals ######################################################## +# proposals class ProposalListView(LoginRequiredMixin, CampViewMixin, ListView): @@ -241,7 +239,7 @@ class EventProposalDetailView(LoginRequiredMixin, CampViewMixin, EnsureUserOwnsP template_name = 'eventproposal_detail.html' -################## speakers ############################################### +# speakers @method_decorator(require_safe, name='dispatch') @@ -268,7 +266,7 @@ class SpeakerListView(CampViewMixin, ListView): template_name = 'speaker_list.html' -################## events ############################################## +# events class EventListView(CampViewMixin, ListView): @@ -281,7 +279,7 @@ class EventDetailView(CampViewMixin, DetailView): template_name = 'schedule_event_detail.html' -################## schedule ############################################# +# schedule class NoScriptScheduleView(CampViewMixin, TemplateView): @@ -293,13 +291,12 @@ class NoScriptScheduleView(CampViewMixin, TemplateView): return context - class ScheduleView(CampViewMixin, TemplateView): template_name = 'schedule_overview.html' def get_context_data(self, *args, **kwargs): context = super(ScheduleView, self).get_context_data(**kwargs) - context['schedule_midnight_offset_hours'] = settings.SCHEDULE_MIDNIGHT_OFFSET_HOURS; + context['schedule_midnight_offset_hours'] = settings.SCHEDULE_MIDNIGHT_OFFSET_HOURS return context @@ -308,8 +305,8 @@ class CallForSpeakersView(CampViewMixin, TemplateView): return '%s_call_for_speakers.html' % self.camp.slug +# control center -################## control center ############################################# class ProgramControlCenter(CampViewMixin, TemplateView): template_name = "control/index.html"