From aaa4df27db2d97f98ad2eaa8cc31727abed70ed8 Mon Sep 17 00:00:00 2001 From: Stephan Telling Date: Sun, 4 Mar 2018 15:58:20 +0100 Subject: [PATCH] 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 -