Exemple #1
0
def modify(request):

    user = request.user
    student = user.userinformation

    if request.method == "POST":

        user_form = UserEditForm(request.POST, instance=request.user)
        userinformation_form = UserInformationForm(request.POST, instance=request.user.userinformation)

        if user_form.is_valid() and userinformation_form.is_valid():

            user.save()
            userinformation_form.save()
            return redirect('user-profile')

    else:

        user_form = UserEditForm(instance=request.user)
        userinformation_form = UserInformationForm(instance=request.user.userinformation)
    return render(
        request,
        'user/edit.html',
        {
            'title': '{} {}'.format(user.first_name, user.last_name),
            'user_form': user_form,
            'userinformation_form': userinformation_form
        }
    )
class EditUser(TemplateView):
    template_name = 'user/edit_user.html'

    @method_decorator(email_black_list_check(false_function=HttpResponse('/')))
    @method_decorator(login_required)
    def get(self, request, *args, **kwargs):
        user = get_user_model().objects.get(pk=request.user.pk)
        self.form = UserEditForm(instance=user)
        return super(EditUser, self).get(request, *args, **kwargs)

    @method_decorator(email_black_list_check(false_function=HttpResponse('/')))
    @method_decorator(login_required)
    def post(self, request, *args, **kwargs):
        recaptcha_response = captchaResult(
            request.POST.get('g-recaptcha-response'))
        user = get_user_model().objects.get(pk=request.user.pk)
        self.form = UserEditForm(request.POST, instance=user)
        if self.form.is_valid():
            if True:  #recaptcha_response['success']:
                self.form.save()
                return redirect('/')
            MessageManager().makeMessage(request, message='confirm_not_robot')
            return redirect(str(request.path))
        MessageManager().makeMessage(request, message='problem_with_save')
        return redirect(str(request.path))

    def get_context_data(self, **kwargs):
        context = super(EditUser, self).get_context_data(**kwargs)
        context['edit_user_form'] = self.form
        return context
def settings(request):
    user = request.user
    if request.method == 'POST':
        form = ProfileForm(request.POST, instance=request.user)
        user_form = UserEditForm(instance=request.user, data=request.POST)
        if form.is_valid() and user_form.is_valid():
            user.first_name = form.cleaned_data.get('first_name')
            user.last_name = form.cleaned_data.get('last_name')
            user.profile.job_title = form.cleaned_data.get('job_title')
            user.email = form.cleaned_data.get('email')
            user.profile.url = form.cleaned_data.get('url')
            user.profile.location = form.cleaned_data.get('location')
            user.profile.about = form.cleaned_data.get('about')
            user.save()
            messages.add_message(request, messages.SUCCESS,
                                 'Your profile was successfully edited.')

    else:
        user_form = UserEditForm(instance=request.user)
        form = ProfileForm(instance=user,
                           initial={
                               'job_title': user.profile.job_title,
                               'url': user.profile.url,
                               'location': user.profile.location,
                               'about': user.profile.about,
                           })
    return render(request, 'core/settings.html', {'form': form})
Exemple #4
0
def modify(request):
    user = request.user
    student = user.userinformation

    if request.method == "POST":

        user_form = UserEditForm(request.POST, instance=request.user)
        userinformation_form = UserInformationForm(
            request.POST, instance=request.user.userinformation)

        if user_form.is_valid() and userinformation_form.is_valid():

            user.save()
            userinformation_form.save()
            return redirect('user-profile')

    else:

        user_form = UserEditForm(instance=request.user)
        userinformation_form = UserInformationForm(
            instance=request.user.userinformation)
    return render(
        request, 'user/edit.html', {
            'title': '{} {}'.format(user.first_name, user.last_name),
            'user_form': user_form,
            'userinformation_form': userinformation_form
        })
Exemple #5
0
def edit(request):
    form = UserEditForm(request.POST or None,
                        request.FILES or None,
                        instance=request.user)
    if form.is_valid():
        form.save()
        return close_view(request, 'project-list')
    return render(request, 'edit.html', {'form': form})
Exemple #6
0
 def post(self, request):
     user_form = UserEditForm(instance=request.user, data=request.POST)
     profile_form = ProfileEditForm(instance=request.user.profile,
                                    data=request.POST,
                                    files=request.FILES)
     if user_form.is_valid() and profile_form.is_valid():
         user_form.save()
         profile_form.save()
     return HttpResponseRedirect(reverse('footage-view'))
 def post(self, request, *args, **kwargs):
     recaptcha_response = captchaResult(
         request.POST.get('g-recaptcha-response'))
     user = get_user_model().objects.get(pk=request.user.pk)
     self.form = UserEditForm(request.POST, instance=user)
     if self.form.is_valid():
         if True:  #recaptcha_response['success']:
             self.form.save()
             return redirect('/')
         MessageManager().makeMessage(request, message='confirm_not_robot')
         return redirect(str(request.path))
     MessageManager().makeMessage(request, message='problem_with_save')
     return redirect(str(request.path))
Exemple #8
0
    def post(self, request, *args, id):
        user = get_object_or_404(UserInfo, user_id=id)
        form = UserEditForm(request.POST, instance=user)
        if not form.is_valid():
            errors = {key: invalid_msg.format(value[0]) for key, value in form.errors.items()}
            return render(request, self.template_name, {'error': errors, 'form': form})

        user = form.save(commit=False)
        user.updatedUser = request.user.username
        user.updatedTime = datetime.now()
        user.save()

        return redirect('user:user')
Exemple #9
0
 def get(self, request):
     user_form = UserEditForm(instance=request.user)
     profile_form = ProfileEditForm(instance=request.user.profile)
     return render(request, 'user/user_edit_form.html', {
         'user_form': user_form,
         'profile_form': profile_form,
     })
Exemple #10
0
def manageuser(request, username):
    user = get_object_or_404(User, username = username)
    user2 = Profile.objects.get(user = user.pk)
    profileform = ProfileForm(instance = user2)
    userform = UserEditForm(instance = user)
    args = {'profileform' : profileform, 'userform' : userform, 'user' : user2, 'data' : user}
    if request.method == 'POST':
        profileform = ProfileForm(request.POST, request.FILES, instance = user2)
        userform = UserEditForm(request.POST, instance = user)
        if profileform.is_valid() and userform.is_valid():
            profileform.save()
            userform.save()
            args = {'profileform' : profileform, 'userform' : userform, 'user' : user2, }
            return redirect('/webmaster/user/'+user.username)
        else:
            print("errors : {}".format(profileform.errors.as_data()))
            print("errors : {}".format(userform.errors.as_data()))
    return render(request, 'webadmin/pages/manage/user/index.html',args)
Exemple #11
0
def edit_profile(request):
    if request.method == 'POST':
        user_form = UserEditForm(data=request.POST or None,
                                 instance=request.user)
        profile_form = ProfileEditForm(data=request.POST or None,
                                       instance=request.user.profile,
                                       files=request.FILES or None)
        if user_form.is_valid and profile_form.is_valid():
            user_form.save()
            profile_form.save()
    else:
        user_form = UserEditForm(instance=request.user)
        profile_form = ProfileEditForm(instance=request.user.profile)

    return render(request, 'edit_profile.html', {
        'user_form': user_form,
        'profile_form': profile_form
    })
 def get(self, request, *args, **kwargs):
     user = get_user_model().objects.get(pk=request.user.pk)
     self.form = UserEditForm(instance=user)
     return super(EditUser, self).get(request, *args, **kwargs)
Exemple #13
0
 def get(self, request, *args, id):
     user = get_object_or_404(UserInfo, user_id=id)
     form = UserEditForm(instance=user)
     return render(request, self.template_name, {'form': form})