Documents

* add get document route
* add missing attributes to intervention detail view
This commit is contained in:
mipel 2021-07-23 15:35:05 +02:00
parent 13a15e4f56
commit a0c0a0f074
4 changed files with 133 additions and 4 deletions

View File

@ -57,6 +57,14 @@
<th class="w-25" scope="row">{% trans 'Title' %}</th> <th class="w-25" scope="row">{% trans 'Title' %}</th>
<td class="align-middle">{{intervention.title}}</td> <td class="align-middle">{{intervention.title}}</td>
</tr> </tr>
<tr>
<th scope="row">{% trans 'Process type' %}</th>
<td class="align-middle">{{intervention.process_type|default_if_none:""}}</td>
</tr>
<tr>
<th scope="row">{% trans 'Law' %}</th>
<td class="align-middle">{{intervention.law|default_if_none:""}}</td>
</tr>
<tr> <tr>
<th scope="row">{% trans 'Registration office' %}</th> <th scope="row">{% trans 'Registration office' %}</th>
<td class="align-middle">{{intervention.registration_office|default_if_none:""}}</td> <td class="align-middle">{{intervention.registration_office|default_if_none:""}}</td>
@ -73,6 +81,10 @@
<th scope="row">{% trans 'Conversation office file number' %}</th> <th scope="row">{% trans 'Conversation office file number' %}</th>
<td class="align-middle">{{intervention.conservation_file_number|default_if_none:""}}</td> <td class="align-middle">{{intervention.conservation_file_number|default_if_none:""}}</td>
</tr> </tr>
<tr>
<th scope="row">{% trans 'Handler' %}</th>
<td class="align-middle">{{intervention.handler|default_if_none:""}}</td>
</tr>
<tr> <tr>
<th scope="row">{% trans 'Checked' %}</th> <th scope="row">{% trans 'Checked' %}</th>
<td class="align-middle"> <td class="align-middle">
@ -131,7 +143,7 @@
</div> </div>
<hr> <hr>
<div id="related-objects" class="row mb-5"> <div id="related-objects" class="row">
<div class="col-sm-12 col-md-12 col-lg-6"> <div class="col-sm-12 col-md-12 col-lg-6">
<div id="related-compensations" class="card"> <div id="related-compensations" class="card">
<div class="card-header rlp-r"> <div class="card-header rlp-r">
@ -231,5 +243,105 @@
</div> </div>
</div> </div>
</div> </div>
<div id="related-documents" class="row">
<div class="col-sm-12 col-md-12 col-lg-6">
<div class="card">
<div class="card-header rlp-r">
<div class="row">
<div class="col-sm-6">
<h5>
<span class="badge badge-light">{{intervention.documents.count}}</span>
{% trans 'Documents' %}
</h5>
</div>
<div class="col-sm-6">
<div class="d-flex justify-content-end">
<a href="{% url 'compensation:new' %}" title="{% trans 'Add new compensation' %}">
<button class="btn btn-outline-default">
{% fa5_icon 'plus' %}
{% fa5_icon 'file' %}
</button>
</a>
</div>
</div>
</div>
</div>
<div class="card-body">
<table class="table table-hover">
<thead>
<tr>
<th scope="col">
{% trans 'Title' %}
</th>
<th scope="col">
{% trans 'Comment' %}
</th>
</tr>
</thead>
<tbody>
{% for doc in intervention.documents.all %}
<tr>
<td>
<a href="{% url 'compensation:open' doc.id %}">
{{ doc.title }}
</a>
</td>
<td>{{ doc.comment }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
<div class="col-sm-12 col-md-12 col-lg-6">
<div id="related-payments" class="card">
<div class="card-header rlp-r">
<div class="row">
<div class="col-sm-6">
<h5>
<span class="badge badge-light">{{intervention.payments.count}}</span>
{% trans 'Payments' %}
</h5>
</div>
<div class="col-sm-6">
<div class="d-flex justify-content-end">
<a href="{% url 'compensation:pay-new' %}" title="{% trans 'Add new payment' %}">
<button class="btn btn-outline-default">
{% fa5_icon 'plus' %}
{% fa5_icon 'money-bill-wave' %}
</button>
</a>
</div>
</div>
</div>
</div>
<div class="card-body">
<table class="table table-hover">
<thead>
<tr>
<th scope="col">
{% trans 'Amount' %}
</th>
<th scope="col">
{% trans 'Transfer comment' %}
</th>
</tr>
</thead>
<tbody>
{% for pay in intervention.payments.all %}
<a href="{% url 'compensation:pay-open' pay.id %}">
<tr>
<td>{{ pay.amount }}</td>
<td>{{ pay.comment }}</td>
</tr>
</a>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
{% endblock %} {% endblock %}

View File

@ -60,6 +60,7 @@ class Document(BaseResource):
""" """
Documents can be attached to compensation or intervention for uploading legal documents or pictures. Documents can be attached to compensation or intervention for uploading legal documents or pictures.
""" """
title = models.CharField(max_length=500, null=True, blank=True)
date_of_creation = models.DateField() date_of_creation = models.DateField()
document = models.FileField() document = models.FileField()
comment = models.TextField() comment = models.TextField()

View File

@ -20,7 +20,7 @@ from simple_sso.sso_client.client import Client
from konova.autocompletes import OrganisationAutocomplete, NonOfficialOrganisationAutocomplete from konova.autocompletes import OrganisationAutocomplete, NonOfficialOrganisationAutocomplete
from konova.settings import SSO_SERVER, SSO_PUBLIC_KEY, SSO_PRIVATE_KEY, DEBUG from konova.settings import SSO_SERVER, SSO_PUBLIC_KEY, SSO_PRIVATE_KEY, DEBUG
from konova.views import logout_view, home_view from konova.views import logout_view, home_view, get_document_view
sso_client = Client(SSO_SERVER, SSO_PUBLIC_KEY, SSO_PRIVATE_KEY) sso_client = Client(SSO_SERVER, SSO_PUBLIC_KEY, SSO_PRIVATE_KEY)
urlpatterns = [ urlpatterns = [
@ -34,6 +34,7 @@ urlpatterns = [
path('organisation/', include("organisation.urls")), path('organisation/', include("organisation.urls")),
path('user/', include("user.urls")), path('user/', include("user.urls")),
path('news/', include("news.urls")), path('news/', include("news.urls")),
path('document/<id>', get_document_view, name="doc-open"),
# Autocomplete paths # Autocomplete paths
path("atcmplt/orgs", OrganisationAutocomplete.as_view(), name="orgs-autocomplete"), path("atcmplt/orgs", OrganisationAutocomplete.as_view(), name="orgs-autocomplete"),

View File

@ -7,11 +7,12 @@ Created on: 16.11.20
""" """
from django.contrib.auth import logout from django.contrib.auth import logout
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.http import HttpRequest from django.http import HttpRequest, FileResponse
from django.shortcuts import redirect, render from django.shortcuts import redirect, render, get_object_or_404
from django.utils import timezone from django.utils import timezone
from konova.contexts import BaseContext from konova.contexts import BaseContext
from konova.models import Document
from news.models import ServerMessage from news.models import ServerMessage
from konova.settings import SSO_SERVER_BASE from konova.settings import SSO_SERVER_BASE
@ -63,3 +64,17 @@ def home_view(request: HttpRequest):
} }
context = BaseContext(request, additional_context).context context = BaseContext(request, additional_context).context
return render(request, template, context) return render(request, template, context)
def get_document_view(request: HttpRequest, id: str):
""" Returns a document as downloadable attachment
Args:
request (HttpRequest): The incoming request
id (str): The document id
Returns:
"""
doc = get_object_or_404(Document, id=id)
return FileResponse(doc.file, as_attachment=True)