|
12 | 12 | from django.contrib import messages |
13 | 13 | from django.contrib.auth.mixins import LoginRequiredMixin |
14 | 14 | from django.contrib.gis.geos import Point |
15 | | -from django.utils.decorators import method_decorator |
16 | | -from django.views.decorators.cache import cache_page |
17 | | -from django.views.decorators.cache import cache_control |
18 | 15 | from django.core.exceptions import BadRequest |
19 | 16 | from django.core.exceptions import PermissionDenied |
20 | 17 | from django.core.serializers import serialize |
| 18 | +from django.db.models import Count |
21 | 19 | from django.db.models import Q |
22 | 20 | from django.http import HttpRequest |
23 | 21 | from django.http import HttpResponse |
|
27 | 25 | from django.templatetags.static import static |
28 | 26 | from django.urls import reverse |
29 | 27 | from django.utils.decorators import method_decorator |
| 28 | +from django.views.decorators.cache import cache_control |
| 29 | +from django.views.decorators.cache import cache_page |
30 | 30 | from django.views.decorators.csrf import csrf_exempt |
31 | 31 | from django.views.generic import CreateView |
32 | 32 | from django.views.generic import DeleteView |
@@ -136,21 +136,34 @@ def get_layers(self) -> QuerySet: |
136 | 136 | user_teams = self.request.user.teammember_set.filter( |
137 | 137 | team__camp=self.camp, |
138 | 138 | ).values_list("team__name", flat=True) |
139 | | - return Layer.objects.filter( |
140 | | - ((Q(responsible_team__camp=self.camp) | Q(responsible_team=None)) & Q(public=True)) |
141 | | - | (Q(responsible_team__name__in=user_teams) & Q(public=False)), |
| 139 | + return ( |
| 140 | + Layer.objects.filter( |
| 141 | + ((Q(responsible_team__camp=self.camp) | Q(responsible_team=None)) & Q(public=True)) |
| 142 | + | (Q(responsible_team__name__in=user_teams) & Q(public=False)), |
| 143 | + ) |
| 144 | + .annotate(num_features=Count("features")) |
| 145 | + .filter(num_features__gt=0) |
142 | 146 | ) |
143 | 147 |
|
144 | 148 | def get_context_data(self, **kwargs) -> dict: |
145 | 149 | """Get the context data.""" |
146 | 150 | context = super().get_context_data(**kwargs) |
147 | | - context["facilitytype_list"] = FacilityType.objects.filter( |
148 | | - responsible_team__camp=self.camp, |
| 151 | + context["facilitytype_list"] = ( |
| 152 | + FacilityType.objects.filter( |
| 153 | + responsible_team__camp=self.camp, |
| 154 | + ) |
| 155 | + .annotate(num_facilities=Count("facilities")) |
| 156 | + .filter(num_facilities__gt=0) |
149 | 157 | ) |
150 | 158 | context["layers"] = self.get_layers() |
151 | | - context["user_location_types"] = UserLocationType.objects.filter( |
152 | | - user_locations__isnull=False, |
153 | | - ).distinct() |
| 159 | + context["user_location_types"] = ( |
| 160 | + UserLocationType.objects.filter( |
| 161 | + user_locations__isnull=False, |
| 162 | + ) |
| 163 | + .annotate(num_features=Count("user_locations")) |
| 164 | + .filter(num_features__gt=0) |
| 165 | + .distinct() |
| 166 | + ) |
154 | 167 | context["externalLayers"] = ExternalLayer.objects.filter( |
155 | 168 | Q(responsible_team__camp=self.camp) | Q(responsible_team=None), |
156 | 169 | ) |
|
0 commit comments