Refactoring to konova
This commit is contained in:
@@ -5,14 +5,13 @@ Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 17.11.20
|
||||
|
||||
"""
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.gis.db import models
|
||||
from django.utils.timezone import now
|
||||
|
||||
from compensation.settings import COMPENSATION_IDENTIFIER_LENGTH, COMPENSATION_IDENTIFIER_TEMPLATE
|
||||
from konova.models import BaseObject, BaseResource
|
||||
from konova.models import BaseObject, BaseResource, Geometry
|
||||
from konova.utils.generators import generate_random_string
|
||||
from process.models import Process
|
||||
from organisation.models import Organisation
|
||||
|
||||
|
||||
class CompensationControl(BaseResource):
|
||||
@@ -22,7 +21,7 @@ class CompensationControl(BaseResource):
|
||||
deadline = models.ForeignKey("konova.Deadline", on_delete=models.SET_NULL, null=True, blank=True)
|
||||
type = models.CharField(max_length=500, null=True, blank=True)
|
||||
expected_result = models.CharField(max_length=500, null=True, blank=True, help_text="The expected outcome, that needs to be controlled")
|
||||
by_authority = models.CharField(max_length=500, null=True, blank=True)
|
||||
by_authority = models.ForeignKey(Organisation, null=True, blank=True, on_delete=models.SET_NULL)
|
||||
comment = models.TextField()
|
||||
|
||||
|
||||
@@ -31,8 +30,7 @@ class CompensationState(models.Model):
|
||||
Compensations must define the state of an area before and after the compensation.
|
||||
"""
|
||||
biotope_type = models.CharField(max_length=500, null=True, blank=True)
|
||||
amount = models.FloatField()
|
||||
unit = models.CharField(max_length=100, null=True, blank=True)
|
||||
surface = models.FloatField()
|
||||
|
||||
|
||||
class CompensationAction(BaseResource):
|
||||
@@ -50,22 +48,21 @@ 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.
|
||||
"""
|
||||
is_old_law = models.BooleanField(default=False)
|
||||
type = models.CharField(max_length=500, null=True, blank=True)
|
||||
registration_office = models.CharField(max_length=500, null=True, blank=True) # ToDo: Really needed?
|
||||
process = models.ForeignKey("process.Process", related_name="compensations", on_delete=models.CASCADE)
|
||||
registration_office = models.ForeignKey(Organisation, on_delete=models.SET_NULL, null=True)
|
||||
conservation_office = models.ForeignKey(Organisation, on_delete=models.SET_NULL, null=True)
|
||||
|
||||
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!
|
||||
|
||||
before_states = models.ManyToManyField(CompensationState, blank=True, related_name='+')
|
||||
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")
|
||||
initial_states = models.ManyToManyField(CompensationState, blank=True, related_name='+')
|
||||
final_states = models.ManyToManyField(CompensationState, blank=True, related_name='+')
|
||||
geometry = models.MultiPolygonField(null=True, blank=True)
|
||||
documents = models.ManyToManyField("konova.Document", blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return "{} of {}".format(self.type, self.process)
|
||||
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:
|
||||
@@ -92,36 +89,8 @@ class Compensation(BaseObject):
|
||||
self.identifier = new_id
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
@staticmethod
|
||||
def get_role_objects(user: User, order_by: str = "-created_on"):
|
||||
""" Returns objects depending on the currently selected role of the user
|
||||
|
||||
* REGISTRATIONOFFICE
|
||||
* User can see the processes where registration_office is set to the organisation of the currently selected role
|
||||
* User can see self-created processes
|
||||
* LICENSINGOFFICE
|
||||
* same
|
||||
* DATAPROVIDER
|
||||
* User can see only self-created processes
|
||||
|
||||
Args:
|
||||
user (User): The performing user
|
||||
order_by (str): Order by which Process attribute
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
role = user.current_role
|
||||
if role is None:
|
||||
return Compensation.objects.none()
|
||||
processes = Process.get_role_objects(user, order_by)
|
||||
processes.prefetch_related("compensations")
|
||||
compensations = []
|
||||
[compensations.extend(process.compensations.all()) for process in processes]
|
||||
return compensations
|
||||
|
||||
|
||||
class EcoAccount(BaseResource):
|
||||
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.
|
||||
@@ -129,17 +98,4 @@ class EcoAccount(BaseResource):
|
||||
'Withdrawing' can only be applied by shrinking the size of the available geometry and declaring the withdrawed
|
||||
geometry as a compensation for a process.
|
||||
"""
|
||||
is_old_law = models.BooleanField(default=False)
|
||||
type = models.CharField(max_length=500, null=True, blank=True)
|
||||
licensing_authority_document_identifier = models.CharField(max_length=500, null=True, blank=True)
|
||||
registration_office = models.CharField(max_length=500, null=True, blank=True)
|
||||
handler = models.CharField(max_length=500, null=True, blank=True)
|
||||
handler_comments = models.TextField()
|
||||
geometry = models.GeometryCollectionField()
|
||||
documents = models.ManyToManyField("konova.Document")
|
||||
initial_states = models.ManyToManyField(CompensationState, blank=True, related_name='+')
|
||||
final_states = models.ManyToManyField(CompensationState, blank=True, related_name='+')
|
||||
actions = models.ManyToManyField(CompensationAction)
|
||||
deadline_maintaining = models.ForeignKey("konova.Deadline", on_delete=models.SET_NULL, null=True, blank=True)
|
||||
deadline_other = models.ManyToManyField("konova.Deadline", blank=True, related_name='+')
|
||||
comments = models.TextField()
|
||||
handler = models.CharField(max_length=500, null=True, blank=True, help_text="Who is responsible for handling the actions")
|
||||
|
||||
@@ -9,7 +9,6 @@ from konova.decorators import *
|
||||
|
||||
|
||||
@login_required
|
||||
@resolve_user_role
|
||||
def index_view(request: HttpRequest):
|
||||
"""
|
||||
Renders the index view for compensation
|
||||
@@ -22,7 +21,7 @@ def index_view(request: HttpRequest):
|
||||
"""
|
||||
template = "generic_index.html"
|
||||
user = request.user
|
||||
compensations = Compensation.get_role_objects(user)
|
||||
compensations = None # ToDo
|
||||
table = CompensationTable(
|
||||
request=request,
|
||||
queryset=compensations
|
||||
|
||||
Reference in New Issue
Block a user