Beispiel #1
0
def edit_profile(request):
    user = request.user
    user_profile = user.user_profile
    error = False
    msg = None

    if request.POST:
        user_form = UserEditForm(request.POST, instance=user)
        profile_form = UserProfileForm(request.POST, instance=user_profile)
        if user_form.is_valid():
            user_profile = user_form.save(commit=False)
            user_profile.save()
            profile_form.is_valid()
            print profile_form
            if profile_form.is_valid():
                profile = profile_form.save(commit=False)
                if "url" in request.POST:
                    profile.picture = cropAndSave(user, request.POST)
                # return here if different behaviour desired
                profile.save()

                return JsonResponse({error: False,msg: "Profile Updated!"})
            else:
                return JsonResponse({error: True,msg: "Please check the required fields"})
        else:
            return JsonResponse({error: True,msg: "Please check the required fields"})
    else:
        user_form = UserEditForm(instance=user)
        profile_form = UserProfileForm(instance=user_profile)
    return render(request, "mentee/edit_profile.html", locals())
Beispiel #2
0
def edit_profile(request):
    user = request.user
    user_profile = user.user_profile

    if request.method == 'POST' and request.POST:
        user_form = UserEditForm(request.POST, instance=user)
        profile_form = UserProfileForm(request.POST, request.FILES, instance=user_profile)
        edu_formset = EducationDetailsFormSet(request.POST, instance=user_profile)
        emp_formset = EmploymentDetailsFormSet(request.POST, instance=user_profile)
        if user_form.is_valid() and profile_form.is_valid() and edu_formset.is_valid() and emp_formset.is_valid():
            if "url" in request.POST:
                user_profile.picture = cropAndSave(user, request.POST)
                user_profile.save()

            user_form.save()
            profile_form.save()
            emp_formset.save()
            edu_formset.save()
            return render(request, "mentor/edit_profile.html", locals())
            # return here if different behaviour desired
        else:
            print user_form.errors
            print profile_form.errors
            return render(request, "mentor/edit_profile.html", locals())
    else:
        user_form = UserEditForm(instance=user)
        profile_form = UserProfileForm(instance=user_profile)
        edu_formset = EducationDetailsFormSet(instance=user_profile)
        emp_formset = EmploymentDetailsFormSet(instance=user_profile)

    context = RequestContext(request)
    context_dict = {}

    categories = Business_categories.objects.all()

    dict_index = 0;
    for cat in categories:
        subcat_list = []
        subcategories = Business_subcategories.objects.filter(category_id=cat.id)
        subcat_list.append({'category_id': cat.id, 'category_name': cat.name, 'subcategories': subcategories})
        context_dict[dict_index] = subcat_list
        dict_index = dict_index + 1

    tags = Business_Mentor_Tags.objects.filter(mentor=user_profile)

    return render(request, "mentor/edit_profile.html", locals())