cleanup in program/

This commit is contained in:
Stephan Telling 2018-03-04 15:48:57 +01:00
parent 5bffb9c53a
commit f9ba48ddfb
5 changed files with 31 additions and 25 deletions

View file

@ -1,7 +1,14 @@
from channels.generic.websockets import JsonWebsocketConsumer from channels.generic.websockets import JsonWebsocketConsumer
from camps.models import Camp 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): class ScheduleConsumer(JsonWebsocketConsumer):

View file

@ -3,8 +3,9 @@ from django.shortcuts import redirect
from django.urls import reverse from django.urls import reverse
from . import models from . import models
from django.contrib import messages from django.contrib import messages
import sys, mimetypes
from django.http import Http404, HttpResponse from django.http import Http404, HttpResponse
import sys
import mimetypes
class EnsureCFSOpenMixin(SingleObjectMixin): class EnsureCFSOpenMixin(SingleObjectMixin):
@ -12,7 +13,9 @@ class EnsureCFSOpenMixin(SingleObjectMixin):
# do not permit editing if call for speakers is not open # do not permit editing if call for speakers is not open
if not self.camp.call_for_speakers_open: if not self.camp.call_for_speakers_open:
messages.error(request, "The Call for Speakers is not 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 # alright, continue with the request
return super().dispatch(request, *args, **kwargs) return super().dispatch(request, *args, **kwargs)
@ -23,8 +26,10 @@ class CreateProposalMixin(SingleObjectMixin):
# set camp and user before saving # set camp and user before saving
form.instance.camp = self.camp form.instance.camp = self.camp
form.instance.user = self.request.user form.instance.user = self.request.user
speaker = form.save() form.save()
return redirect(reverse('proposal_list', kwargs={'camp_slug': self.camp.slug})) return redirect(
reverse('proposal_list', kwargs={'camp_slug': self.camp.slug})
)
class EnsureUnapprovedProposalMixin(SingleObjectMixin): class EnsureUnapprovedProposalMixin(SingleObjectMixin):
@ -54,7 +59,9 @@ class EnsureUserOwnsProposalMixin(SingleObjectMixin):
# make sure that this proposal belongs to the logged in user # make sure that this proposal belongs to the logged in user
if self.get_object().user.username != request.user.username: if self.get_object().user.username != request.user.username:
messages.error(request, "No thanks") 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 # alright, continue with the request
return super().dispatch(request, *args, **kwargs) return super().dispatch(request, *args, **kwargs)
@ -83,7 +90,10 @@ class PictureViewMixin(SingleObjectMixin):
def get_picture_response(self, path): def get_picture_response(self, path):
if 'runserver' in sys.argv or 'runserver_plus' in sys.argv: 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 # 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: else:
# make nginx serve the picture using X-Accel-Redirect # make nginx serve the picture using X-Accel-Redirect
# (this works for nginx only, other webservers use x-sendfile) # (this works for nginx only, other webservers use x-sendfile)

View file

@ -1,7 +1,6 @@
import uuid import uuid
import os import os
import icalendar import icalendar
import CommonMark
import logging import logging
from datetime import timedelta from datetime import timedelta
@ -10,12 +9,9 @@ from django.contrib.postgres.fields import DateTimeRangeField
from django.contrib import messages from django.contrib import messages
from django.db import models from django.db import models
from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.dispatch import receiver
from django.utils.text import slugify from django.utils.text import slugify
from django.conf import settings from django.conf import settings
from django.core.urlresolvers import reverse_lazy 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.core.files.storage import FileSystemStorage
from django.urls import reverse from django.urls import reverse
from django.apps import apps from django.apps import apps
@ -644,7 +640,6 @@ class Speaker(CampRelatedModel):
def get_large_picture_url(self): def get_large_picture_url(self):
return self.get_picture_url('large') return self.get_picture_url('large')
def serialize(self): def serialize(self):
data = { data = {
'name': self.name, 'name': self.name,

View file

@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View file

@ -1,4 +1,3 @@
import datetime
import logging import logging
import os 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.auth.mixins import LoginRequiredMixin
from django.contrib import messages from django.contrib import messages
from django.urls import reverse from django.urls import reverse
from django.db.models import Q
from django.template import Engine, Context from django.template import Engine, Context
import icalendar import icalendar
@ -34,7 +32,7 @@ from . import models
logger = logging.getLogger("bornhack.%s" % __name__) logger = logging.getLogger("bornhack.%s" % __name__)
############## ical calendar ######################################################## # ical calendar
class ICSView(CampViewMixin, View): class ICSView(CampViewMixin, View):
@ -90,7 +88,7 @@ class ICSView(CampViewMixin, View):
return response return response
############## proposals ######################################################## # proposals
class ProposalListView(LoginRequiredMixin, CampViewMixin, ListView): class ProposalListView(LoginRequiredMixin, CampViewMixin, ListView):
@ -241,7 +239,7 @@ class EventProposalDetailView(LoginRequiredMixin, CampViewMixin, EnsureUserOwnsP
template_name = 'eventproposal_detail.html' template_name = 'eventproposal_detail.html'
################## speakers ############################################### # speakers
@method_decorator(require_safe, name='dispatch') @method_decorator(require_safe, name='dispatch')
@ -268,7 +266,7 @@ class SpeakerListView(CampViewMixin, ListView):
template_name = 'speaker_list.html' template_name = 'speaker_list.html'
################## events ############################################## # events
class EventListView(CampViewMixin, ListView): class EventListView(CampViewMixin, ListView):
@ -281,7 +279,7 @@ class EventDetailView(CampViewMixin, DetailView):
template_name = 'schedule_event_detail.html' template_name = 'schedule_event_detail.html'
################## schedule ############################################# # schedule
class NoScriptScheduleView(CampViewMixin, TemplateView): class NoScriptScheduleView(CampViewMixin, TemplateView):
@ -293,13 +291,12 @@ class NoScriptScheduleView(CampViewMixin, TemplateView):
return context return context
class ScheduleView(CampViewMixin, TemplateView): class ScheduleView(CampViewMixin, TemplateView):
template_name = 'schedule_overview.html' template_name = 'schedule_overview.html'
def get_context_data(self, *args, **kwargs): def get_context_data(self, *args, **kwargs):
context = super(ScheduleView, self).get_context_data(**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 return context
@ -308,8 +305,8 @@ class CallForSpeakersView(CampViewMixin, TemplateView):
return '%s_call_for_speakers.html' % self.camp.slug return '%s_call_for_speakers.html' % self.camp.slug
# control center
################## control center #############################################
class ProgramControlCenter(CampViewMixin, TemplateView): class ProgramControlCenter(CampViewMixin, TemplateView):
template_name = "control/index.html" template_name = "control/index.html"