#25 Public reports
* prevents Actions column in tables from being rendered if there would be no buttons inside due to permission checking * enhances amount of sql requests for detail view and report view
This commit is contained in:
		
							parent
							
								
									193ba4c658
								
							
						
					
					
						commit
						ce74d011f6
					
				@ -4,7 +4,7 @@
 | 
			
		||||
        <div class="row">
 | 
			
		||||
            <div class="col-sm-6">
 | 
			
		||||
                <h5>
 | 
			
		||||
                    <span class="badge badge-light">{{obj.actions.count}}</span>
 | 
			
		||||
                    <span class="badge badge-light">{{actions.count}}</span>
 | 
			
		||||
                    {% trans 'Actions' context 'Compensation' %}
 | 
			
		||||
                </h5>
 | 
			
		||||
            </div>
 | 
			
		||||
@ -41,7 +41,7 @@
 | 
			
		||||
            </tr>
 | 
			
		||||
            </thead>
 | 
			
		||||
            <tbody>
 | 
			
		||||
            {% for action in obj.actions.all %}
 | 
			
		||||
            {% for action in actions %}
 | 
			
		||||
            <tr>
 | 
			
		||||
                <td class="align-middle">
 | 
			
		||||
                    {{ action.action_type }}
 | 
			
		||||
 | 
			
		||||
@ -33,9 +33,11 @@
 | 
			
		||||
                <th scope="col">
 | 
			
		||||
                    {% trans 'Comment' %}
 | 
			
		||||
                </th>
 | 
			
		||||
                <th scope="col">
 | 
			
		||||
                    {% trans 'Action' %}
 | 
			
		||||
                </th>
 | 
			
		||||
                {% if is_default_member and has_access %}
 | 
			
		||||
                    <th scope="col">
 | 
			
		||||
                        {% trans 'Action' %}
 | 
			
		||||
                    </th>
 | 
			
		||||
                {% endif %}
 | 
			
		||||
            </tr>
 | 
			
		||||
            </thead>
 | 
			
		||||
            <tbody>
 | 
			
		||||
 | 
			
		||||
@ -30,9 +30,11 @@
 | 
			
		||||
                <th scope="col">
 | 
			
		||||
                    {% trans 'Comment' %}
 | 
			
		||||
                </th>
 | 
			
		||||
                <th scope="col">
 | 
			
		||||
                    {% trans 'Action' %}
 | 
			
		||||
                </th>
 | 
			
		||||
                {% if is_default_member and has_access %}
 | 
			
		||||
                    <th scope="col">
 | 
			
		||||
                        {% trans 'Action' %}
 | 
			
		||||
                    </th>
 | 
			
		||||
                {% endif %}
 | 
			
		||||
            </tr>
 | 
			
		||||
            </thead>
 | 
			
		||||
            <tbody>
 | 
			
		||||
 | 
			
		||||
@ -4,7 +4,7 @@
 | 
			
		||||
        <div class="row">
 | 
			
		||||
            <div class="col-sm-6">
 | 
			
		||||
                <h5>
 | 
			
		||||
                    <span class="badge badge-light">{{obj.before_states.count}}</span>
 | 
			
		||||
                    <span class="badge badge-light">{{before_states.count}}</span>
 | 
			
		||||
                    {% trans 'States before' %}
 | 
			
		||||
                </h5>
 | 
			
		||||
            </div>
 | 
			
		||||
 | 
			
		||||
@ -23,10 +23,14 @@
 | 
			
		||||
                    <tr>
 | 
			
		||||
                        <th scope="row">{% trans 'Funded by' %}</th>
 | 
			
		||||
                        <td class="align-middle">
 | 
			
		||||
                            {% for funding in obj.fundings.all %}
 | 
			
		||||
                            {% with obj.fundings.all as fundings %}
 | 
			
		||||
                            {% for funding in fundings %}
 | 
			
		||||
                                <div class="badge pill-badge rlp-r-outline">{{funding.short_name}}</div>
 | 
			
		||||
                                <br>
 | 
			
		||||
                            {% empty %}
 | 
			
		||||
                                {% trans 'None' %}
 | 
			
		||||
                            {% endfor %}
 | 
			
		||||
                            {% endwith %}
 | 
			
		||||
                        </td>
 | 
			
		||||
                    </tr>
 | 
			
		||||
                    <tr>
 | 
			
		||||
 | 
			
		||||
@ -163,8 +163,9 @@ def detail_view(request: HttpRequest, id: str):
 | 
			
		||||
    is_data_shared = comp.intervention.is_shared_with(_user)
 | 
			
		||||
 | 
			
		||||
    # Order states according to surface
 | 
			
		||||
    before_states = comp.before_states.all().order_by("-surface")
 | 
			
		||||
    after_states = comp.after_states.all().order_by("-surface")
 | 
			
		||||
    before_states = comp.before_states.all().prefetch_related("biotope_type").order_by("-surface")
 | 
			
		||||
    after_states = comp.after_states.all().prefetch_related("biotope_type").order_by("-surface")
 | 
			
		||||
    actions = comp.actions.all().prefetch_related("action_type")
 | 
			
		||||
 | 
			
		||||
    # Precalculate logical errors between before- and after-states
 | 
			
		||||
    # Sum() returns None in case of no states, so we catch that and replace it with 0 for easier handling
 | 
			
		||||
@ -176,6 +177,7 @@ def detail_view(request: HttpRequest, id: str):
 | 
			
		||||
        "obj": comp,
 | 
			
		||||
        "geom_form": geom_form,
 | 
			
		||||
        "has_access": is_data_shared,
 | 
			
		||||
        "actions": actions,
 | 
			
		||||
        "before_states": before_states,
 | 
			
		||||
        "after_states": after_states,
 | 
			
		||||
        "sum_before_states": sum_before_states,
 | 
			
		||||
@ -416,8 +418,10 @@ def report_view(request:HttpRequest, id: str):
 | 
			
		||||
        7
 | 
			
		||||
    )
 | 
			
		||||
    # Order states by surface
 | 
			
		||||
    before_states = comp.before_states.all().order_by("-surface")
 | 
			
		||||
    after_states = comp.after_states.all().order_by("-surface")
 | 
			
		||||
    before_states = comp.before_states.all().order_by("-surface").prefetch_related("biotope_type")
 | 
			
		||||
    after_states = comp.after_states.all().order_by("-surface").prefetch_related("biotope_type")
 | 
			
		||||
    actions = comp.actions.all().prefetch_related("action_type")
 | 
			
		||||
 | 
			
		||||
    context = {
 | 
			
		||||
        "obj": comp,
 | 
			
		||||
        "qrcode": qrcode_img,
 | 
			
		||||
@ -426,6 +430,7 @@ def report_view(request:HttpRequest, id: str):
 | 
			
		||||
        "before_states": before_states,
 | 
			
		||||
        "after_states": after_states,
 | 
			
		||||
        "geom_form": geom_form,
 | 
			
		||||
        "actions": actions,
 | 
			
		||||
    }
 | 
			
		||||
    context = BaseContext(request, context).context
 | 
			
		||||
    return render(request, template, context)
 | 
			
		||||
 | 
			
		||||
@ -32,9 +32,11 @@
 | 
			
		||||
                <th scope="col">
 | 
			
		||||
                    {% trans 'Title' %}
 | 
			
		||||
                </th>
 | 
			
		||||
                <th scope="col">
 | 
			
		||||
                    {% trans 'Action' %}
 | 
			
		||||
                </th>
 | 
			
		||||
                {% if is_default_member and has_access %}
 | 
			
		||||
                    <th scope="col">
 | 
			
		||||
                        {% trans 'Action' %}
 | 
			
		||||
                    </th>
 | 
			
		||||
                {% endif %}
 | 
			
		||||
            </tr>
 | 
			
		||||
            </thead>
 | 
			
		||||
            <tbody>
 | 
			
		||||
 | 
			
		||||
@ -33,9 +33,11 @@
 | 
			
		||||
                <th scope="col">
 | 
			
		||||
                    {% trans 'Created' %}
 | 
			
		||||
                </th>
 | 
			
		||||
                <th scope="col">
 | 
			
		||||
                    {% trans 'Action' %}
 | 
			
		||||
                </th>
 | 
			
		||||
                {% if is_default_member and has_access %}
 | 
			
		||||
                    <th scope="col">
 | 
			
		||||
                        {% trans 'Action' %}
 | 
			
		||||
                    </th>
 | 
			
		||||
                {% endif %}
 | 
			
		||||
            </tr>
 | 
			
		||||
            </thead>
 | 
			
		||||
            <tbody>
 | 
			
		||||
 | 
			
		||||
@ -30,9 +30,11 @@
 | 
			
		||||
                <th scope="col">
 | 
			
		||||
                    {% trans 'Comment' %}
 | 
			
		||||
                </th>
 | 
			
		||||
                <th scope="col">
 | 
			
		||||
                    {% trans 'Action' %}
 | 
			
		||||
                </th>
 | 
			
		||||
                {% if is_default_member and has_access %}
 | 
			
		||||
                    <th scope="col">
 | 
			
		||||
                        {% trans 'Action' %}
 | 
			
		||||
                    </th>
 | 
			
		||||
                {% endif %}
 | 
			
		||||
            </tr>
 | 
			
		||||
            </thead>
 | 
			
		||||
            <tbody>
 | 
			
		||||
 | 
			
		||||
@ -33,9 +33,11 @@
 | 
			
		||||
                <th scope="col">
 | 
			
		||||
                    {% trans 'Comment' %}
 | 
			
		||||
                </th>
 | 
			
		||||
                <th scope="col">
 | 
			
		||||
                    {% trans 'Action' %}
 | 
			
		||||
                </th>
 | 
			
		||||
                {% if is_default_member and has_access %}
 | 
			
		||||
                    <th scope="col">
 | 
			
		||||
                        {% trans 'Action' %}
 | 
			
		||||
                    </th>
 | 
			
		||||
                {% endif %}
 | 
			
		||||
            </tr>
 | 
			
		||||
            </thead>
 | 
			
		||||
            <tbody>
 | 
			
		||||
 | 
			
		||||
@ -36,9 +36,11 @@
 | 
			
		||||
                <th scope="col">
 | 
			
		||||
                    {% trans 'Comment' %}
 | 
			
		||||
                </th>
 | 
			
		||||
                <th scope="col">
 | 
			
		||||
                    {% trans 'Action' %}
 | 
			
		||||
                </th>
 | 
			
		||||
                {% if is_default_member and has_access %}
 | 
			
		||||
                    <th scope="col">
 | 
			
		||||
                        {% trans 'Action' %}
 | 
			
		||||
                    </th>
 | 
			
		||||
                {% endif %}
 | 
			
		||||
            </tr>
 | 
			
		||||
            </thead>
 | 
			
		||||
            <tbody>
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user