コード例 #1
0
def edit_profile(request):
    address_formset = formset_factory(AddressForm, max_num=2, extra=2)
    student = Alumno.objects.get(id=request.user.id)

    if request.method == 'POST':
        form = StudentProfileForm(request.POST,
                                  request.FILES,
                                  student_id=student.id)
        formset = address_formset(request.POST)
        if form.is_valid() and formset.is_valid():
            ProfileService.reconstruct_and_save(form, formset, request.user.id)
            messages.success(request,
                             _('Information has been saved successfully.'))
        elif len(request.FILES) > 0:
            # Warn the user to select the image again
            messages.warning(request,
                             _('Please, select the profile photo again.'))

    else:

        form = StudentProfileForm(
            initial=ProfileService.get_form_data(student),
            student_id=student.id)
        formset = address_formset(
            initial=ProfileService.get_formset_data(student))

    return render_to_response('profile/edit.html', {
        'form': form,
        'formset': formset,
        'student': student
    },
                              context_instance=RequestContext(request))
コード例 #2
0
def edit_lecturer(request):
    lecturer = Profesor.objects.get(id=request.user.id)

    if request.method == 'POST':
        form = LecturerProfileForm(request.POST)
        if form.is_valid():
            ProfileService.update_profile(lecturer, form)
            messages.success(request, _('Information was updated successfully'))
    else:
        initial_data = ProfileService.build_initial_profile_data(lecturer)
        form = LecturerProfileForm(initial=initial_data)

    return render_to_response('lecturer/edit.html', {'form': form}, context_instance=RequestContext(request))
コード例 #3
0
def edit_lecturer(request):
    lecturer = Profesor.objects.get(id=request.user.id)

    if request.method == 'POST':
        form = LecturerProfileForm(request.POST)
        if form.is_valid():
            ProfileService.update_profile(lecturer, form)
            messages.success(request,
                             _('Information was updated successfully'))
    else:
        initial_data = ProfileService.build_initial_profile_data(lecturer)
        form = LecturerProfileForm(initial=initial_data)

    return render_to_response('lecturer/edit.html', {'form': form},
                              context_instance=RequestContext(request))
コード例 #4
0
def edit_profile(request):
    address_formset = formset_factory(AddressForm, max_num=2, extra=2)
    student = Alumno.objects.get(id=request.user.id)

    if request.method == 'POST':
        form = StudentProfileForm(request.POST, request.FILES, student_id=student.id)
        formset = address_formset(request.POST)
        if form.is_valid() and formset.is_valid():
            ProfileService.reconstruct_and_save(form, formset, request.user.id)
            messages.success(request, _('Information has been saved successfully.'))
        elif len(request.FILES) > 0:
            # Warn the user to select the image again
            messages.warning(request, _('Please, select the profile photo again.'))

    else:

        form = StudentProfileForm(initial=ProfileService.get_form_data(student), student_id=student.id)
        formset = address_formset(initial=ProfileService.get_formset_data(student))

    return render_to_response('profile/edit.html', {'form': form, 'formset': formset, 'student': student},
                              context_instance=RequestContext(request))