#38 User requests

* implements 2) "Multiple revocations for interventions"
This commit is contained in:
2021-11-15 12:18:22 +01:00
parent a0df7f4fe1
commit faffd454b9
8 changed files with 227 additions and 226 deletions

View File

@@ -162,14 +162,13 @@ class NewRevocationModalForm(BaseModalForm):
)
revocation = Revocation.objects.create(
date=self.cleaned_data["date"],
legal=self.instance.legal,
comment=self.cleaned_data["comment"],
created=created_action,
)
self.instance.modified = edited_action
self.instance.save()
self.instance.log.add(edited_action)
self.instance.legal.revocation = revocation
self.instance.legal.save()
if self.cleaned_data["file"]:
RevocationDocument.objects.create(

View File

@@ -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

View File

@@ -4,8 +4,8 @@
<div class="row">
<div class="col-sm-6">
<h5>
<span class="badge badge-light">{% if obj.legal.revocation %}1{% else %}0{% endif %}</span>
{% trans 'Revocation' %}
<span class="badge badge-light">{{obj.legal.revocations.count}}</span>
{% trans 'Revocations' %}
</h5>
</div>
<div class="col-sm-6">
@@ -44,30 +44,28 @@
</tr>
</thead>
<tbody>
{% if obj.legal.revocation %}
{% with obj.legal.revocation as rev %}
<tr>
<td class="align-middle">
{{ rev.date }}
</td>
<td class="align-middle">
{% if rev.document %}
<a href="{% url 'intervention:get-doc-revocation' rev.document.id %}">
{% trans 'Revocation' %}
</a>
{% endif %}
</td>
<td class="align-middle">{{ rev.comment }}</td>
<td>
{% if is_default_member and has_access %}
<button data-form-url="{% url 'intervention:remove-revocation' rev.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove revocation' %}">
{% fa5_icon 'trash' %}
</button>
{% endif %}
</td>
</tr>
{% endwith %}
{% endif %}
{% for rev in obj.legal.revocations.all %}
<tr>
<td class="align-middle">
{{ rev.date }}
</td>
<td class="align-middle">
{% if rev.document %}
<a href="{% url 'intervention:get-doc-revocation' rev.document.id %}">
{% trans 'Revocation' %}
</a>
{% endif %}
</td>
<td class="align-middle">{{ rev.comment }}</td>
<td>
{% if is_default_member and has_access %}
<button data-form-url="{% url 'intervention:remove-revocation' rev.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove revocation' %}">
{% fa5_icon 'trash' %}
</button>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>

View File

@@ -99,9 +99,9 @@
<th scope="row">{% trans 'Binding on' %}</th>
<td class="align-middle">{{obj.legal.binding_date|default_if_none:""}}</td>
</tr>
<tr {% if obj.legal.revocation %}class="alert alert-danger" title="{% trans 'Exists' %}" {% endif %}>
<th scope="row">{% trans 'Revocation' %}</th>
<td class="align-middle">{{obj.legal.revocation.date|naturalday|default_if_none:""}}</td>
<tr {% if obj.legal.revocations.all %}class="alert alert-danger" title="{% trans 'Exists' %}" {% endif %}>
<th scope="row">{% trans 'Revocations' %}</th>
<td class="align-middle">{{obj.legal.revocations.count}}</td>
</tr>
<tr>
<th scope="row">{% trans 'Last modified' %}</th>

View File

@@ -66,8 +66,8 @@ class InterventionQualityChecker(AbstractQualityChecker):
try:
legal = self.obj.legal
# Check for a revocation
if legal.revocation:
self.messages.append(_("Revocation exists"))
if legal.revocations.exists():
self.messages.append(_("Revocations exists"))
if legal.registration_date is None:
self._add_missing_attr_name(_("Registration date"))

View File

@@ -147,7 +147,7 @@ def get_revocation_view(request: HttpRequest, doc_id: str):
"""
doc = get_object_or_404(RevocationDocument, id=doc_id)
# File download only possible if related instance is shared with user
if not doc.instance.users.filter(id=request.user.id):
if not doc.instance.legal.intervention.users.filter(id=request.user.id):
messages.info(
request,
DATA_UNSHARED
@@ -238,10 +238,10 @@ def detail_view(request: HttpRequest, id: str):
)
# Inform user about revocation
if intervention.legal.revocation:
if intervention.legal.revocations.exists():
messages.error(
request,
_("This intervention has a revocation from {}").format(intervention.legal.revocation.date.strftime(DEFAULT_DATE_FORMAT)),
_("This intervention has {} revocations").format(intervention.legal.revocations.count()),
extra_tags="danger",
)