def RandomClient(faker): client = Client() sex = 'male' active = True if random.randrange(1,2) == 1: sex = 'female' if random.randrange(1,10) == 1: active = False profile = faker.profile(fields=['username','password','mail','address'],sex=sex) client.username = profile['username'] client.email = profile['mail'] client.password = faker.md5(raw_output=False) client.active = active client.created = faker.date_object() client.save()
def add_client(self, request: HttpRequest) -> json: data = get_request_param_json('data', request) client_id = int(data.get('client_id', '')) client_service = self.factory.get_service('client') client = Client() if client_id: client = client_service.get_client(client_id) client.name = data.get('client_name', '') client.mobile_no = data.get('client_mobile', '') client.email = data.get('client_email', '') client.property = { 'address': data.get('client_address', ''), 'country': data.get('client_country', ''), 'country_code': data.get('client_country_code', ''), 'zip_code': data.get('client_zip_code', ''), 'company_name': data.get('client_c_n', ''), 'company_website': data.get('client_c_w', ''), } client_service.add_update_client(client) return JsonResponse(data, safe=False)
def client(id): client = Client.query.filter_by(id=id).first() form = NewClientForm() if form.validate_on_submit(): client = Client(name=form.name.data, representative_name=form.representative_name.data, phone=form.phone.data, email=form.email.data) client.name = form.name.data client.representative_name = form.representative_name.data client.phone = form.phone.data client.email = form.email.data db.session.commit() flash(_('Client edited!')) return redirect(url_for('main.client', id=id)) elif request.method == 'GET': form.name.data = client.name form.representative_name.data = client.representative_name form.phone.data = client.phone form.email.data = client.email if client is None: flash(_('The client with this id was not found!')) return redirect(url_for('main.clients')) return render_template('client.html', form=form)