def user (request, idnum): if len(Person.objects.filter(id=idnum)) == 0: if request.method == 'POST': form = NewUserForm(request.POST) if form.is_valid(): person = form.save(commit=False) person.id = idnum person.save() else: form = NewUserForm() return render(request, "scanner/newuser.html", {"idnum": idnum, "form": form}) person = Person.objects.get(id=idnum) messages = [] if request.method == 'POST': form = ScanForm(request.POST) if form.is_valid(): if len(CheckoutItem.objects.filter(id=form.cleaned_data["scan"])) > 0: item = CheckoutItem.objects.get(id=form.cleaned_data["scan"]) if len(Checkout.objects.filter(person=person, item=item, checked_in=False)) > 0: for checkout in Checkout.objects.filter(person=person, item=item, checked_in=False): checkout.checked_in = True checkout.date_returned = datetime.now() checkout.save() messages.append(item.name + " successfully checked in.") else: new_checkout = Checkout(person=person, item=CheckoutItem.objects.get(id=form.cleaned_data["scan"]), date_checked_out=datetime.now() , date_due=datetime.now() + timedelta(CheckoutItem.objects.get(id=form.cleaned_data["scan"]).default_checkout_time)) new_checkout.save() messages.append(item.name + " successfully checked out.") else: messages.append("That item is not in the database.") form = ScanForm() return render(request, "scanner/user.html", {"person": person, "form": form, "checkouts": Checkout.objects.filter(person=person, checked_in=False), "messages": messages})
def _create(request): form = NewUserForm(request.POST) if form.is_valid(): new_user = form.save() messages.success(request, "New user created!") return redirect(new_user) return new(request, form)
def new_user(request): if not request.user.is_superuser: messages.error(request, "you are not authorized to create users") return redirect('profile') else: if request.method == 'POST': form = NewUserForm(request.POST) if form.is_valid(): user = form.save(commit=False) user.username = user.email user.is_staff = True user.save() messages.success( request, "You have created a new user: " + user.username) return redirect(reverse('profile')) else: messages.error(request, 'Please correct the errors below.') else: form = NewUserForm() args = { 'form': form, 'cancelview': 'profile', 'heading_text': 'You are creating a new User!', 'button_text': 'Save User', } return render(request, 'form.html', args)
def new(request, usp=None): data = {} if usp: data['usp'] = True if "next" in request.POST: data['next'] = clear_url(request, request.POST['next']) if "create" in request.POST: form = NewUserForm(request.POST) if form.is_valid(): user = form.save() try: send_mail(_(u"Criação de conta no Delos"), user, "users/email_newuser.html", {'name': user.name}) except: pass # mail couldn't be sent, probably email is wrong... what should I do oh Lord? password = request.POST['password1'] next = clear_url(request, request.POST.get('next', '') ) request.POST = QueryDict('username=%s&password=%s'% (user.identification, password) ) return login(request, next) else: form = NewUserForm() data['form'] = form return render_to_response('users/create.html', data, context_instance=RequestContext(request))
def new_user(request): if request.method == 'POST': form = NewUserForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('posting_site')) else: form = NewUserForm() context = { 'form': form, } return render( request, 'new_user.html', context=context, )
def new_account(request): next = request.GET.get('next', default = '/') if request.method == "POST": form = NewUserForm(request.POST) if form.is_valid(): form.save() user = authenticate(username=request.POST['username'], password=request.POST['password1']) login(request, user) print next return HttpResponseRedirect(next) return render_to_response('interface/new_user.html', {'form':form}, context_instance=RequestContext(request)) form = NewUserForm() return render_to_response('interface/new_user.html', {'form':form.as_table, 'path':next}, context_instance=RequestContext(request))
def signup(request): if request.method == "POST": form = NewUserForm(request.POST) print(dir(form.errors)) if form.is_valid(): form.save() login(request, form.cleaned_data['user']) #password = request.POST['password'] #user = authenticate(username=user, password=password) #print(user, password) #if user is not None: # login(request, user) # print('SESSION user is', request.session) return HttpResponseRedirect(reverse('main')) else: return render(request, 'qa/signup.html', {'form': form}) else: form = NewUserForm() return render(request, 'qa/signup.html', {'form': form})
def new_account(request): next = request.GET.get('next', default='/') if request.method == "POST": form = NewUserForm(request.POST) if form.is_valid(): form.save() user = authenticate(username=request.POST['username'], password=request.POST['password1']) login(request, user) print next return HttpResponseRedirect(next) return render_to_response('interface/new_user.html', {'form': form}, context_instance=RequestContext(request)) form = NewUserForm() return render_to_response('interface/new_user.html', { 'form': form.as_table, 'path': next }, context_instance=RequestContext(request))
def createUser(request): print "** createUser DEBUG LOG**" form = NewUserForm(request.POST) print 'form set' if form.is_valid(): newUser = form.save() newUserProfile = Profile(user=newUser) newUserProfile.save() print "user '%s' created" % newUser.username print '**OK**' return HttpResponseRedirect(reverse('home')) else: form = NewUserForm() print 'form reset' print '**ERR FORM CREATION FAILED**' return render(request, 'signup.html', {'form':form})
def registration(request): if request.user.is_authenticated(): return redirect(to='profile', permanent=True) context = dict(active_tab='registration') if request.method == 'POST': form = NewUserForm(request.POST) if form.is_valid(): user = form.save() user.account = Account() user.account.save() request.session['registration_completed'] = True return redirect(to='login', permanent=True) else: context['form'] = form else: context['form'] = NewUserForm() return render(request, 'accounts/registration.html', context)