Example #1
0
def organisation_toggle_admin(request, pk):
    teacher = get_object_or_404(Teacher, id=pk)
    user = request.user.userprofile.teacher

    # check user has authority to change
    if teacher.school != user.school or not user.is_admin:
        raise Http404

    # check not trying to change self
    if user == teacher:
        raise Http404

    teacher.is_admin = not teacher.is_admin
    teacher.save()

    if teacher.is_admin:
        messages.success(request,
                         'Administrator status has been given successfully.')
        emailMessage = emailMessages.adminGivenEmail(request,
                                                     teacher.school.name)
    else:
        messages.success(
            request, 'Administrator status has been revoked successfully.')
        emailMessage = emailMessages.adminRevokedEmail(request,
                                                       teacher.school.name)

    send_email(NOTIFICATION_EMAIL, [teacher.user.user.email],
               emailMessage['subject'], emailMessage['message'])

    return HttpResponseRedirect(reverse_lazy('organisation_manage'))
def organisation_toggle_admin(request, pk):
    teacher = get_object_or_404(Teacher, id=pk)
    user = request.user.userprofile.teacher

    # check user has authority to change
    if teacher.school != user.school or not user.is_admin:
        raise Http404

    # check not trying to change self
    if user == teacher:
        raise Http404

    teacher.is_admin = not teacher.is_admin
    teacher.save()

    if teacher.is_admin:
        messages.success(request, 'Administrator status has been given successfully.')
        emailMessage = emailMessages.adminGivenEmail(request, teacher.school.name)
    else:
        messages.success(request, 'Administrator status has been revoked successfully.')
        emailMessage = emailMessages.adminRevokedEmail(request, teacher.school.name)

    send_email(NOTIFICATION_EMAIL, [teacher.user.user.email], emailMessage['subject'], emailMessage['message'])

    return HttpResponseRedirect(reverse_lazy('organisation_manage'))
def organisation_toggle_admin(request, pk):
    teacher = get_object_or_404(Teacher, id=pk)
    user = request.user.new_teacher

    check_is_toggle_authorised(teacher, user)

    if request.method == 'POST':
        teacher.is_admin = not teacher.is_admin
        teacher.save()

        if teacher.is_admin:
            messages.success(
                request, 'Administrator status has been given successfully.')
            emailMessage = emailMessages.adminGivenEmail(
                request, teacher.school.name)
        else:
            messages.success(
                request, 'Administrator status has been revoked successfully.')
            emailMessage = emailMessages.adminRevokedEmail(
                request, teacher.school.name)

        send_email(NOTIFICATION_EMAIL, [teacher.new_user.email],
                   emailMessage['subject'], emailMessage['message'])

        return HttpResponseRedirect(reverse_lazy('organisation_manage'))