diff --git a/smash/web/templates/appointments/edit.html b/smash/web/templates/appointments/edit.html index 54a953066def79d006827ac729b23a4350ac54e8..029dcca76dde7d0688eed472d96c3b2ea6a0a7e9 100644 --- a/smash/web/templates/appointments/edit.html +++ b/smash/web/templates/appointments/edit.html @@ -105,6 +105,9 @@ </form> </div> {% include 'includes/mail_templates_box.html' with instance_id=appointment.id %} + {% if appointment.visit %} + {% include 'includes/contact_attempts_box.html' with subject=appointment.visit.subject contact_attempts=contact_attempts appointment_id=appointment.id %} + {% endif %} {% endblock %} diff --git a/smash/web/templates/includes/contact_attempts_box.html b/smash/web/templates/includes/contact_attempts_box.html new file mode 100644 index 0000000000000000000000000000000000000000..68d1244495033cd88fcc5e82bde436240403c57f --- /dev/null +++ b/smash/web/templates/includes/contact_attempts_box.html @@ -0,0 +1,42 @@ +<div class="row"> + <div class="col-lg-12"> + <div class="box box-success"> + <div class="box-header with-border"> + <h3>Contact attempts <a title="add a new contact attempt" + id="add-contact-attempt" + href=" + {% url 'web.views.contact_add' subject.id %}{% if appointment_id %}?from_appointment={{ appointment_id }}{% endif %}" + class="text-primary" + ><i class="fa fa-plus-circle text-success"></i></a></h3> + </div> + <div class="box-body"> + <table class="table table-bordered table-striped"> + <thead> + <tr> + + <th class="text-center">When</th> + <th class="text-center">Who</th> + <th class="text-center">Type</th> + <th class="text-center">Success</th> + <th class="text-center">Comment</th> + </tr> + </thead> + <tbody> + {% for contact_attempt in contact_attempts %} + <tr> + <td>{{ contact_attempt.datetime_when }}</td> + <td>{{ contact_attempt.worker }}</td> + <td class="text-center">{{ contact_attempt.get_type_display }}</td> + <td class="text-center"> + <i class="fa {% if contact_attempt.success %}fa-check text-success{% else %}fa-times text-danger{% endif %}"></i> + </td> + <td>{{ contact_attempt.comment }}</td> + </tr> + {% endfor %} + </tbody> + </table> + </div> + </div> + + </div> +</div> diff --git a/smash/web/templates/subjects/edit.html b/smash/web/templates/subjects/edit.html index f1dbc493d27a2022d4981fbc3ae747f01b02f04a..ec809187f951314173831d76475bcbdf3e6b7234 100644 --- a/smash/web/templates/subjects/edit.html +++ b/smash/web/templates/subjects/edit.html @@ -90,47 +90,7 @@ {% include 'includes/mail_templates_box.html' with instance_id=subject.id %} - <div class="row"> - <div class="col-lg-12"> - <div class="box box-success"> - <div class="box-header with-border"> - <h3>Contact attempts <a title="add a new contact attempt" - id="add-contact-attempt" - href="{% url 'web.views.contact_add' subject.id %}" class="text-primary" - ><i class="fa fa-plus-circle text-success"></i></a></h3> - </div> - <div class="box-body"> - <table class="table table-bordered table-striped"> - <thead> - <tr> - - <th class="text-center">When</th> - <th class="text-center">Who</th> - <th class="text-center">Type</th> - <th class="text-center">Success</th> - <th class="text-center">Comment</th> - </tr> - </thead> - <tbody> - {% for contact_attempt in contact_attempts %} - <tr> - <td>{{ contact_attempt.datetime_when }}</td> - <td>{{ contact_attempt.worker }}</td> - <td class="text-center">{{ contact_attempt.get_type_display }}</td> - <td class="text-center"> - <i class="fa {% if contact_attempt.success %}fa-check text-success{% else %}fa-times text-danger{% endif %}"></i> - </td> - <td>{{ contact_attempt.comment }}</td> - </tr> - {% endfor %} - </tbody> - </table> - </div> - </div> - - </div> - </div> - + {% include 'includes/contact_attempts_box.html' with subject=subject contact_attempts=contact_attempts %} <div class="modal modal-danger fade" id="confirm-dead-resigned-mark-dialog" tabindex="-1" role="dialog"> diff --git a/smash/web/views/appointment.py b/smash/web/views/appointment.py index 7516755a6c32e0a36c8d03cc32e71f71b483207d..b4712eb74e607fbaa9621b43b1279b52b8364374 100644 --- a/smash/web/views/appointment.py +++ b/smash/web/views/appointment.py @@ -54,6 +54,7 @@ def appointment_add(request, visit_id=None): def appointment_edit(request, id): the_appointment = get_object_or_404(Appointment, id=id) subject_form = None + contact_attempts = None if request.method == 'POST': appointment_form = AppointmentEditForm(request.POST, @@ -94,6 +95,7 @@ def appointment_edit(request, id): if the_appointment.visit is not None: subject_form = SubjectEditForm(instance=the_appointment.visit.subject, prefix="subject") + contact_attempts = the_appointment.visit.subject.contactattempt_set.order_by('-datetime_when').all() languages = [] if the_appointment.visit is not None: @@ -106,5 +108,6 @@ def appointment_edit(request, id): 'subject_form': subject_form, 'id': id, 'appointment': the_appointment, + 'contact_attempts': contact_attempts, 'mail_templates': MailTemplate.get_appointment_mail_templates(languages) }) diff --git a/smash/web/views/contact_attempt.py b/smash/web/views/contact_attempt.py index 229e11f8744863c69432aa18b0d7a51a55f21023..439a2a025329c9de1aa3b5feaa17cc25da87bf18 100644 --- a/smash/web/views/contact_attempt.py +++ b/smash/web/views/contact_attempt.py @@ -12,7 +12,10 @@ def contact_add(request, subject_id): form.instance.subject_id = subject_id if form.is_valid(): form.save() - return redirect('web.views.subject_edit', id=subject_id) + if 'from_appointment' in request.GET: + return redirect('web.views.appointment_edit', id=request.GET.get('from_appointment','')) + else: + return redirect('web.views.subject_edit', id=subject_id) else: form = ContactAttemptForm(user=request.user, subject=subject)