Add basic proposal acceptance admin view

This commit is contained in:
Stefan Wehrmeyer 2022-03-18 19:04:12 +01:00
parent 7248b40a60
commit b22cdef2b8
5 changed files with 291 additions and 3 deletions

View file

@ -0,0 +1,13 @@
{% extends "admin/change_form.html" %}
{% load i18n %}
{% block object-tools-items %}
{% if original.pk and original.proposals %}
<li>
<a href="{% url 'admin:froide_govplan-plan_accept_proposal' pk=original.pk %}">
{% trans "See update proposals" %}
</a>
</li>
{% endif %}
{{ block.super }}
{% endblock %}

View file

@ -0,0 +1,77 @@
{% load i18n %}
{% load form_helper %}
{% load permission_helper %}
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>{% trans "Field" %}</th>
{% for key, proposal in proposals.items %}
<th>
<span title="{{ proposal.timestamp }}">
{% if request.user.is_staff and request.user|has_perm:"account.view_user" %}
{{ proposal.user.get_full_name }} ({{ proposal.user.email }})
{% else %}
{{ proposal.timestamp | date:"SHORT_DATETIME" }}
{% endif %}
</span>
</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% if proposals %}
<tr>
<td>
{% trans "Proposal" %}
</td>
{% for key, proposal in proposals.items %}
<td>
<label>
<input type="radio" name="proposal_id" class="proposal" value="{{ key }}" required>
{% trans "Turn into update draft" %}
</label>
</td>
{% endfor %}
</tr>
{% endif %}
{% for field in form %}
<tr>
<td>{{ field.label }}</td>
{% for key, proposal in proposals.items %}
{% with val=proposal.data|get_item_by_key:field.name %}
<td>
{% with label_name=field.name|add:"_label" %}
{% if proposal.data|get_item_by_key:label_name %}
{{ proposal.data|get_item_by_key:label_name }}
{% else %}
{{ val|urlize|linebreaksbr }}
{% endif %}
{% endwith %}
</td>
{% endwith %}
{% endfor %}
</tr>
{{ form.field }}
{% endfor %}
{% if proposals %}
<tr>
<td>
{% trans "Delete proposal" %}
</td>
{% for key, proposal in proposals.items %}
<td>
<label>
<input type="checkbox" name="proposal_delete" value="{{ proposal.user.id }}">
{% trans "Delete" %}
</label>
</td>
{% endfor %}
</tr>
{% endif %}
</tbody>
</table>
</div>

View file

@ -0,0 +1,33 @@
{% extends "admin/change_form.html" %}
{% load i18n %}
{% block title %}{{ object.title }} - {{ block.super }}{% endblock %}
{% block content %}<div id="content-main">
<h3>{{ object.title }}</h3>
<form action="" method="post">
{% csrf_token %}
<fieldset>
{% include "froide_govplan/admin/_proposal.html" %}
</fieldset>
<div class="submit-row">
<input type="submit" value="{% trans 'Create update draft' %}" style="float:left"/>
</div>
<div class="card border-danger mt-3">
<div class="card-body">
<h3>{% trans "Delete proposal" %}</h3>
<p><label for="delete_reason">
{% trans "Please give a reason for not accepting this proposal. It will be send to the user who made the proposal." %}
</label>
<p>
<p><textarea id="delete_reason" class="form-control" name="delete_reason" placeholder="{% trans 'We could not accept this update because...' %}"></textarea></p>
<p><button class="mt-2 btn btn-danger float-right" type="submit" name="delete" value="1">
{% trans "Delete proposed update" %}
</button></p>
</div>
</div>
</form>
{% endblock %}