[#41] Allow users to download the user/planting guide for a payment - backend #92
2 changed files with 12 additions and 11 deletions
|
@ -13,7 +13,7 @@ class ZoneAdmin(admin.ModelAdmin):
|
|||
|
||||
|
||||
class QuestionnaireAdmin(admin.ModelAdmin):
|
||||
list_display = ['address_display', 'location_display', 'soil_variant', 'ecological_district', 'habitat', 'zone']
|
||||
list_display = ['address_display', 'location_display', 'soil_variant', 'ecological_district_display', 'habitat', 'zone']
|
||||
actions = ['export']
|
||||
|
||||
@admin.display(description="Address")
|
||||
|
@ -24,6 +24,14 @@ class QuestionnaireAdmin(admin.ModelAdmin):
|
|||
def location_display(self, obj):
|
||||
return f"({obj.location.x}, {obj.location.y})"
|
||||
|
||||
@admin.display(description="Ecological District")
|
||||
def ecological_district_display(self, obj):
|
||||
return getattr(
|
||||
models.EcologicalDistrictLayer.objects.filter(geom__intersects=obj.location).first(),
|
||||
"ecologic_2",
|
||||
None,
|
||||
)
|
||||
|
||||
@admin.action(description="Export planting guides for selected questionnaires")
|
||||
def export(self, request, queryset):
|
||||
export = models.Export.objects.create(creation_date=timezone.now())
|
||||
|
|
|
@ -208,14 +208,6 @@ class Questionnaire(models.Model):
|
|||
def habitat(self):
|
||||
return self.zone.habitat
|
||||
|
||||
@property
|
||||
def ecological_district_layer(self):
|
||||
return EcologicalDistrictLayer.objects.filter(geom__intersects=self.location).first()
|
||||
|
||||
@property
|
||||
def ecological_district(self):
|
||||
return self.ecological_district_layer.ecologic_2
|
||||
|
||||
@cached_property
|
||||
def address(self):
|
||||
return \
|
||||
|
@ -264,8 +256,9 @@ class Export(models.Model):
|
|||
|
||||
_, files = storage.listdir(f"export_{self.pk}")
|
||||
|
||||
# halved as there are two files (csv, pdf) per questionnaire
|
||||
return 0.5 * len(files) / self.questionnaires.count()
|
||||
# 0.25 multiplier as there are four files per questionnaire:
|
||||
# csv, filters PDF, plants PDF, merged PDF
|
||||
return 0.25 * len(files) / self.questionnaires.count()
|
||||
|
||||
def export(self):
|
||||
from .tasks import generate_pdf
|
||||
|
|
Loading…
Reference in a new issue