コード例 #1
0
ファイル: views.py プロジェクト: octaflop/arxer
def faculty_edit(request, *args, **kwargs):
    """ A wrapper to pull up a student and edit them """
    faculty = Faculty.objects.get(member__slug=kwargs['slug'])
    is_me = False
    if request.method == 'POST':
        form = FacultyForm(request.POST, instance=faculty)
        if faculty.member.user == request.user:
            is_me=True
        if form.is_valid():
            new_faculty = form.save(commit=False)
            if is_me:
                new_faculty.member = request.user.member
                faculty.delete()
                new_faculty.save()
                return redirect(faculty.get_absolute_url())
            else:
                return HttpResponse(status=403)
    else:
        form = FacultyForm(instance=faculty)
    ret = dict(object=faculty, form=form, is_me=is_me)
    return render(request, 'verbena/members/faculty_form.html', ret)
コード例 #2
0
ファイル: views.py プロジェクト: octaflop/arxer
def add_faculty(request, *args, **kwargs):
    """
    Sign up a member as a faculty.
    Also "seal" the faculty into this membership by deleting old memberships
    """
    data = request.POST
    facultyform = FacultyForm(data=data)
    if facultyform.is_valid():
        faculty = facultyform.save(commit=False)
        faculty.member = request.user.member
        del_member_class(faculty.member)
        # after deleting, we finally try one more save
        try:
            faculty.save()
            messages.add_message(request, messages.SUCCESS,
                _("Successfully added %(faculty)s as faculty.") % {
                    "faculty": faculty.member.user.username
                }
            )
        except:
            return HttpResponse(status=500)
        return redirect(faculty.get_absolute_url())
    ret = dict(form=facultyform)
    return HttpResponse(request, 'verbena/members/faculty_form.html', ret)