From 488767b4f0bbd8abb22a7b569b6ea2a5c1d25187 Mon Sep 17 00:00:00 2001 From: Stephan Telling Date: Sun, 4 Mar 2018 15:38:40 +0100 Subject: [PATCH 01/10] cleanup in shop/ --- src/shop/admin.py | 1 + src/shop/apps.py | 1 + src/shop/coinify.py | 11 +++-- src/shop/context_processors.py | 5 -- src/shop/epay.py | 12 +++-- src/shop/forms.py | 1 - src/shop/managers.py | 2 - src/shop/models.py | 13 ++--- src/shop/tests.py | 3 -- src/shop/urls.py | 1 - src/shop/views.py | 89 +++++++++++++++++++--------------- 11 files changed, 70 insertions(+), 69 deletions(-) delete mode 100644 src/shop/tests.py diff --git a/src/shop/admin.py b/src/shop/admin.py index 5362cf9d..b783e359 100644 --- a/src/shop/admin.py +++ b/src/shop/admin.py @@ -40,6 +40,7 @@ def available_from(product): return "None" available_from.short_description = 'Available from' + def available_to(product): if product.available_in.upper: return product.available_in.upper.strftime("%c") diff --git a/src/shop/apps.py b/src/shop/apps.py index 5edbc95c..8e6d60e7 100644 --- a/src/shop/apps.py +++ b/src/shop/apps.py @@ -2,6 +2,7 @@ from django.apps import AppConfig import logging logger = logging.getLogger("bornhack.%s" % __name__) + class ShopConfig(AppConfig): name = 'shop' diff --git a/src/shop/coinify.py b/src/shop/coinify.py index 1077f97b..3b984c5a 100644 --- a/src/shop/coinify.py +++ b/src/shop/coinify.py @@ -1,8 +1,9 @@ from vendor.coinify.coinify_api import CoinifyAPI -from vendor.coinify.coinify_callback import CoinifyCallback from .models import CoinifyAPIRequest, CoinifyAPIInvoice, CoinifyAPICallback from django.conf import settings -import json, logging +import json +import logging +import requests logger = logging.getLogger("bornhack.%s" % __name__) @@ -34,7 +35,7 @@ def save_coinify_callback(request, order): # now attempt to parse json try: parsed = json.loads(request.body.decode('utf-8')) - except Exception as E: + except Exception: parsed = '' # save this callback to db @@ -89,8 +90,8 @@ def handle_coinify_api_response(req, order): if req.response['success']: # save this new coinify invoice to the DB coinifyinvoice = process_coinify_invoice_json( - invoicejson = req.response['data'], - order = order, + invoicejson=req.response['data'], + order=order, ) return coinifyinvoice else: diff --git a/src/shop/context_processors.py b/src/shop/context_processors.py index 676e42b5..94796c89 100644 --- a/src/shop/context_processors.py +++ b/src/shop/context_processors.py @@ -1,6 +1,3 @@ -from django.conf import settings - - def current_order(request): if request.user.is_authenticated(): order = None @@ -11,5 +8,3 @@ def current_order(request): return {'current_order': order} return {} - - diff --git a/src/shop/epay.py b/src/shop/epay.py index dba32ba1..764cec28 100644 --- a/src/shop/epay.py +++ b/src/shop/epay.py @@ -1,6 +1,7 @@ import hashlib from django.conf import settings + def calculate_epay_hash(order, request): hashstring = ( '{merchant_number}{description}11{amount}DKK' @@ -10,9 +11,9 @@ def calculate_epay_hash(order, request): description=order.description, amount=order.total*100, order_id=order.pk, - accept_url = order.get_epay_accept_url(request), - cancel_url = order.get_cancel_url(request), - callback_url = order.get_epay_callback_url(request), + accept_url=order.get_epay_accept_url(request), + cancel_url=order.get_cancel_url(request), + callback_url=order.get_epay_callback_url(request), md5_secret=settings.EPAY_MD5_SECRET, ) epay_hash = hashlib.md5(hashstring.encode('utf-8')).hexdigest() @@ -24,6 +25,7 @@ def validate_epay_callback(query): for key, value in query.items(): if key != 'hash': hashstring += value - hash = hashlib.md5((hashstring + settings.EPAY_MD5_SECRET).encode('utf-8')).hexdigest() + hash = hashlib.md5( + (hashstring + settings.EPAY_MD5_SECRET).encode('utf-8') + ).hexdigest() return hash == query['hash'] - diff --git a/src/shop/forms.py b/src/shop/forms.py index 6d6f41af..3d8dcbcd 100644 --- a/src/shop/forms.py +++ b/src/shop/forms.py @@ -1,5 +1,4 @@ from django import forms -from .models import Order class AddToOrderForm(forms.Form): diff --git a/src/shop/managers.py b/src/shop/managers.py index e10d1906..dc01c2e6 100644 --- a/src/shop/managers.py +++ b/src/shop/managers.py @@ -1,5 +1,3 @@ -from psycopg2.extras import DateTimeTZRange - from django.db.models import QuerySet from django.utils import timezone diff --git a/src/shop/models.py b/src/shop/models.py index a7ab8953..a8d3acc7 100644 --- a/src/shop/models.py +++ b/src/shop/models.py @@ -1,8 +1,4 @@ -import io import logging -import hashlib -import base64 -import qrcode from django.conf import settings from django.db import models @@ -202,7 +198,7 @@ class Order(CreatedUpdatedModel): if request: messages.success(request, "Created %s tickets of type: %s" % (order_product.quantity, order_product.product.ticket_type.name)) # and mark the OPR as handed_out=True - order_product.handed_out=True + order_product.handed_out = True order_product.save() self.save() @@ -210,8 +206,8 @@ class Order(CreatedUpdatedModel): if not self.paid: messages.error(request, "Order %s is not paid, so cannot mark it as refunded!" % self.pk) else: - self.refunded=True - ### delete any tickets related to this order + self.refunded = True + # delete any tickets related to this order if self.tickets.all(): messages.success(request, "Order %s marked as refunded, deleting %s tickets..." % (self.pk, self.tickets.count())) self.tickets.all().delete() @@ -259,7 +255,6 @@ class Order(CreatedUpdatedModel): if not self.coinify_api_invoices.exists(): return False - coinifyinvoice = None for tempinvoice in self.coinify_api_invoices.all(): # we already have a coinifyinvoice for this order, check if it expired if not tempinvoice.expired: @@ -512,7 +507,7 @@ class CoinifyAPIInvoice(CreatedUpdatedModel): @property def expired(self): - return parse_datetime(self.invoicejson['expire_time']) < timezone.now() + return parse_datetime(self.invoicejson['expire_time']) < timezone.now() class CoinifyAPICallback(CreatedUpdatedModel): diff --git a/src/shop/tests.py b/src/shop/tests.py deleted file mode 100644 index 7ce503c2..00000000 --- a/src/shop/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/src/shop/urls.py b/src/shop/urls.py index 78d7dc1d..5f089d28 100644 --- a/src/shop/urls.py +++ b/src/shop/urls.py @@ -1,6 +1,5 @@ from django.conf.urls import url from .views import * -from tickets.views import ShopTicketListView urlpatterns = [ url(r'^$', ShopIndexView.as_view(), name='index'), diff --git a/src/shop/views.py b/src/shop/views.py index 4d77e1c7..2ed4dc13 100644 --- a/src/shop/views.py +++ b/src/shop/views.py @@ -3,21 +3,23 @@ from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin from django.core.urlresolvers import reverse, reverse_lazy from django.db.models import Count, F -from django.http import HttpResponse, HttpResponseRedirect, HttpResponseBadRequest, Http404 +from django.http import ( + HttpResponse, + HttpResponseRedirect, + HttpResponseBadRequest, + Http404 +) from django.shortcuts import get_object_or_404 from django.views.generic import ( View, - TemplateView, ListView, DetailView, FormView, - UpdateView, ) from django.views.generic.base import RedirectView from django.views.generic.detail import SingleObjectMixin from django.utils.decorators import method_decorator from django.views.decorators.csrf import csrf_exempt -from django.utils.dateparse import parse_datetime from django.utils import timezone from shop.models import ( @@ -27,24 +29,22 @@ from shop.models import ( ProductCategory, EpayCallback, EpayPayment, - CoinifyAPIInvoice, - CoinifyAPICallback, CreditNote, ) from .forms import AddToOrderForm from .epay import calculate_epay_hash, validate_epay_callback from collections import OrderedDict -from vendor.coinify.coinify_api import CoinifyAPI from vendor.coinify.coinify_callback import CoinifyCallback -from .coinify import create_coinify_invoice, save_coinify_callback, process_coinify_invoice_json -import json, time +from .coinify import ( + create_coinify_invoice, + save_coinify_callback, + process_coinify_invoice_json +) import logging logger = logging.getLogger("bornhack.%s" % __name__) - -################################################################################# -### Mixins +# Mixins class EnsureCreditNoteHasPDFMixin(SingleObjectMixin): model = CreditNote @@ -92,7 +92,9 @@ class EnsureUnpaidOrderMixin(SingleObjectMixin): def dispatch(self, request, *args, **kwargs): if self.get_object().paid: messages.error(request, "This order is already paid for!") - return HttpResponseRedirect(reverse_lazy('shop:order_detail', kwargs={'pk': self.get_object().pk})) + return HttpResponseRedirect( + reverse_lazy('shop:order_detail', kwargs={'pk': self.get_object().pk}) + ) return super(EnsureUnpaidOrderMixin, self).dispatch( request, *args, **kwargs @@ -105,7 +107,9 @@ class EnsurePaidOrderMixin(SingleObjectMixin): def dispatch(self, request, *args, **kwargs): if not self.get_object().paid: messages.error(request, "This order is not paid for!") - return HttpResponseRedirect(reverse_lazy('shop:order_detail', kwargs={'pk': self.get_object().pk})) + return HttpResponseRedirect( + reverse_lazy('shop:order_detail', kwargs={'pk': self.get_object().pk}) + ) return super(EnsurePaidOrderMixin, self).dispatch( request, *args, **kwargs @@ -118,7 +122,9 @@ class EnsureClosedOrderMixin(SingleObjectMixin): def dispatch(self, request, *args, **kwargs): if self.get_object().open is not None: messages.error(request, 'This order is still open!') - return HttpResponseRedirect(reverse_lazy('shop:order_detail', kwargs={'pk': self.get_object().pk})) + return HttpResponseRedirect( + reverse_lazy('shop:order_detail', kwargs={'pk': self.get_object().pk}) + ) return super(EnsureClosedOrderMixin, self).dispatch( request, *args, **kwargs @@ -160,15 +166,16 @@ class EnsureOrderHasInvoicePDFMixin(SingleObjectMixin): def dispatch(self, request, *args, **kwargs): if not self.get_object().invoice.pdf: messages.error(request, "This order has no invoice yet!") - return HttpResponseRedirect(reverse_lazy('shop:order_detail', kwargs={'pk': self.get_object().pk})) + return HttpResponseRedirect( + reverse_lazy('shop:order_detail', kwargs={'pk': self.get_object().pk}) + ) return super(EnsureOrderHasInvoicePDFMixin, self).dispatch( request, *args, **kwargs ) -################################################################################# -### Shop views +# Shop views class ShopIndexView(ListView): model = Product template_name = "shop_index.html" @@ -215,7 +222,7 @@ class ProductDetailView(FormView, DetailView): def dispatch(self, request, *args, **kwargs): if not self.get_object().category.public: - ### this product is not publicly available + # this product is not publicly available raise Http404("Product not found") return super(ProductDetailView, self).dispatch( @@ -264,7 +271,9 @@ class ProductDetailView(FormView, DetailView): return super(ProductDetailView, self).form_valid(form) def get_success_url(self): - return Order.objects.get(user=self.request.user, open__isnull=False).get_absolute_url() + return Order.objects.get( + user=self.request.user, open__isnull=False + ).get_absolute_url() class OrderListView(LoginRequiredMixin, ListView): @@ -289,7 +298,9 @@ class OrderDetailView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureOrderH if payment_method in order.PAYMENT_METHODS: if not request.POST.get('accept_terms'): messages.error(request, "You need to accept the general terms and conditions before you can continue!") - return HttpResponseRedirect(reverse_lazy('shop:order_detail', kwargs={'pk': order.pk})) + return HttpResponseRedirect( + reverse_lazy('shop:order_detail', kwargs={'pk': order.pk}) + ) # Set payment method and mark the order as closed order.payment_method = payment_method @@ -389,9 +400,7 @@ class OrderMarkAsPaidView(LoginRequiredMixin, SingleObjectMixin, View): return HttpResponseRedirect(request.META.get('HTTP_REFERER')) -################################################################################# -### Epay views - +# Epay views class EpayFormView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureUnpaidOrderMixin, EnsureClosedOrderMixin, EnsureOrderHasProductsMixin, DetailView): model = Order template_name = 'epay_form.html' @@ -435,18 +444,18 @@ class EpayCallbackView(SingleObjectMixin, View): return HttpResponse(status=400) if order.paid: - ### this order is already paid, perhaps we are seeing a double callback? + # this order is already paid, perhaps we are seeing a double callback? return HttpResponse('OK') - ### epay callback is valid - has the order been paid in full? + # epay callback is valid - has the order been paid in full? if int(query['amount']) == order.total * 100: - ### create an EpayPayment object linking the callback to the order + # create an EpayPayment object linking the callback to the order EpayPayment.objects.create( order=order, callback=callback, txnid=query.get('txnid'), ) - ### and mark order as paid (this will create tickets) + # and mark order as paid (this will create tickets) order.mark_as_paid(request) else: logger.error("valid epay callback with wrong amount detected") @@ -464,15 +473,16 @@ class EpayThanksView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureClosedO if request.GET: # epay redirects the user back to our accepturl with a long # and ugly querystring, redirect user to the clean url - return HttpResponseRedirect(reverse('shop:epay_thanks', kwargs={'pk': self.get_object().pk})) + return HttpResponseRedirect( + reverse('shop:epay_thanks', kwargs={'pk': self.get_object().pk}) + ) return super(EpayThanksView, self).dispatch( request, *args, **kwargs ) -################################################################################# -### Bank Transfer view +# Bank Transfer view class BankTransferView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureUnpaidOrderMixin, EnsureOrderHasProductsMixin, DetailView): model = Order @@ -489,16 +499,14 @@ class BankTransferView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureUnpai return context -################################################################################# -### Cash payment view +# Cash payment view class CashView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureUnpaidOrderMixin, EnsureOrderHasProductsMixin, DetailView): model = Order template_name = 'cash.html' -################################################################################# -### Coinify views +# Coinify views class CoinifyRedirectView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureUnpaidOrderMixin, EnsureClosedOrderMixin, EnsureOrderHasProductsMixin, SingleObjectMixin, RedirectView): model = Order @@ -511,7 +519,9 @@ class CoinifyRedirectView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureUn coinifyinvoice = create_coinify_invoice(order, request) if not coinifyinvoice: messages.error(request, "There was a problem with the payment provider. Please try again later") - return HttpResponseRedirect(reverse_lazy('shop:order_detail', kwargs={'pk': self.get_object().pk})) + return HttpResponseRedirect( + reverse_lazy('shop:order_detail', kwargs={'pk': self.get_object().pk}) + ) return super(CoinifyRedirectView, self).dispatch( request, *args, **kwargs @@ -544,14 +554,17 @@ class CoinifyCallbackView(SingleObjectMixin, View): # attemt to validate the callbackc if sdk.validate_callback(request.body, request.META['HTTP_X_COINIFY_CALLBACK_SIGNATURE']): # mark callback as valid in db - callbackobject.valid=True + callbackobject.valid = True callbackobject.save() else: logger.error("invalid coinify callback detected") return HttpResponseBadRequest('something is fucky') if callbackobject.payload['event'] == 'invoice_state_change' or callbackobject.payload['event'] == 'invoice_manual_resend': - coinifyinvoice = process_coinify_invoice_json(callbackobject.payload['data'], self.get_object()) + process_coinify_invoice_json( + callbackobject.payload['data'], + self.get_object() + ) return HttpResponse('OK') else: logger.error("unsupported callback event %s" % callbackobject.payload['event']) From 8026dba14fa59c879b56c0b69274b6c63220ae2b Mon Sep 17 00:00:00 2001 From: Stephan Telling Date: Sun, 4 Mar 2018 15:39:22 +0100 Subject: [PATCH 02/10] cleanup in sponsors/ --- src/sponsors/apps.py | 2 -- src/sponsors/models.py | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sponsors/apps.py b/src/sponsors/apps.py index c1102258..4db5584e 100644 --- a/src/sponsors/apps.py +++ b/src/sponsors/apps.py @@ -1,5 +1,3 @@ - - from django.apps import AppConfig diff --git a/src/sponsors/models.py b/src/sponsors/models.py index c7f78731..f1823b99 100644 --- a/src/sponsors/models.py +++ b/src/sponsors/models.py @@ -43,6 +43,7 @@ class Sponsor(CampRelatedModel): def camp(self): return self.tier.camp + class SponsorTier(CampRelatedModel): name = models.CharField( max_length=25, From 5bffb9c53a092014086d9437ef3abad390436f28 Mon Sep 17 00:00:00 2001 From: Stephan Telling Date: Sun, 4 Mar 2018 15:40:34 +0100 Subject: [PATCH 03/10] cleanup in villages/ --- src/villages/apps.py | 2 -- src/villages/mixins.py | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/villages/apps.py b/src/villages/apps.py index 13a45918..473aafca 100644 --- a/src/villages/apps.py +++ b/src/villages/apps.py @@ -1,5 +1,3 @@ - - from django.apps import AppConfig diff --git a/src/villages/mixins.py b/src/villages/mixins.py index 9b157ef6..a6356ed2 100644 --- a/src/villages/mixins.py +++ b/src/villages/mixins.py @@ -9,9 +9,9 @@ class EnsureWritableCampMixin(SingleObjectMixin): # do not permit view if camp is in readonly mode if self.camp.read_only: messages.error(request, "No thanks") - return redirect(reverse('village_list', kwargs={'camp_slug': self.camp.slug})) + return redirect( + reverse('village_list', kwargs={'camp_slug': self.camp.slug}) + ) # alright, continue with the request return super().dispatch(request, *args, **kwargs) - - From f9ba48ddfb77a0ba5be11f566d83a85e100e11c4 Mon Sep 17 00:00:00 2001 From: Stephan Telling Date: Sun, 4 Mar 2018 15:48:57 +0100 Subject: [PATCH 04/10] 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" From aac89c0a9c2626984f54d263c8488f8748cb118b Mon Sep 17 00:00:00 2001 From: Stephan Telling Date: Sun, 4 Mar 2018 15:50:05 +0100 Subject: [PATCH 05/10] cleanup in profiles/ --- src/profiles/admin.py | 1 + src/profiles/tests.py | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) delete mode 100644 src/profiles/tests.py diff --git a/src/profiles/admin.py b/src/profiles/admin.py index a2c46950..012a4199 100644 --- a/src/profiles/admin.py +++ b/src/profiles/admin.py @@ -1,6 +1,7 @@ from django.contrib import admin from .models import Profile + @admin.register(Profile) class OrderAdmin(admin.ModelAdmin): actions = ['approve_public_credit_names'] diff --git a/src/profiles/tests.py b/src/profiles/tests.py deleted file mode 100644 index 7ce503c2..00000000 --- a/src/profiles/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. From e482501d7bd91e1247300cffd956730e565a1dd4 Mon Sep 17 00:00:00 2001 From: Stephan Telling Date: Sun, 4 Mar 2018 15:51:33 +0100 Subject: [PATCH 06/10] cleanup in news/ --- src/news/apps.py | 2 -- src/news/models.py | 2 -- src/news/tests.py | 3 --- src/news/views.py | 3 ++- 4 files changed, 2 insertions(+), 8 deletions(-) delete mode 100644 src/news/tests.py diff --git a/src/news/apps.py b/src/news/apps.py index 0077041d..5a7b92d0 100644 --- a/src/news/apps.py +++ b/src/news/apps.py @@ -1,5 +1,3 @@ - - from django.apps import AppConfig diff --git a/src/news/models.py b/src/news/models.py index ee8a028e..86b2b786 100644 --- a/src/news/models.py +++ b/src/news/models.py @@ -1,5 +1,3 @@ - - from django.db import models from django.utils import encoding from django.utils.text import slugify diff --git a/src/news/tests.py b/src/news/tests.py deleted file mode 100644 index 7ce503c2..00000000 --- a/src/news/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/src/news/views.py b/src/news/views.py index 8056bc9d..7d324709 100644 --- a/src/news/views.py +++ b/src/news/views.py @@ -1,6 +1,7 @@ from django.views.generic import ListView, DetailView from django.utils import timezone -from .models import * +from .models import NewsItem + class NewsIndex(ListView): model = NewsItem From f20695094ec2c764afe074eacbf251db0331a47e Mon Sep 17 00:00:00 2001 From: Stephan Telling Date: Sun, 4 Mar 2018 15:52:56 +0100 Subject: [PATCH 07/10] cleanup in ircbot/ --- src/ircbot/admin.py | 2 +- src/ircbot/apps.py | 2 -- src/ircbot/ircworker.py | 5 +++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ircbot/admin.py b/src/ircbot/admin.py index 91278423..eff2cb89 100644 --- a/src/ircbot/admin.py +++ b/src/ircbot/admin.py @@ -1,5 +1,5 @@ from django.contrib import admin -from .models import * +from .models import OutgoingIrcMessage admin.site.register(OutgoingIrcMessage) diff --git a/src/ircbot/apps.py b/src/ircbot/apps.py index d057f8c7..54a5147b 100644 --- a/src/ircbot/apps.py +++ b/src/ircbot/apps.py @@ -1,5 +1,3 @@ - - from django.apps import AppConfig diff --git a/src/ircbot/ircworker.py b/src/ircbot/ircworker.py index 94fac174..b0afd363 100644 --- a/src/ircbot/ircworker.py +++ b/src/ircbot/ircworker.py @@ -1,5 +1,6 @@ from django.conf import settings -import logging, irc3 +import logging +import irc3 logging.basicConfig(level=logging.INFO) logger = logging.getLogger('bornhack.%s' % __name__) @@ -24,5 +25,5 @@ def do_work(): irc3.IrcBot(**config).run(forever=True) except Exception as E: logger.exception("Got exception inside do_work for %s" % self.workermodule) - raise + raise E From d20a964793e5d33841b6269cb6abc7e0cacf5a44 Mon Sep 17 00:00:00 2001 From: Stephan Telling Date: Sun, 4 Mar 2018 15:56:11 +0100 Subject: [PATCH 08/10] cleanup in info/ --- src/info/admin.py | 5 ++++- src/info/apps.py | 2 -- src/info/models.py | 32 +++++++++++++++----------------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/info/admin.py b/src/info/admin.py index 028c25aa..941ac13a 100644 --- a/src/info/admin.py +++ b/src/info/admin.py @@ -1,5 +1,8 @@ from django.contrib import admin -from .models import * +from .models import ( + InfoItem, + InfoCategory +) @admin.register(InfoItem) diff --git a/src/info/apps.py b/src/info/apps.py index 7fca4660..3891f47e 100644 --- a/src/info/apps.py +++ b/src/info/apps.py @@ -1,5 +1,3 @@ - - from django.apps import AppConfig diff --git a/src/info/models.py b/src/info/models.py index ac6964c2..f507c683 100644 --- a/src/info/models.py +++ b/src/info/models.py @@ -11,22 +11,22 @@ class InfoCategory(CampRelatedModel): camp = models.ForeignKey( 'camps.Camp', - related_name = 'infocategories', - on_delete = models.PROTECT + related_name='infocategories', + on_delete=models.PROTECT ) headline = models.CharField( - max_length = 100, - help_text = "The headline of this info category" + max_length=100, + help_text="The headline of this info category" ) anchor = models.SlugField( - help_text = "The HTML anchor to use for this info category." + help_text="The HTML anchor to use for this info category." ) weight = models.PositiveIntegerField( - help_text = 'Determines sorting/ordering. Heavier categories sink to the bottom. Categories with the same weight are ordered alphabetically. Defaults to 100.', - default = 100, + help_text='Determines sorting/ordering. Heavier categories sink to the bottom. Categories with the same weight are ordered alphabetically. Defaults to 100.', + default=100, ) def clean(self): @@ -45,26 +45,26 @@ class InfoItem(CampRelatedModel): category = models.ForeignKey( 'info.InfoCategory', - related_name = 'infoitems', - on_delete = models.PROTECT + related_name='infoitems', + on_delete=models.PROTECT ) headline = models.CharField( - max_length = 100, - help_text = "Headline of this info item." + max_length=100, + help_text="Headline of this info item." ) anchor = models.SlugField( - help_text = "The HTML anchor to use for this info item." + help_text="The HTML anchor to use for this info item." ) body = models.TextField( - help_text = 'Body of this info item. Markdown is supported.' + help_text='Body of this info item. Markdown is supported.' ) weight = models.PositiveIntegerField( - help_text = 'Determines sorting/ordering. Heavier items sink to the bottom. Items with the same weight are ordered alphabetically. Defaults to 100.', - default = 100, + help_text='Determines sorting/ordering. Heavier items sink to the bottom. Items with the same weight are ordered alphabetically. Defaults to 100.', + default=100, ) @property @@ -78,5 +78,3 @@ class InfoItem(CampRelatedModel): def __str__(self): return '%s (%s)' % (self.headline, self.category) - - From aaa4df27db2d97f98ad2eaa8cc31727abed70ed8 Mon Sep 17 00:00:00 2001 From: Stephan Telling Date: Sun, 4 Mar 2018 15:58:20 +0100 Subject: [PATCH 09/10] cleanup in camps/ --- src/camps/context_processors.py | 2 -- src/camps/mixins.py | 4 +--- src/camps/utils.py | 4 ++-- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/camps/context_processors.py b/src/camps/context_processors.py index a1b290f7..bedd7ee2 100644 --- a/src/camps/context_processors.py +++ b/src/camps/context_processors.py @@ -1,6 +1,4 @@ -from django.conf import settings from .models import Camp -from django.utils import timezone def camp(request): diff --git a/src/camps/mixins.py b/src/camps/mixins.py index 5234c1c7..83338f84 100644 --- a/src/camps/mixins.py +++ b/src/camps/mixins.py @@ -17,10 +17,8 @@ class CampViewMixin(object): if queryset: # check if we have a foreignkey to Camp, filter if so for field in queryset.model._meta.fields: - if field.name=="camp" and field.related_model._meta.label == "camps.Camp": + if field.name == "camp" and field.related_model._meta.label == "camps.Camp": return queryset.filter(camp=self.camp) # Camp relation not found, or queryset is empty, return it unaltered return queryset - - diff --git a/src/camps/utils.py b/src/camps/utils.py index 036a45dd..c4e2838e 100644 --- a/src/camps/utils.py +++ b/src/camps/utils.py @@ -2,12 +2,14 @@ from camps.models import Camp from django.utils import timezone from django.contrib import admin + def get_current_camp(): try: return Camp.objects.get(camp__contains=timezone.now()) except Camp.DoesNotExist: return False + class CampPropertyListFilter(admin.SimpleListFilter): """ SimpleListFilter to filter models by camp when camp is @@ -27,7 +29,6 @@ class CampPropertyListFilter(admin.SimpleListFilter): for camp in unique_camps: yield (camp.slug, camp.title) - def queryset(self, request, queryset): # if self.value() is None return everything if not self.value(): @@ -45,4 +46,3 @@ class CampPropertyListFilter(admin.SimpleListFilter): if item.camp != camp: queryset = queryset.exclude(pk=item.pk) return queryset - From 663099a6030b0a29613bd8901a47a8e7bc3b650d Mon Sep 17 00:00:00 2001 From: Stephan Telling Date: Sun, 4 Mar 2018 15:59:12 +0100 Subject: [PATCH 10/10] cleanup in bar/ --- src/bar/admin.py | 3 --- src/bar/apps.py | 2 -- src/bar/models.py | 1 - src/bar/views.py | 1 - 4 files changed, 7 deletions(-) diff --git a/src/bar/admin.py b/src/bar/admin.py index 337ee768..ee04ed0f 100644 --- a/src/bar/admin.py +++ b/src/bar/admin.py @@ -1,5 +1,4 @@ from django.contrib import admin - from .models import ProductCategory, Product @@ -12,5 +11,3 @@ class ProductCategoryAdmin(admin.ModelAdmin): class ProductAdmin(admin.ModelAdmin): list_display = ['name', 'price', 'category', 'in_stock'] list_editable = ['in_stock'] - - diff --git a/src/bar/apps.py b/src/bar/apps.py index 7a6c111b..e24009a8 100644 --- a/src/bar/apps.py +++ b/src/bar/apps.py @@ -1,5 +1,3 @@ - - from django.apps import AppConfig diff --git a/src/bar/models.py b/src/bar/models.py index 9c70a485..8d4d3b87 100644 --- a/src/bar/models.py +++ b/src/bar/models.py @@ -1,5 +1,4 @@ from django.db import models - from utils.models import CampRelatedModel diff --git a/src/bar/views.py b/src/bar/views.py index eb0cf10e..747a744e 100644 --- a/src/bar/views.py +++ b/src/bar/views.py @@ -6,4 +6,3 @@ class MenuView(ListView): model = ProductCategory template_name = "bar_menu.html" context_object_name = "categories" -