Compensation action
* adds compensation action to compensation detail view * adds adding/removing logic for compensation action * adds bootstrap style to select fields in forms * refactors UnitEnum into UnitChoices using models.TextChoices (Django 3.x) * adds translations
This commit is contained in:
+29
-1
@@ -11,6 +11,7 @@ from django.core.validators import MinValueValidator, MaxValueValidator
|
||||
from django.db import transaction
|
||||
from django.utils import timezone
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from compensation.settings import COMPENSATION_IDENTIFIER_LENGTH, COMPENSATION_IDENTIFIER_TEMPLATE
|
||||
from intervention.models import Intervention, ResponsibilityData
|
||||
@@ -63,18 +64,45 @@ class CompensationState(UuidModel):
|
||||
return "{} | {} m²".format(self.biotope_type, self.surface)
|
||||
|
||||
|
||||
class UnitChoices(models.TextChoices):
|
||||
"""
|
||||
Predefines units for selection
|
||||
"""
|
||||
cm = "cm", _("cm")
|
||||
m = "m", _("m")
|
||||
km = "km", _("km")
|
||||
qm = "qm", _("m²")
|
||||
ha = "ha", _("ha")
|
||||
st = "pcs", _("Pieces") # pieces
|
||||
|
||||
|
||||
class CompensationAction(BaseResource):
|
||||
"""
|
||||
Compensations include actions like planting trees, refreshing rivers and so on.
|
||||
"""
|
||||
action_type = models.CharField(max_length=500, null=True, blank=True)
|
||||
amount = models.FloatField()
|
||||
unit = models.CharField(max_length=100, null=True, blank=True)
|
||||
unit = models.CharField(max_length=100, null=True, blank=True, choices=UnitChoices.choices)
|
||||
control = models.ForeignKey(CompensationControl, on_delete=models.SET_NULL, null=True, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return "{} | {} {}".format(self.action_type, self.amount, self.unit)
|
||||
|
||||
@property
|
||||
def unit_humanize(self):
|
||||
""" Returns humanized version of enum
|
||||
|
||||
Used for template rendering
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
choices = UnitChoices.choices
|
||||
for choice in choices:
|
||||
if choice[0] == self.unit:
|
||||
return choice[1]
|
||||
return None
|
||||
|
||||
|
||||
class AbstractCompensation(BaseObject):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user