master #409
@ -11,6 +11,7 @@ from abc import abstractmethod
|
||||
from django.contrib.gis import geos
|
||||
from django.contrib.gis.geos import GEOSGeometry
|
||||
from django.core.paginator import Paginator
|
||||
from django.db.models import Q
|
||||
|
||||
from konova.sub_settings.lanis_settings import DEFAULT_SRID_RLP
|
||||
from konova.utils.message_templates import DATA_UNSHARED
|
||||
@ -32,8 +33,8 @@ class AbstractModelAPISerializer:
|
||||
self.lookup = {
|
||||
"id": None, # must be set
|
||||
"deleted__isnull": True,
|
||||
"users__in": [], # must be set
|
||||
}
|
||||
self.shared_lookup = Q() # must be set, so user or team based share will be used properly
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
@abstractmethod
|
||||
@ -76,7 +77,11 @@ class AbstractModelAPISerializer:
|
||||
else:
|
||||
# Return certain object
|
||||
self.lookup["id"] = _id
|
||||
self.lookup["users__in"] = [user]
|
||||
|
||||
self.shared_lookup = Q(
|
||||
Q(users__in=[user]) |
|
||||
Q(teams__in=list(user.shared_teams))
|
||||
)
|
||||
|
||||
def fetch_and_serialize(self):
|
||||
""" Serializes the model entry according to the given lookup data
|
||||
@ -86,7 +91,13 @@ class AbstractModelAPISerializer:
|
||||
Returns:
|
||||
serialized_data (dict)
|
||||
"""
|
||||
entries = self.model.objects.filter(**self.lookup).order_by("id")
|
||||
entries = self.model.objects.filter(
|
||||
**self.lookup
|
||||
).filter(
|
||||
self.shared_lookup
|
||||
).order_by(
|
||||
"id"
|
||||
).distinct()
|
||||
self.paginator = Paginator(entries, self.rpp)
|
||||
requested_entries = self.paginator.page(self.page_number)
|
||||
|
||||
|
@ -6,6 +6,7 @@ Created on: 24.01.22
|
||||
|
||||
"""
|
||||
from django.db import transaction
|
||||
from django.db.models import Q
|
||||
|
||||
from api.utils.serializer.v1.serializer import AbstractModelAPISerializerV1, AbstractCompensationAPISerializerV1Mixin
|
||||
from compensation.models import Compensation
|
||||
@ -21,8 +22,10 @@ class CompensationAPISerializerV1(AbstractModelAPISerializerV1, AbstractCompensa
|
||||
|
||||
def prepare_lookup(self, id, user):
|
||||
super().prepare_lookup(id, user)
|
||||
del self.lookup["users__in"]
|
||||
self.lookup["intervention__users__in"] = [user]
|
||||
self.shared_lookup = Q(
|
||||
Q(intervention__users__in=[user]) |
|
||||
Q(intervention__teams__in=user.shared_teams)
|
||||
)
|
||||
|
||||
def intervention_to_json(self, entry):
|
||||
return {
|
||||
|
@ -6,6 +6,7 @@ Created on: 28.01.22
|
||||
|
||||
"""
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.db.models import Q
|
||||
|
||||
from api.utils.serializer.v1.serializer import DeductableAPISerializerV1Mixin, AbstractModelAPISerializerV1
|
||||
from compensation.models import EcoAccountDeduction, EcoAccount
|
||||
@ -28,9 +29,11 @@ class DeductionAPISerializerV1(AbstractModelAPISerializerV1,
|
||||
|
||||
"""
|
||||
super().prepare_lookup(_id, user)
|
||||
del self.lookup["users__in"]
|
||||
del self.lookup["deleted__isnull"]
|
||||
self.lookup["intervention__users__in"] = [user]
|
||||
self.shared_lookup = Q(
|
||||
Q(intervention__users__in=[user]) |
|
||||
Q(intervention__teams__in=user.shared_teams)
|
||||
)
|
||||
|
||||
def _model_to_geo_json(self, entry):
|
||||
""" Adds the basic data
|
||||
|
@ -23,11 +23,6 @@ class AbstractAPIViewV1(AbstractAPIView):
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.lookup = {
|
||||
"id": None, # must be set in subclasses
|
||||
"deleted__isnull": True,
|
||||
"users__in": [], # must be set in subclasses
|
||||
}
|
||||
super().__init__(*args, **kwargs)
|
||||
self.serializer = self.serializer()
|
||||
|
||||
|
54
konova/management/commands/send_to_egon.py
Normal file
54
konova/management/commands/send_to_egon.py
Normal file
@ -0,0 +1,54 @@
|
||||
"""
|
||||
Author: Michel Peltriaux
|
||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||
Contact: ksp-servicestelle@sgdnord.rlp.de
|
||||
Created on: 18.06.24
|
||||
|
||||
"""
|
||||
from django.db.models import QuerySet
|
||||
|
||||
from intervention.models import Intervention
|
||||
from konova.management.commands.setup import BaseKonovaCommand
|
||||
|
||||
|
||||
class Command(BaseKonovaCommand):
|
||||
help = "Send specific intervention entries to EGON if there are any payments on them"
|
||||
|
||||
def add_arguments(self, parser):
|
||||
try:
|
||||
parser.add_argument("--intervention-ids", type=str)
|
||||
except ValueError as e:
|
||||
self._write_error(f"Argument error: {e}")
|
||||
exit(-1)
|
||||
|
||||
def __handle_arguments(self, options):
|
||||
self.intervention_ids = options["intervention_ids"] or ""
|
||||
self.intervention_ids = self.intervention_ids.split(",")
|
||||
self.intervention_ids = [x.strip() for x in self.intervention_ids]
|
||||
|
||||
def handle(self, *args, **options):
|
||||
try:
|
||||
self.__handle_arguments(options)
|
||||
interventions = self.get_interventions()
|
||||
self.process_egon_sending(interventions)
|
||||
except KeyboardInterrupt:
|
||||
self._break_line()
|
||||
exit(-1)
|
||||
|
||||
def get_interventions(self) -> QuerySet:
|
||||
"""
|
||||
Getter for interventions, defined by parameter 'intervention-ids'
|
||||
|
||||
Returns:
|
||||
interventions (QuerySet): The interventions
|
||||
"""
|
||||
interventions = Intervention.objects.filter(
|
||||
id__in=self.intervention_ids,
|
||||
)
|
||||
self._write_success(f"... Found {interventions.count()} interventions")
|
||||
return interventions
|
||||
|
||||
def process_egon_sending(self, interventions: QuerySet):
|
||||
for intervention in interventions:
|
||||
intervention.send_data_to_egon()
|
||||
self._write_warning(f"... {intervention.identifier} has been sent to EGON (if it has payments)")
|
@ -20,7 +20,7 @@
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="scroll-150 font-italic">
|
||||
{{obj.comment}}
|
||||
{{obj.comment|linebreaks}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user