def post(self, request): form = CustomerUserDelectionForm(request.POST) if form.is_valid(): data = {} data['password'] = request.POST['password'] password = request.POST['password'] # utilizando o authenticate do django user = authenticate(username=request.user.username, password=password) if user is not None: user = form.delete() user.delete() messages.sucess(request, 'Sua conta foi excluída') response = render(request, 'signup.html') return response else: pass else: response = render(request, 'excluirConta.html', {'form': form}) return response
def delete_farm(request, pk): user = request.user profile = Profile.objects.get(user__id=user.id) farm = Farm.objects.get(pk=pk, profile__id=profile.id) farm.delete() messages.sucess(request, "Farm successfully deleted.") return HttpResponseRedirect(reverse_lazy("farms:farm-list"))
def search(request): if request.method == 'POST': srch = request.POST['srh'] if srch != None: t = srch.split(",") l = [] for i in t: print(i) match = Search.objects.filter( Q(course__icontains=i) | Q(faculty__icontains=i) | Q(location__icontains=i)) print(match) if match: l.append(match) # print(l) else: messages.error( request, 'data not found Please enter course name .......') # if len(l)==0: # messages.error(request, 'no result found') # else: return render(request, 'search.html', {'sr': l}) else: messages.sucess("enter data") else: #return HttpResponseRedirect('/search/') return render(request, 'search.html')
def del_user(request): try: u = User.objects.all() u.delete() messages.sucess(request, "The user is deleted") except: messages.error(request, "The user not found") return redirect('/')
def remove_user(request, user_id): try: u = User.objects.get(id=user_id) u.delete() messages.sucess(request, "The user was deleted") except: messages.error(request, "The user was not found", extra_tags='danger') return redirect('/auth/users/page-1/')
def post(self, request, *args, **kwargs): form = PasswordChangeForm(request.user, request.POST) if form.is_valid(): user = form.save() update_session_auth_hash(request, user) messages.sucess(request, 'Your password was sucessfully updated!') return redirect('change_password') else: messages.error(request, 'Please correct the error below') return render(request, 'account/change_password.html', {'form': form})
def post(self, request, *args, **kwargs): formAvaliacaoPosturalSalva = AvaliacaoPosturalForm(request.POST) formAvaliacaoPosturalSalva.save() formAvaliacaoPosturalSalva = AvaliacaoPosturalForm messages.sucess(request, 'Os dados foram salvos com sucesso.') context = { 'title': 'Nova Avaliacao Postural', 'formAvaliacaoPostural': formAvaliacaoPosturalSalva, } return render(request, 'avaliacao-postural.html', context)
def delete2(request, id): try: u = get_object_or_404(User, id=id) u.delete() messages.sucess(request, "The user is deleted") except User.DoesNotExist: messages.error(request, "User doesnot exist") return render(request, 'member_list.html') except Exception as e: return render(request, 'member_list.html', {'err': e.message})
def add_user(request): if request.method == 'POST': form = UserForm(request.POST) if form.is_valid(): u = form.save() u.set_password(u.password) u.save() messages.sucess(request, 'Usuário criado com sucesso! Utilize o formulário abaixo para fazer login.') return redirect('accounts:user_login') else: form = UserForm() return render(request, 'accounts/add_user.html', {'form': form})
def record_giveaway_response(request, giveaway_id): giveaway = get_object_or_404(Giveaway, id=giveaway_id) form = GiveawayResponseForm(request.POST or None) if form.is_valid(): new_instance = form.save() new_instance.giveaway = giveaway new_instance.respondent = request.user new_instance.save() messages.sucess(request, 'Your response has been recorded.') try: return HttpResponseRedirect(giveaway.update_set.all()[0].get_absolute_url()) except: return HttpResponseRedirect(reverse('events_index'))
def change_password(request): if request.method == 'POST': form = passwordChange(request.user, request.POST) if form.is_valid(): user = form.save() update_session_auth_hash(request, user) messages.sucess(request, 'Password changed successfully!') return render(request, 'home/home.html') else: messages.error(request, 'Error below') else: form = passwordChange(request.user) return render(request, 'accounts/change_password.html', {'form': form})
def subscription_create(request): if request.GET: full_path = request.get_full_path form = SubForm(request.POST or None, request.FILES or None) if form.is_valid() or form.is_bound: form.save() messages.sucess(request, "Thanks for subscribing to station, I'll give you more content with no ugly filler") else: messages.error(request, "Sorry, there was a problem handling request") return HttpResponseRedirect(full_path) context = {"form": form} return render(request, "sub_form.html", context)
def record_giveaway_response(request, giveaway_id): giveaway = get_object_or_404(Giveaway, id=giveaway_id) form = GiveawayResponseForm(request.POST or None) if form.is_valid(): new_instance = form.save() new_instance.giveaway = giveaway new_instance.respondent = request.user new_instance.save() messages.sucess(request, 'Your response has been recorded.') try: return HttpResponseRedirect( giveaway.update_set.all()[0].get_absolute_url()) except: return HttpResponseRedirect(reverse('events_index'))
def register(request): #working with the post data,,if we get post request it gets passes to form if not the empty post is passes if request.method == 'POST': form = form = UserCreationForm(request.POST) #to validate the post,,if we are getting the fields and data that we expect if form.is_valid(): form.save() # this saves the user username = form.cleaned_data.get('username') messages.sucess(request, f'account created for{username}!') #redirecting return redirect('blog-home') else: form = UserCreationForm() form = UserCreationForm() #rendering a template using this form... return render(request, 'users/register.html', {'form': form})
def create_url(request): url = request.POST['url'] if Url.objects.filter(full_url=url).exists(): menssagem = _('Url já existente') messages.sucess(request, menssagem) return redirect('index') url = Url(full_url=url) url.save() data = { 'full_url': url.full_url, 'hash': url.short_url, } return render(request, 'pages/created.html', data)
def inserir_membro(request, id): capitao = True # checa se o id é um número e existe um time associado de fato try: id = int(id) except ValueError: raise Http404() try: time = Time.objects.get(id=id) except Time.DoesNotExist: messages.error(request, 'O time pedido não existe, confira a url digitada =).') return redirect('/') if request.method == 'GET': # checar se o usuário é capitão do time try: contrato = Contrato.objects.get(user__user__username=request.user.username, time__id=id) capitao = contrato.capitao except Contrato.DoesNotExist: messages.error(request, 'Só o capitão do time pode adicionar membros =(.') return redirect('/times/meus-times/') form = InserirMembroForm(initial={'time_id': id}) else: form = InserirMembroForm(request.POST) if form.is_valid(): form_data = form.cleaned_data if insere_membro(request.user.username, id, form_data): messages.sucess(request, 'Membro adicionado com sucesso!') redirect_url = u'/times/{0}/'.format(id) return redirect(redirect_url) else: messages.error(request, 'Erro interno ao inserir usuário =/. Tente mais tarde ou contate-nos sobre o erro.') else: messages.error(request, 'Parece que há algo de errado no seu formulário, confira-o por favor =).') return render(request, 'time-inserir-membro.html', { 'time_inserir_form': form, 'time': time, 'capitao': capitao, }, context_instance=RequestContext(request))
def edit(request): if request.method == "POST": 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() messages.sucess(request, "Profile updates successfully") else: messages.error(request, "Error updating your profile") else: user_form = UserEditForm(instance=request.user) profile_form = ProfileEditForm(instance=request.user.profile) return render(request, 'account/edit.html', { 'user_form': user_form, 'profile_form': profile_form })
def search(request): if request.method == 'POST': srch = request.POST['srh'] if srch != None: t = srch.split(",") l = [] for i in t: print(i) match = Search.objects.filter(Q(job__icontains=i)) print(match) if match: l.append(match) else: messages.error(request, 'Data not found Please try again .......') return render(request, 'search.html', {'sr': l}) else: messages.sucess("enter data") else: return render(request, 'search.html')
def form_valid(self, form): form.save(request=self.request) messages.sucess(self.request, "Password changed successfully.") return HttpResponseRedirect("/")