#86 Edit document EcoAccount
* adds support for editing of documents * adds buttons and urls for ecoaccount
This commit is contained in:
		
							parent
							
								
									3ded54b80f
								
							
						
					
					
						commit
						fe842cb9bc
					
				@ -27,6 +27,9 @@
 | 
			
		||||
                <th scope="col">
 | 
			
		||||
                    {% trans 'Title' %}
 | 
			
		||||
                </th>
 | 
			
		||||
                <th scope="col">
 | 
			
		||||
                    {% trans 'Created on' %}
 | 
			
		||||
                </th>
 | 
			
		||||
                <th scope="col">
 | 
			
		||||
                    {% trans 'Comment' %}
 | 
			
		||||
                </th>
 | 
			
		||||
@ -41,18 +44,24 @@
 | 
			
		||||
            {% for doc in obj.documents.all %}
 | 
			
		||||
            <tr>
 | 
			
		||||
                <td class="align-middle">
 | 
			
		||||
                    <a href="{% url 'compensation:acc:get-doc' doc.id %}">
 | 
			
		||||
                    <a href="{% url 'compensation:acc:get-doc' obj.id doc.id %}">
 | 
			
		||||
                        {{ doc.title }}
 | 
			
		||||
                    </a>
 | 
			
		||||
                </td>
 | 
			
		||||
                <td class="align-middle">
 | 
			
		||||
                    {{ doc.date_of_creation }}
 | 
			
		||||
                </td>
 | 
			
		||||
                <td class="align-middle">
 | 
			
		||||
                    <div class="scroll-150">
 | 
			
		||||
                        {{ doc.comment }}
 | 
			
		||||
                    </div>
 | 
			
		||||
                </td>
 | 
			
		||||
                <td class="align-middle">
 | 
			
		||||
                <td class="align-middle float-right">
 | 
			
		||||
                    {% if is_default_member and has_access  %}
 | 
			
		||||
                    <button data-form-url="{% url 'compensation:acc:remove-doc' doc.id %}" class="btn btn-default btn-modal float-right" title="{% trans 'Remove document' %}">
 | 
			
		||||
                    <button data-form-url="{% url 'compensation:acc:edit-doc' obj.id doc.id %}" class="btn btn-default btn-modal" title="{% trans 'Edit document' %}">
 | 
			
		||||
                        {% fa5_icon 'edit' %}
 | 
			
		||||
                    </button>
 | 
			
		||||
                    <button data-form-url="{% url 'compensation:acc:remove-doc' obj.id doc.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove document' %}">
 | 
			
		||||
                        {% fa5_icon 'trash' %}
 | 
			
		||||
                    </button>
 | 
			
		||||
                    {% endif %}
 | 
			
		||||
 | 
			
		||||
@ -30,8 +30,9 @@ urlpatterns = [
 | 
			
		||||
 | 
			
		||||
    # Documents
 | 
			
		||||
    path('<id>/document/new/', new_document_view, name='new-doc'),
 | 
			
		||||
    path('document/<doc_id>', get_document_view, name='get-doc'),
 | 
			
		||||
    path('document/<doc_id>/remove/', remove_document_view, name='remove-doc'),
 | 
			
		||||
    path('<id>/document/<doc_id>', get_document_view, name='get-doc'),
 | 
			
		||||
    path('<id>/document/<doc_id>/edit', edit_document_view, name='edit-doc'),
 | 
			
		||||
    path('<id>/document/<doc_id>/remove/', remove_document_view, name='remove-doc'),
 | 
			
		||||
 | 
			
		||||
    # Eco-account deductions
 | 
			
		||||
    path('<id>/deduction/<deduction_id>/remove', deduction_remove_view, name='remove-deduction'),
 | 
			
		||||
 | 
			
		||||
@ -24,7 +24,8 @@ from intervention.forms.modalForms import NewDeductionModalForm, ShareModalForm,
 | 
			
		||||
from konova.contexts import BaseContext
 | 
			
		||||
from konova.decorators import any_group_check, default_group_required, conservation_office_group_required, \
 | 
			
		||||
    shared_access_required
 | 
			
		||||
from konova.forms import RemoveModalForm, SimpleGeomForm, NewDocumentModalForm, RecordModalForm, RemoveDeadlineModalForm
 | 
			
		||||
from konova.forms import RemoveModalForm, SimpleGeomForm, NewDocumentModalForm, RecordModalForm, \
 | 
			
		||||
    RemoveDeadlineModalForm, EditDocumentModalForm
 | 
			
		||||
from konova.models import Deadline
 | 
			
		||||
from konova.settings import DEFAULT_GROUP, ZB_GROUP, ETS_GROUP
 | 
			
		||||
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
 | 
			
		||||
@ -33,7 +34,7 @@ from konova.utils.generators import generate_qr_code
 | 
			
		||||
from konova.utils.message_templates import IDENTIFIER_REPLACED, FORM_INVALID, DATA_UNSHARED, DATA_UNSHARED_EXPLANATION, \
 | 
			
		||||
    CANCEL_ACC_RECORDED_OR_DEDUCTED, DEDUCTION_REMOVED, DEDUCTION_ADDED, DOCUMENT_ADDED, COMPENSATION_STATE_REMOVED, \
 | 
			
		||||
    COMPENSATION_STATE_ADDED, COMPENSATION_ACTION_REMOVED, COMPENSATION_ACTION_ADDED, DEADLINE_ADDED, DEADLINE_REMOVED, \
 | 
			
		||||
    DEDUCTION_EDITED
 | 
			
		||||
    DEDUCTION_EDITED, DOCUMENT_EDITED
 | 
			
		||||
from konova.utils.user_checks import in_group
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -534,46 +535,68 @@ def new_document_view(request: HttpRequest, id: str):
 | 
			
		||||
 | 
			
		||||
@login_required
 | 
			
		||||
@default_group_required
 | 
			
		||||
def get_document_view(request: HttpRequest, doc_id: str):
 | 
			
		||||
@shared_access_required(EcoAccount, "id")
 | 
			
		||||
def get_document_view(request: HttpRequest, id:str, doc_id: str):
 | 
			
		||||
    """ Returns the document as downloadable file
 | 
			
		||||
 | 
			
		||||
    Wraps the generic document fetcher function from konova.utils.
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        request (HttpRequest): The incoming request
 | 
			
		||||
        id (str): The account id
 | 
			
		||||
        doc_id (str): The document id
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
 | 
			
		||||
    """
 | 
			
		||||
    acc = get_object_or_404(EcoAccount, id=id)
 | 
			
		||||
    doc = get_object_or_404(EcoAccountDocument, id=doc_id)
 | 
			
		||||
    user = request.user
 | 
			
		||||
    instance = doc.instance
 | 
			
		||||
    # File download only possible if related instance is shared with user
 | 
			
		||||
    if not instance.users.filter(id=user.id):
 | 
			
		||||
        messages.info(
 | 
			
		||||
            request,
 | 
			
		||||
            DATA_UNSHARED
 | 
			
		||||
        )
 | 
			
		||||
        return redirect("compensation:acc:detail", id=instance.id)
 | 
			
		||||
    return get_document(doc)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@login_required
 | 
			
		||||
@default_group_required
 | 
			
		||||
@shared_access_required(EcoAccount, "id")
 | 
			
		||||
def remove_document_view(request: HttpRequest, doc_id: str):
 | 
			
		||||
def edit_document_view(request: HttpRequest, id: str, doc_id: str):
 | 
			
		||||
    """ Removes the document from the database and file system
 | 
			
		||||
 | 
			
		||||
    Wraps the generic functionality from konova.utils.
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        request (HttpRequest): The incoming request
 | 
			
		||||
        id (str): The account id
 | 
			
		||||
        doc_id (str): The document id
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
 | 
			
		||||
    """
 | 
			
		||||
    acc = get_object_or_404(EcoAccount, id=id)
 | 
			
		||||
    doc = get_object_or_404(EcoAccountDocument, id=doc_id)
 | 
			
		||||
    form = EditDocumentModalForm(request.POST or None, request.FILES or None, instance=acc, document=doc, request=request)
 | 
			
		||||
    return form.process_request(
 | 
			
		||||
        request,
 | 
			
		||||
        DOCUMENT_EDITED,
 | 
			
		||||
        reverse("compensation:acc:detail", args=(id,)) + "#related_data"
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@login_required
 | 
			
		||||
@default_group_required
 | 
			
		||||
@shared_access_required(EcoAccount, "id")
 | 
			
		||||
def remove_document_view(request: HttpRequest, id: str, doc_id: str):
 | 
			
		||||
    """ Removes the document from the database and file system
 | 
			
		||||
 | 
			
		||||
    Wraps the generic functionality from konova.utils.
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        request (HttpRequest): The incoming request
 | 
			
		||||
        id (str): The account id
 | 
			
		||||
        doc_id (str): The document id
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
 | 
			
		||||
    """
 | 
			
		||||
    acc = get_object_or_404(EcoAccount, id=id)
 | 
			
		||||
    doc = get_object_or_404(EcoAccountDocument, id=doc_id)
 | 
			
		||||
    return remove_document(
 | 
			
		||||
        request,
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user