Example #1
0
def add_profile_info(request):
    user = get_current_user(request)
    if request.method == 'POST':
        try:
            profile = user.profile
        except:
            profile = None
        form = ProfileForm(instance=profile,
                           data=request.POST,
                           files=request.FILES)

        if form.is_valid():
            form.save()
            return redirect('/user/{}/'.format(user.id))
        else:
            return render(request, 'user_profile/profile_info_form.html', {
                'user': user,
                'form': form,
            })
    elif request.method == 'GET':
        form = create_populated_profile_form(user)

        return render(request, 'user_profile/profile_info_form.html', {
            'user': user,
            'form': form,
        })
Example #2
0
 def test_profile_form_clean(self):
     image = SimpleUploadedFile("img.png",
                                b"file_content",
                                content_type="image/png")
     skill = Skill.objects.create(name='SKILL')
     data = {'skill': skill, 'picture': image}
     form = ProfileForm(data)
     self.assertTrue(form.is_valid())
Example #3
0
def view_edit_form(request):
    user = User.objects.get(id=request.user.id)
    profile = None
    try:
        profile = Profile.objects.get(user=user)
        profile_form = ProfileForm(instance=profile)
    except ObjectDoesNotExist:
        profile_form = ProfileForm()
    context = {
        'form': profile_form,
    }
    return render(request, 'user_profile/Profile_edit.html', context)
Example #4
0
def change(request):
    profile, create = Profile.objects.get_or_create(user=request.user)
    
    #profile=Profile.objects.filter(user=request.user).get()
    if request.method== "POST":
        form=ProfileForm(request.POST, instance=profile)
        if form.is_valid():
            profile= form.save(commit=False)
            profile.save()
        
            return HttpResponseRedirect('/pin/user/%d' % request.user.id)
    else:
        form = ProfileForm(instance=profile)
    return render_to_response('user_profile/change.html',{'form':form},context_instance=RequestContext(request))
Example #5
0
def edit_profile(request):
    
    if request.method == 'POST':
        color_blindness = request.POST.get("color_blindness", None)
        editor_theme = request.POST.get("editor_theme", None)
        confirm = request.POST.get("confirm", False)
    
        if color_blindness is not None:  # Can be 0
            request.user.profile.color_blindness = color_blindness
        if editor_theme is not None:  # Can be 0
            request.user.profile.editor_theme = editor_theme
        
        request.user.profile.confirm = confirm == 'on'
        request.user.profile.save()
        messages.info(request, "Paramètres sauvergardés.")
    
    form = ProfileForm(initial={
        "color_blindness": request.user.profile.color_blindness,
        "editor_theme": request.user.profile.editor_theme,
        "student_id": request.user.profile.student_id,
        "consumer_id": request.user.profile.consumer_id,
        "role": request.user.profile.role,
        "mail": request.user.email,
        "confirm": request.user.profile.confirm,
    })
    
    return render(request, "user_profile/edit_profile.html", {"form": form})
Example #6
0
def settings(request):
    user = request.user
    if request.method == 'POST':
        form = ProfileForm(request.POST)
        if form.is_valid():
            user.first_name = form.cleaned_data.get('first_name')
            user.last_name = form.cleaned_data.get('last_name')
            user.email = form.cleaned_data.get('email')
            user.profile.location = form.cleaned_data.get('location')
            user.save()
            messages.add_message(request, messages.SUCCESS, 'Your profile has been  successfully edited.')
    else:
        form = ProfileForm(instance=user, initial={
            'location': user.profile.location
            })
    return render_to_response('setting.html', {'form':form})
Example #7
0
 def get_context_data(self, **kwargs):
     context = super(ProfileEdit, self).get_context_data()
     profile = get_object_or_404(UserProfile, user=self.request.user)
     fullname = profile.fullname
     form = ProfileForm({'fullname': fullname})
     if self.request.POST:
         # print("post")
         form = self.get_form()
     context['form'] = form
     return context
Example #8
0
def profile(request):
    if request.method == 'POST':
        profile_info = ProfileForm(request.POST or None, request.FILES or None)
        if profile_info.is_valid():
            profile_info.save(commit=True)
        else:
            return render(request, 'Trial_app/profile.html', {'form': profile_info})
    else:
        profile_info = ProfileForm()
    return render(request, 'user_profile/profile.html', {'form': profile_info})
Example #9
0
def save_form(request):
    form = ProfileForm(request.POST,
                       instance=Profile.objects.get(user=request.user))
    if form.is_valid():
        profile = form.save(commit=False)
        profile.user = request.user
        avatar = request.FILES.get("profile_image")
        if avatar and avatar.content_type.__contains__(
                'image/'):  #check valid file
            if profile.avatar_path:
                delete_from_firebase(profile.avatar_path)
            img_folder = save_file_to_firebase(file=avatar,
                                               type='image',
                                               path='profile_pics/' +
                                               str(request.user.username))
            profile.avatar_url = img_folder[0]
            profile.avatar_path = img_folder[1]

        profile = form.save(commit=True)
    return HttpResponseRedirect(
        reverse('profile:profile_view', args=(request.user.username, )))
Example #10
0
def home_page(request):
    if request.method == 'GET':
        profile = Profile.objects.all()

        if not profile:
            context = {'form': ProfileForm(label_suffix='')}
            return render(request, 'homepage/home-no-profile.html', context)

        else:
            expenses = Expense.objects.all()
            profile = profile[0]
            profile.balance = profile.budget - sum(
                [expense.price for expense in expenses])
            context = {
                'expenses': expenses,
                'profile': profile,
            }
            return render(request, 'homepage/home-with-profile.html', context)

    elif request.method == 'POST':
        form = ProfileForm(request.POST)
        if not form.is_valid():
            context = {'form': ProfileForm(), 'errors': form.errors}
            return render(request, 'homepage/home-no-profile.html', context)
        profile = form.save(commit=False)
        profile.full_clean()  # check what full_clean
        profile.save()
        return render(request, 'homepage/home-with-profile.html')
Example #11
0
def personal_info(request):
    if request.method == 'POST':
        user_form = UserForm(request.POST, instance=request.user)
        profile_form = ProfileForm(request.POST, request.FILES, instance=request.user.profile)
        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
            messages.success(request, 'Your profile was successfully updated!')
            return redirect('profile:personal_info')
        else:
            messages.error(request, 'Please correct the error below.')

    user_form = UserForm()
    profile_form = ProfileForm()
    return render(request, 'user_profile/personal_info.html',
                  {'title': 'Personal info',
                   'user_form': user_form,
                   'profile_form': profile_form})
Example #12
0
def edit_profile(request):
    current_profile = Profile.objects.all()[0]
    context = {'form': ProfileForm(instance=current_profile, label_suffix='')}

    if request.method == 'GET':
        return render(request, 'profile/profile-edit.html', context)

    elif request.method == 'POST':
        form = ProfileForm(request.POST, instance=current_profile)

        if not form.is_valid():
            return render(request, 'profile/profile-edit.html', {'form': form})

        form.save()
        return redirect('profile')
Example #13
0
def change(request):
    profile, create = Profile.objects.get_or_create(user=request.user)

    #profile=Profile.objects.filter(user=request.user).get()
    if request.method == "POST":
        form = ProfileForm(request.POST, instance=profile)
        if form.is_valid():
            profile = form.save(commit=False)
            profile.save()

            return HttpResponseRedirect('/pin/user/%d' % request.user.id)
    else:
        form = ProfileForm(instance=profile)
    return render_to_response('user_profile/change.html', {'form': form},
                              context_instance=RequestContext(request))
Example #14
0
def profile_update(request, *args, **kwargs):
    profile = UserProfile.objects.get(pk=kwargs['pk'])
    user = profile.user
    if request.method == 'POST':
        # For submission of form for updating information...
        form = ProfileForm(request.POST, request.FILES, instance=profile)
        if form.is_valid():
            form.save()
            user.first_name = form.cleaned_data.get('first_name')
            user.last_name = form.cleaned_data.get('last_name')
            user.email = form.cleaned_data.get('email')
            user.save()
            return HttpResponseRedirect(
                reverse('profile:profile'))
    else:
        # For populating a form when a user navigates to page
        # using the edit link in the profile detail page...
        initial = {'first_name': user.first_name,
                   'last_name': user.last_name,
                   'email': user.email,
                   }

        form = ProfileForm(instance=profile, initial=initial)
    return render(request, 'profile_update.html', {'form': form})