def add_to_org(sender, **kwargs): org = sender.objects.last() user = org.creator member, created = OrganisationMember.objects.get_or_create( org=org, member=user) if created: tld = tldextract.extract(org.url) client = Client() client.name = org.name client.organisation = org client.schema_name = org.slug client.paid_until = datetime.now() + timedelta(days=90) try: client.domain_url = tld.domain client.save() except KeyError: try: client.domain_url = tld.domain + '-' + tld.subdomain client.save() except KeyError: client.domain_url = org.slug client.save()
def add_to_org(sender, **kwargs): org = sender.objects.last() user = org.creator member, created = OrganisationMember.objects.get_or_create(org=org, member=user) if created: tld = tldextract.extract(org.url) client = Client() client.name = org.name client.organisation = org client.schema_name = org.slug client.paid_until = datetime.now() + timedelta(days=90) try: client.domain_url = tld.domain client.save() except KeyError: try: client.domain_url = tld.domain + '-' + tld.subdomain client.save() except KeyError: client.domain_url = org.slug client.save()
def client(): form = ClientForm() client = Client() if form.validate_on_submit(): client.service_to_client = Service.query.filter_by(name=form.service.data).first() client.name = form.username.data.strip() client.tel = form.phone.data.strip() client.metro, client.exit_num = form.station.data.split('(') client.metro = client.metro.strip() if client.exit_num: client.exit_num = client.exit_num.replace(')', '').strip() client.info = form.about.data client.cost = form.cost.data db.session.add(client) db.session.commit() return redirect(url_for('client')) return render_template('client.html', form=form, service_data=Service.query.all())
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)
def test_db_add_client(self): client = Client() client.name = 'Test Client' self.db.session.add(client)