Commits

Luke Plant committed 0310940 Merge

Merged from default

  • Participants
  • Parent commits 9ab9952, da14e47
  • Branches live

Comments (0)

Files changed (6)

cciw/officers/email.py

     return salted_hmac("cciw.officers.emailupdate", oldemail + ':' + newemail).hexdigest()[::2]
 
 
+def admin_emails_for_camp(camp):
+    leaders = [user for leader in camp.leaders.all()
+               for user in leader.users.all()] + \
+               list(camp.admins.all())
+
+    return filter(lambda x: x is not None,
+                  map(formatted_email, leaders))
+
+
 def admin_emails_for_application(application):
     """
     For the supplied application, finds the camps admins that are relevant.
     camps = camps_for_application(application)
     groups = []
     for camp in camps:
-        leaders = [user for leader in camp.leaders.all()
-                   for user in leader.users.all()] + \
-                   list(camp.admins.all())
-        groups.append((camp, filter(lambda x: x is not None,
-                                    map(formatted_email, leaders))))
+        groups.append((camp, admin_emails_for_camp(camp)))
     return groups
 
 
               settings.DEFAULT_FROM_EMAIL,
               [officer.email],
               fail_silently=False)
+
+
+def send_crb_consent_problem_email(message, officer, camps):
+    # If more than one camp involved, we deliberately put all camp leaders
+    # together on a single e-mail, so that they can see that more than one camp
+    # is involved
+    emails = []
+    for c in camps:
+        emails.extend(admin_emails_for_camp(c))
+    send_mail("CRB consent problem for %s %s" % (officer.first_name, officer.last_name),
+              message,
+              settings.DEFAULT_FROM_EMAIL,
+              emails,
+              fail_silently=False)

cciw/officers/urls.py

     (r'^leaders/crbs/(?P<year>\d{4})/', 'manage_crbs'),
     (r'^leaders/mark-crb-sent/', 'mark_crb_sent'),
     (r'^leaders/undo-mark-crb-sent/', 'undo_mark_crb_sent'),
+    (r'^leaders/crb-consent-problem/', 'crb_consent_problem'),
     (r'^leaders/stats/(?P<year>\d{4})/$', 'stats'),
     (r'^ref/(?P<ref_id>\d+)-(?P<prev_ref_id>\d*)-(?P<hash>.*)/$', 'create_reference_form'),
     (r'^ref/thanks/$', 'create_reference_thanks'),

cciw/officers/views.py

 from cciw.cciwmain.models import Camp
 from cciw.cciwmain.utils import python_to_json
 from cciw.mail.lists import address_for_camp_officers, address_for_camp_slackers
-from cciw.officers.applications import application_to_text, application_to_rtf, application_rtf_filename, application_txt_filename, thisyears_applications, applications_for_camp
+from cciw.officers.applications import application_to_text, application_to_rtf, application_rtf_filename, application_txt_filename, thisyears_applications, applications_for_camp, camps_for_application
 from cciw.officers import create
 from cciw.officers.email_utils import send_mail_with_attachments, formatted_email
-from cciw.officers.email import make_update_email_hash, send_reference_request_email, make_ref_form_url, make_ref_form_url_hash, send_leaders_reference_email, send_nag_by_officer
+from cciw.officers.email import make_update_email_hash, send_reference_request_email, make_ref_form_url, make_ref_form_url_hash, send_leaders_reference_email, send_nag_by_officer, send_crb_consent_problem_email
 from cciw.officers.widgets import ExplicitBooleanFieldSelect
 from cciw.officers.models import Application, Reference, ReferenceForm, Invitation, CRBApplication, CRBFormLog
 from cciw.officers.utils import camp_officer_list, camp_slacker_list
     crbformlog_id = int(request.POST['crbformlog_id'])
     c = CRBFormLog.objects.filter(id=crbformlog_id).delete()
     return {'status':'success'}
+
+
+class CrbConsentProblemForm(SendMessageForm):
+    def get_message_template(self):
+        return 'cciw/officers/crb_consent_problem_email.txt'
+
+
+@staff_member_required
+@camp_admin_required
+def crb_consent_problem(request):
+    try:
+        app_id = int(request.GET.get('application_id'))
+    except ValueError, TypeError:
+        raise Http404
+    app = get_object_or_404(Application.objects.filter(id=app_id))
+    officer = app.officer
+    camps = camps_for_application(app)
+
+    c = {}
+    messageform_info = dict(application=app,
+                            officer=officer,
+                            camps=camps,
+                            sender=request.user)
+
+    if request.method == 'POST':
+        if 'send' in request.POST:
+            messageform = CrbConsentProblemForm(request.POST, message_info=messageform_info)
+            # It's impossible for the form to be invalid, so assume valid
+            messageform.is_valid()
+            send_crb_consent_problem_email(wordwrap(messageform.cleaned_data['message'], 70), officer, camps)
+            return close_window_response()
+        else:
+            # cancel
+            return close_window_response()
+
+    messageform = CrbConsentProblemForm(message_info=messageform_info)
+
+    c['messageform'] = messageform
+    c['officer'] = officer
+    c['is_popup'] = True
+    return render(request, 'cciw/officers/crb_consent_problem.html', c)

templates/cciw/officers/manage_crbs.html

         }
     });
 }
+
+function alertLeadersCrbConsentCheck(applicationId) {
+    window.open("{% url 'cciw.officers.views.crb_consent_problem' %}?application_id=" + applicationId.toString(),
+                '_blank',"toolbar=yes,height=600,width=900,location=yes,menubar=yes,scrollbars=yes,resizable=yes");
+
+}
 </script>
 
 <h1>Manage CRBs</h1>
               {% if officer.temp.crb_check_consent %}
                 <a href="javascript:void(0)" onclick="$('#id_address_{{ officer.id }}').toggle();">Show address</a> <span class="address" style="display:none;" id="id_address_{{ officer.id }}">{{ officer.temp.address }}</span>
               {% else %}
-                <b>Officer does not<br/> consent to CRB check.<br/>
-                Leaders should be told.</b>
+                <b>Officer does not<br/> consent to CRB check.<br/></b>
+                <button onclick="alertLeadersCrbConsentCheck({{ officer.temp.application_id }})">Alert leaders</button>
               {% endif %}
             {% else %}
               Needs application form