Refactoring to konova
This commit is contained in:
@@ -17,8 +17,7 @@ class CompensationStateAdmin(admin.ModelAdmin):
|
||||
list_display = [
|
||||
"id",
|
||||
"biotope_type",
|
||||
"amount",
|
||||
"unit",
|
||||
"surface",
|
||||
]
|
||||
|
||||
|
||||
@@ -35,7 +34,6 @@ class CompensationActionAdmin(admin.ModelAdmin):
|
||||
class CompensationAdmin(admin.ModelAdmin):
|
||||
list_display = [
|
||||
"id",
|
||||
"type",
|
||||
"created_on",
|
||||
]
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ Created on: 17.11.20
|
||||
|
||||
"""
|
||||
from django.contrib.gis.db import models
|
||||
from django.core.validators import MinValueValidator
|
||||
from django.utils import timezone
|
||||
from django.utils.timezone import now
|
||||
|
||||
from compensation.settings import COMPENSATION_IDENTIFIER_LENGTH, COMPENSATION_IDENTIFIER_TEMPLATE
|
||||
@@ -14,6 +16,14 @@ from konova.utils.generators import generate_random_string
|
||||
from organisation.models import Organisation
|
||||
|
||||
|
||||
class Payment(BaseResource):
|
||||
"""
|
||||
Holds data on a payment for an intervention (alternative to a classic compensation)
|
||||
"""
|
||||
amount = models.FloatField(validators=[MinValueValidator(limit_value=0.00)])
|
||||
due_on = models.DateField(null=True)
|
||||
|
||||
|
||||
class CompensationControl(BaseResource):
|
||||
"""
|
||||
Holds data on how a compensation shall be controlled
|
||||
@@ -48,8 +58,8 @@ class Compensation(BaseObject):
|
||||
The compensation holds information about which actions have to be performed until which date, who is in charge
|
||||
of this, which legal authority is the point of contact, and so on.
|
||||
"""
|
||||
registration_office = models.ForeignKey(Organisation, on_delete=models.SET_NULL, null=True)
|
||||
conservation_office = models.ForeignKey(Organisation, on_delete=models.SET_NULL, null=True)
|
||||
registration_office = models.ForeignKey(Organisation, on_delete=models.SET_NULL, null=True, related_name="+")
|
||||
conservation_office = models.ForeignKey(Organisation, on_delete=models.SET_NULL, null=True, related_name="+")
|
||||
|
||||
ground_definitions = models.CharField(max_length=500, null=True, blank=True) # ToDo: Need to be M2M to laws!
|
||||
action_definitions = models.CharField(max_length=500, null=True, blank=True) # ToDo: Need to be M2M to laws!
|
||||
@@ -58,14 +68,14 @@ class Compensation(BaseObject):
|
||||
after_states = models.ManyToManyField(CompensationState, blank=True, related_name='+')
|
||||
actions = models.ManyToManyField(CompensationAction)
|
||||
|
||||
deadline_creation = models.ForeignKey("konova.Deadline", on_delete=models.SET_NULL, null=True, blank=True, related_name="deadline_creation")
|
||||
deadline_maintaining = models.ForeignKey("konova.Deadline", on_delete=models.SET_NULL, null=True, blank=True, related_name="deadline_maintaining")
|
||||
deadline_creation = models.ForeignKey("konova.Deadline", on_delete=models.SET_NULL, null=True, blank=True, related_name="+")
|
||||
deadline_maintaining = models.ForeignKey("konova.Deadline", on_delete=models.SET_NULL, null=True, blank=True, related_name="+")
|
||||
|
||||
geometry = models.ForeignKey(Geometry, null=True, blank=True, on_delete=models.SET_NULL)
|
||||
documents = models.ManyToManyField("konova.Document", blank=True)
|
||||
|
||||
@staticmethod
|
||||
def __generate_new_identifier() -> str:
|
||||
def _generate_new_identifier() -> str:
|
||||
""" Generates a new identifier for the intervention object
|
||||
|
||||
Returns:
|
||||
@@ -80,12 +90,30 @@ class Compensation(BaseObject):
|
||||
_str = "{}{}{}".format(curr_month, curr_year, rand_str)
|
||||
return COMPENSATION_IDENTIFIER_TEMPLATE.format(_str)
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
""" Custom delete functionality
|
||||
|
||||
Does not delete from database but sets a timestamp for being deleted on and which user deleted the object
|
||||
|
||||
Args:
|
||||
*args ():
|
||||
**kwargs ():
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
_now = timezone.now()
|
||||
_user = kwargs.get("user", None)
|
||||
self.deleted_on = _now
|
||||
self.deleted_by = _user
|
||||
self.save()
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if self.identifier is None or len(self.identifier) == 0:
|
||||
# Create new identifier
|
||||
new_id = self.__generate_new_identifier()
|
||||
new_id = self._generate_new_identifier()
|
||||
while Compensation.objects.filter(identifier=new_id).exists():
|
||||
new_id = self.__generate_new_identifier()
|
||||
new_id = self._generate_new_identifier()
|
||||
self.identifier = new_id
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
@@ -94,8 +122,5 @@ class EcoAccount(Compensation):
|
||||
"""
|
||||
An eco account is a kind of 'prepaid' compensation. It can be compared to an account that already has been filled
|
||||
with some kind of currency. From this account one is able to 'withdraw' currency for current projects.
|
||||
|
||||
'Withdrawing' can only be applied by shrinking the size of the available geometry and declaring the withdrawed
|
||||
geometry as a compensation for a process.
|
||||
"""
|
||||
handler = models.CharField(max_length=500, null=True, blank=True, help_text="Who is responsible for handling the actions")
|
||||
|
||||
@@ -24,11 +24,6 @@ class CompensationTable(BaseTable):
|
||||
orderable=True,
|
||||
accessor="title",
|
||||
)
|
||||
p = tables.Column(
|
||||
verbose_name=_("Process"),
|
||||
orderable=True,
|
||||
accessor="process",
|
||||
)
|
||||
d = tables.Column(
|
||||
verbose_name=_("Created on"),
|
||||
orderable=True,
|
||||
|
||||
Reference in New Issue
Block a user