#38 User requests
* implements 2) "Multiple revocations for interventions"
This commit is contained in:
+11
-10
@@ -68,6 +68,7 @@ class Revocation(BaseResource):
|
||||
Holds revocation data e.g. for intervention objects
|
||||
"""
|
||||
date = models.DateField(null=True, blank=True, help_text="Revocation from")
|
||||
legal = models.ForeignKey("LegalData", null=False, blank=False, on_delete=models.CASCADE, help_text="Refers to 'Widerspruch am'", related_name="revocations")
|
||||
comment = models.TextField(null=True, blank=True)
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
@@ -99,7 +100,7 @@ class RevocationDocument(AbstractDocument):
|
||||
Returns:
|
||||
intervention (Intervention)
|
||||
"""
|
||||
return self.instance.legaldata.intervention
|
||||
return self.instance.legal.intervention
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
"""
|
||||
@@ -118,13 +119,14 @@ class RevocationDocument(AbstractDocument):
|
||||
# Remove the file itself
|
||||
super().delete(*args, **kwargs)
|
||||
|
||||
# Always remove 'revocation' folder
|
||||
# Always remove 'revocation' folder if the one revocation we just processed is the only one left
|
||||
folder_path = self.file.path.split("/")
|
||||
try:
|
||||
shutil.rmtree("/".join(folder_path[:-1]))
|
||||
except FileNotFoundError:
|
||||
# Revocation subfolder seems to be missing already
|
||||
pass
|
||||
if revoc_docs.count() == 0:
|
||||
try:
|
||||
shutil.rmtree("/".join(folder_path[:-1]))
|
||||
except FileNotFoundError:
|
||||
# Revocation subfolder seems to be missing already
|
||||
pass
|
||||
|
||||
if other_intervention_docs.count() == 0:
|
||||
# If there are no further documents for the intervention, we can simply remove the whole folder as well!
|
||||
@@ -167,8 +169,6 @@ class LegalData(UuidModel):
|
||||
}
|
||||
)
|
||||
|
||||
revocation = models.OneToOneField(Revocation, null=True, blank=True, help_text="Refers to 'Widerspruch am'", on_delete=models.SET_NULL)
|
||||
|
||||
|
||||
class Intervention(BaseObject, ShareableObject, RecordableObject, CheckableObject):
|
||||
"""
|
||||
@@ -277,7 +277,7 @@ class Intervention(BaseObject, ShareableObject, RecordableObject, CheckableObjec
|
||||
regular_docs (QuerySet): The queryset of regular other documents
|
||||
"""
|
||||
revoc_docs = RevocationDocument.objects.filter(
|
||||
instance=self.legal.revocation
|
||||
instance__in=self.legal.revocations.all()
|
||||
)
|
||||
regular_docs = InterventionDocument.objects.filter(
|
||||
instance=self
|
||||
@@ -366,6 +366,7 @@ class InterventionDocument(AbstractDocument):
|
||||
if folder_path is not None:
|
||||
try:
|
||||
shutil.rmtree(folder_path)
|
||||
pass
|
||||
except FileNotFoundError:
|
||||
# Folder seems to be missing already...
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user