Beispiel #1
0
def student_edit(request, *args, **kwargs):
    """ A wrapper to pull up a student and edit them """
    student = Student.objects.get(member__slug=kwargs['slug'])
    is_me = False
    if request.method == 'POST':
        form = StudentForm(request.POST, instance=student)
        if student.member.user == request.user:
            is_me=True
        if form.is_valid():
            new_student = form.save(commit=False)
            if is_me:
                new_student.member = request.user.member
                student.delete()
                new_student.save()
                return redirect(student.get_absolute_url())
            else:
                return HttpResponse(status=403)
    else:
        form = StudentForm(instance=student)
    ret = dict(object=student, form=form, is_me=is_me)
    return render(request, 'verbena/members/student_form.html', ret)
Beispiel #2
0
def add_student(request, *args, **kwargs):
    """
    Sign up a member as a student.
    Also "seal" the student into this membership
    """
    data = request.POST
    studentform = StudentForm(data=data)
    if studentform.is_valid():
        student = studentform.save(commit=False)
        student.member = request.user.member
        del_member_class(student.member)
        # after deleting, we finally try one more save
        try:
            student.save()
            messages.add_message(request, messages.SUCCESS,
                _("Successfully added %(student)s as student.") % {
                    "student": student.member.user.username
                }
            )
        except:
            return HttpResponse(status=500)
        return redirect(student.get_absolute_url())
    ret = dict(form=studentform)
    return HttpResponse(request, 'verbena/members/student_form.html', ret)