Project

General

Profile

« Previous | Next » 

Revision 86dfa623

Added by Benjamin Dauvergne over 13 years ago

implement act validation

View differences:

calebasse/agenda/templates/agenda/act-validation.html
{% block appbar %}
<h2>Validation des actes - {{ date|date:"DATE_FORMAT" }}</h2>
<a href="..">Retourner à l'agenda</a>
{% if day_locked %}<button id="unlock-all" data-url="{% url 'unlock-all' service=service date=date %}">Tout déverrouiller</button> {% endif %}<button id="validation-all" data-url="{% url 'validation-all' service=service date=date %}">Validation automatique</button>
{% if day_locked %}
<form method="post">
{% csrf_token %}
<input type="hidden" name="unlock-all" value="1">
<button id="unlock-all">Tout déverrouiller</button>
</form>
{% endif %}
<form method="post">
{% csrf_token %}
<input type="hidden" name="unlock-all" value="1">
<input type="hidden" name="validate-all" value="1">
<button id="validate-all">Validation automatique</button>
</form>
{% endblock %}
{% block agenda-content %}
......
<strong>{{ acte.act_type }}</strong>
{% if acte.description %} <img title="Un commentaire existe" src="{{ STATIC_URL }}images/emblem-documents.png">{% endif%}
</h3>
<p>{% if last_status %}<strong>{{ last_status.state_name }}</strong>, le {{ last_status.created }} par {{ last_status.author }}
<div><span>{% if last_status %}<strong>{{ last_status.state_name }}</strong>, le {{ last_status.created }} par {{ last_status.author }}
{% if last_status.auto %}(par validation automatique){% endif %}.
{% else %}
Non pointé.
{% endif %}
{% if acte.validation_locked %}
{% if authorized_lock %}<button>Déverrouiller</button>{% endif %}
</span>
{% if acte.validation_locked and authorized_lock %}
<form method="post" class="inline-form">
{% csrf_token %}
<input type="hidden" value="{{acte.id}}" name="acte-id">
<input type="hidden" name="unlock" value="1">
<button>Déverrouiller</button>
</form>
{% else %}
<select name="acte_state" id="acte_state">
<form method="post" class="inline-form">
{% csrf_token %}
<input type="hidden" value="{{acte.id}}" name="acte-id">
<select data-previous="{{ last_status.state_name }}" name="act_state">
{% for state_name, display_state_name in validation_states.items %}
<option value="{{ state_name }}">{{ display_state_name }}</option>
<option value="{{ state_name }}" {% if state_name == last_status.state_name %}selected{% endif %}>{{ display_state_name }}</option>
{% endfor %}
</select>
<button>Modifier</button>
{% if authorized_lock %}
{% if last_status %}<button>Verrouiller</button>{% endif %}
<button {% if last_status %}disabled{% endif %}>Modifier</button>
</form>
{% if authorized_lock and last_status %}
<form method="post" class="inline-form">
{% csrf_token %}
<input type="hidden" value="{{acte.id}}" name="acte-id">
<input type="hidden" name="lock" value="1">
<button>Verrouiller</button>
</form>
{% endif %}
{% endif %}
</p>
</div>
</div>
{% endfor %}
</div>
......
<p><strong>Il n'y a pas d'acte à valider le {{ date|date:"DATE_FORMAT" }}.</strong></p>
{% endif %}
{% endblock %}
{% block page-end %}
<script>
$('select[name^="act_state"]').on('change', function () {
$(this).next('button').prop('disabled',
($(this).data('previous') == $(this).val()));
})
</script>
{% endblock %}
calebasse/agenda/views.py
from django.db.models import Q
from django.shortcuts import redirect
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from calebasse.cbv import TemplateView, CreateView
from calebasse.agenda.models import Occurrence, Event, EventType
......
from calebasse.ressources.models import WorkerType
from calebasse.actes.validation import (are_all_acts_of_the_day_locked,
get_acts_of_the_day)
from calebasse.actes.validation_states import VALIDATION_STATES
from calebasse.actes.validation_states import VALIDATION_STATES, VALIDE
from calebasse.actes.models import Act
from calebasse.actes.validation import (automated_validation,
unlock_all_acts_of_the_day)
from forms import NewAppointmentForm, NewEventForm
......
template_name = 'agenda/act-validation.html'
def acts_of_the_day(self):
return get_acts_of_the_day(self.date)
def post(self, request, *args, **kwargs):
return render_to_response(self.template_name, {},
context_instance=None)
if 'validation-all' in request.POST:
# FIXME: Action automatique: tout le monde est valide ?
automated_validation(self.date,
self.service, request.user)
elif 'unlock-all' in request.POST:
unlock_all_acts_of_the_day(self.date)
else:
acte_id = request.POST.get('acte-id')
try:
act = Act.objects.get(id=acte_id)
if 'lock' in request.POST or 'unlock' in request.POST:
act.validation_locked = 'lock' in request.POST
act.save()
else:
state_name = request.POST.get('act_state')
act.set_state(state_name, request.user)
except Act.DoesNotExist:
pass
return HttpResponseRedirect('#acte-frame-'+acte_id)
return HttpResponseRedirect('')
def get_context_data(self, **kwargs):
context = super(AgendaServiceActValidationView, self).get_context_data(**kwargs)
day_locked = are_all_acts_of_the_day_locked(context['date'])
authorized_lock = True # is_authorized_for_locking(get_request().user)
validation_msg = list()
acts_of_the_day = get_acts_of_the_day(context['date'])
acts_of_the_day = self.acts_of_the_day()
actes = list()
for act in acts_of_the_day:
state = act.get_state()
calebasse/static/css/style.css
.person-item span { display: none; }
.person-item.active span { display: inline; }
form.inline-form {
display: inline;
}

Also available in: Unified diff