def Add_client(request): if request.method == 'POST': form = ClientForm(request.POST) if form.is_valid(): form.save() return msg(request,"Cliente adicionado com Sucesso") else: form = ClientForm return render(request, 'add_client.html', {'user':request.user,'form': form})
def create_client(request): if request.method == 'POST': form = ClientForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect(reverse("clients:index")) else: form = ClientForm() context = {} context.update(csrf(request)) context['create_form'] = form return render(request,"clients/createClient.html",context)
def loan_req(request, slug): loantype = get_object_or_404('LoanType', slug=slug) form = ClientForm(request.POST or None) if form.is_valid(): client = form.save(commit=False) client.loanpurpose = loantype client.save() return redirect('pymes/') return render_to_response('pymes/', { 'form': form, }, context)
def edit_client(request,client_UUID): c = Client.objects.get(client_uuid = client_UUID) if request.method == 'POST': form = ClientForm(request.POST,instance = c) if form.is_valid(): client_UUID = c.client_uuid form.save() return HttpResponseRedirect(reverse("clients:edit_client",args =[client_UUID])) else: form = ClientForm(instance = c) context = {} context.update(csrf(request)) context['model_form'] = form context['title'] = c context['uuid'] = client_UUID return render(request,"clients/editClient.html",context)
def search_form(request): """ View to display "search.html" i.e. the search interface or form. First it'll check which type of request is i.e; 'search' request or 'generate register' request. On the basis of that, it'll assign code to search_type_code which will be used in template. It'll raise an exception if anyone give invalid value in 'type'. Argument:Http Request Return:Render Search """ try: if request.GET['type'] == 'search': submit_url = reverse('search_result') search_type_code = '1' client_form = ClientForm() order_form = OrderForm() request_status = request_notify() temp = { 'client_form': client_form, 'order_form': order_form, 'code': search_type_code, 'url': submit_url, 'request': request_status } elif request.GET['type'] == 'register': submit_url = reverse('view_register') search_type_code = '2' client_form = ClientForm() order_form = OrderForm() add_constraints = AddConstraints() request_status = request_notify() temp = { 'client_form': client_form, 'order_form': order_form, 'add_constraints': add_constraints, 'code': search_type_code, 'url': submit_url, 'request': request_status } else: return HttpResponse('<h1>Page not found</h1>') except: return HttpResponse('<h1>Invalid URL</h1>') return render(request, 'reports/search.html', temp)
def client(): form = ClientForm(request.form) if request.method == 'POST': if form.validate() == False: return render_template('client.html', form=form) else: newclient = Client( client_id=gen_salt(40), client_secret=gen_salt(50), client_name=form.name.data, redirect_uris=form.redirect_url.data, default_scopes='email', ) db.session.add(newclient) db.session.commit() return jsonify( client_id=newclient.client_id, client_secret=newclient.client_secret, ) else: return render_template('client.html', form=form)
def formBusquedaCliente(): form = ClientForm() saleData = funciones.salesData() if form.validate_on_submit(): data = form.client.data client = data.title() clientList = funciones.consultedDataClient(client, saleData) return render_template('consultas/productos-por-cliente-form.html', form=form, searchClient=client, lista=clientList) if len(clientList) == 0: clientList = None else: return redirect(url_for('tableProductsPerClient', client=client)) return render_template('consultas/productos-por-cliente-form.html', form=form)
def singclient(request): if request.method == 'POST': user_form = ClientForm(request.POST, prefix='user') profile_form = ClientProfile(request.POST, prefix='Profile') if user_form.is_valid() and profile_form.is_valid(): user_obj = user_form.save() user_profile = profile_form.save(commit=False) user_profile.user = user_obj user_profile.save() login_url = reverse("sign:entrar") url_to_redirect = u"{0}?username={1}".format(login_url, user_obj.username) return HttpResponseRedirect(url_to_redirect) else: user_form = ClientForm(prefix='user') profile_form = ClientProfile(prefix='Profile') ctx = {'clientform': user_form, 'ClientProfile': profile_form} return render(request, "regclient.html", ctx)
def register(request): if request.method == "POST": form = ClientForm(request.POST) if form.is_valid(): # is_active=False) # user.save() # client = Client(user=user, mail=user.email, first_name=data['first_name'], last_name=data['last_name'], # age=int(data['age']), gender=data['gender'], phone_number=data['phone_number']) client = form.save() user_client = client.user current_site = get_current_site(request) subject = 'Aceline Services : Confirmation du Compte' message = render_to_string( 'mail/mail_confirmation.html', { 'user': user_client, 'domain': current_site.domain, 'uid': urlsafe_base64_encode(force_bytes(user_client.pk)), 'token': account_activation_token.make_token(user_client), }) user_client.email_user(subject, message) return redirect('account_activation_sent') # login_func(request, client.user) # # return redirect('/') else: form = ClientForm() return render(request, 'client/login-register.html', {"form": form})
def search(request): """ view to display "search.html" i.e. the search interface or form """ client_form = ClientForm() order_form = OrderForm() add_constraints = AddConstraints() temp = { 'client_form': client_form, 'order_form': order_form, 'add_constraints': add_constraints } return render(request, 'reports/search.html', temp)
def index(request): if request.POST: form=ClientForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect('/') else: form=ClientForm() return render(request,'intro/index.html',{'form':form})
def loan_req(request,slug): context=RequestContext(request) created = False cli = "" idclient = "" birthdate = "" loanpurpose = "" loanamount = "" loanperiod = "" risk = "" status = "" to_url = 'pymes/loan_req.html' if request.method == 'POST': idpyme=int(slug) form=ClientForm(data=request.POST, idpyme=idpyme) if form.is_valid(): rate_dict = get_rates(int(slug)) cat_dict = id_cats(int(slug)) clidata = form.save(idpyme, cat_dict, rate_dict) client1 = client() client1.save(clidata) created = True clinum = request.POST['idclient'] cli = load_cli_info(clinum) idclient = clidata['_id'] birthdate = clidata['birthdate'] loanpurpose = clidata['loanpurpose'] loanamount = clidata['loanamount'] loanperiod = clidata['loanperiod'] risk = clidata['risk'] status = clidata['status'] to_url = 'pymes/client_details.html' else: cat_choices = get_cats(int(slug)) rate_dict = get_rates(int(slug)) form = ClientForm(idpyme=int(slug),custom_choices= cat_choices) to_url = 'pymes/loan_req.html' return render_to_response(to_url, {'form': form, 'created': created, 'idclient': idclient, 'birthdate': birthdate, 'loanpurpose': loanpurpose, 'loanamount': loanamount, 'loanperiod': loanperiod, 'risk': risk, 'status': status}, context)
def update_client(request, client_id, template_name='clients/client_form.html'): client = get_object_or_404(Client, pk=client_id) referrer = request.META.get('HTTP_REFERER', '').strip(' ?') if request.method == 'POST': client_form = ClientForm(request.POST, instance=client) filepath_formset = UpdateFilePathFormSet(request.POST, prefix='filepaths') if all([client_form.is_valid(), filepath_formset.is_valid()]): [j.delete() for j in client.filepaths.all()] client = client_form.save() client.save() for form in filepath_formset.forms: filepath = form.save(commit=False) filepath.client = client filepath.save() messages.success(request, 'Client updated successfully.') return HttpResponseRedirect(client.get_absolute_url()) else: client_form = ClientForm(instance=client) filepaths = client.filepaths.all() filepaths_data = [{'path': j.path} for j in filepaths] filepath_formset = UpdateFilePathFormSet(initial=filepaths_data, prefix='filepaths') if referrer.endswith(client.get_absolute_url()): back_link = client.get_absolute_url() else: back_link = reverse('clients_client_list') data = { 'client': client, 'client_form': client_form, 'filepath_formset': filepath_formset, 'back_link': back_link, } return render_to_response(template_name, data, context_instance=RequestContext(request))
def create_client(request, template_name='clients/client_form.html'): if request.method == 'POST': client_form = ClientForm(request.POST) filepath_formset = FilePathFormSet(request.POST, prefix='filepaths') if all([client_form.is_valid(), filepath_formset.is_valid()]): client = client_form.save() for form in filepath_formset.forms: filepath = form.save(commit=False) filepath.client = client filepath.save() messages.success(request, 'Client created successfully.') return HttpResponseRedirect(client.get_absolute_url()) else: client_form = ClientForm() filepath_formset = FilePathFormSet(prefix='filepaths') data = { 'client_form': client_form, 'filepath_formset': filepath_formset, 'back_link': reverse('clients_client_list'), } return render_to_response(template_name, data, context_instance=RequestContext(request))
def loan_req(request,slug): context=RequestContext(request) created = False cli = "" to_url = 'pymes/loan_req.html' if request.method == 'POST': idpyme=int(slug) form=ClientForm(data=request.POST, idpyme=idpyme) if form.is_valid(): rate_dict = get_rates(int(slug)) cat_dict = id_cats(int(slug)) client = form.save(idpyme, cat_dict, rate_dict) client.save() created = True clinum = request.POST['idclient'] cli = load_cli_info(clinum) to_url = 'pymes/client_details.html' else: cat_choices = get_cats(int(slug)) rate_dict = get_rates(int(slug)) form = ClientForm(idpyme=int(slug),custom_choices= cat_choices) to_url = 'pymes/loan_req.html' return render_to_response(to_url, {'form': form, 'created': created, 'data': cli,}, context)
def upload(): form=ClientForm() if request.method == 'GET': return render_template('index.html', form=form) if request.method=='POST': file = request.files['filename'] if file : filename=secure_filename(form.filename.data.filename) print form.filename.data.filename file.save('uploads/'+filename) send_file(filename) return render_template('index.html', form=form)
def post(self, request, ct="client", resource_id=None): """ Save the form and create relevant records """ client = Client() if resource_id: if ct == "prospection": try: client = Client.objects.get(prospection__pk=int(resource_id)) except Client.DoesNotExist: client = Client(prospection=Prospection.objects.get(pk=int(resource_id))) else: client = Client.objects.get(pk=int(resource_id)) client_form = ClientForm(request.POST, request.FILES, instance=client) if client_form.is_valid(): created_client = client_form.save() print created_client.pk created_client.prospection.status = u"Apartado" inline_formset = ClientPaymentFormSet(request.POST, request.FILES, instance=created_client) if inline_formset.is_valid(): inline_formset.save() return redirect("client_home") else: inline_formset = ClientPaymentFormSet(request.POST, request.FILES, instance=client) return self.render_to_response({ 'form': client_form, 'formset': inline_formset, 'client': client, })
def client(): global context form = ClientForm() response = "" duration = "" durations = [] stats = "" url = "" if form.is_submitted(): start = time.time() if form.get_button.data: # print("GET:", form.get_button.data) if form.num_requests.data == 1: response = client_get(get_start_port(), CLIENT_ID, key=form.key.data) context = response.items[0].context duration = str((time.time()-start) * 1000) else: requests = [client_get]*form.num_requests.data requests_params = [{'port': get_start_port(), 'client_id': CLIENT_ID, 'key': form.key.data} for _ in range(form.num_requests.data)] durations, responses = run_parallel(requests, requests_params, start_port=START_PORT) duration = sum(durations)*1000 stats = str(get_stats(durations)) url = generate_plot(durations, 'GET', form.clear.data) else: # print("PUT:", form.put_button.data) if form.num_requests.data == 1: response = client_put(get_start_port(), CLIENT_ID, key=form.key.data, val=form.val.data, context=context) duration = str((time.time()-start) * 1000) else: requests = [client_put]*form.num_requests.data requests_params = [{'port': get_start_port(), 'client_id': CLIENT_ID, 'key': form.key.data, 'val': form.val.data} for _ in range(form.num_requests.data)] durations, responses = run_parallel(requests, requests_params, start_port=START_PORT) duration = sum(durations)*1000 stats = str(get_stats(durations)) url = generate_plot(durations, 'PUT', form.clear.data) return render_template('client.html', server_name=session['server_name'], form=form, response=str(response), duration=duration, stats=stats, url=url)
def add_edit_client(request, client_id=None): """ Method is used to create or edit some existing client. When new client is created notification email is sended on current logged user email. :param client_id: ID of the client, which is edited :type client_id: Integer """ template_name = 'settings/clients/add_edit_client.html' from_email = settings.EMAIL_HOST to_email = request.user.email text = { 'created_email_body': _("New client has been successfully created on {0}. To authorize it \ use this generated key {1} ."), 'created_email_subject': _("New client has been successfully created"), 'created': _("Client '{0}' with id={1} has been created"), 'created_log': _("Email after creation sended for client '{0}' with id={1}"), 'created_success': _('Additional info were sended on email'), 'edited': "Client '{0}' with id={1} has been edited" } if client_id: client = get_object_or_404(Client, pk=client_id) else: client = Client() client.key = get_random_string(length=32) if request.POST: client_form = ClientForm(request.POST, instance=client) if client_form.is_valid(): client_form.save() if not client_id: log.info(text['created'].format(client.name, client.id)) if from_email and to_email: send_mail( text['created_email_subject'], text['created_email_body'].format( settings.DOMAIN_NAME, client.key), from_email, [to_email]) log.info(text['created_log'].format( client.name, client.id)) else: log.info(text['edited'].format(client.name, client.id)) messages.add_message(request, messages.SUCCESS, text['created_success']) return HttpResponseRedirect(reverse('settings:clients_list'), {'messages': messages}) else: client_form = ClientForm(instance=client) return TemplateResponse( request, template_name, { 'client_form': client_form, 'client_id': client_id if client_id else None, 'client': client if client_id else None, 'moduls': client.moduls() if client_id else None })
def index(): form = ClientForm(request.form) username = session.get('username', None) user = users.get(username, None) return render_template('index.html', user=user, username=username, form=form)
def create_form_client(request): try: return ClientForm(request.POST or None, instance=request.user.client) except: return ClientForm(request.POST or None)
) mail = Mail(app) app.config['FLASKY_MAIL_SUBJECT_PREFIX'] = '[Test]' app.config['FLASKY_MAIL_SENDER'] = 'Flasky Admin <*****@*****.**>' from models import db, Client from forms import ClientForm, recipientEmail @app.route('/', methods=['POST','GET']) def home(): session['client_data'] = "" form = ClientForm(request.form) if request.method == 'POST' and form.validate(): newClient = Client(firstName=form.firstName.data, lastName=form.lastName.data, dob=form.dob.data, address=form.address.data, city=form.city.data, zipcode=form.zipcode.data, telephone=form.telephone.data, safeNumber=form.safeNumber.data, language=form.language.data, income=form.income.data, incomeSource=form.incomeSource.data, dependents=form.dependents.data, health=form.health.data, military=form.military.data,