def post(self): args = request.get_json() username = args['username'] email = args['email'] password = args['password'] client = Client(username=username, email=email, password=password) client.save() return jsonify({'message': 'Saved', 'code': '200'})
def create_client(): first_names = ["Gastón", "Juan", "Sebastian", "Pedro", "Julian", "Martin"] last_names = ["Donnet", "Martinez", "Fabro", "Zamora", "Batalla"] punctuation = ["B", "R", "M"] client = Client( name=random.choice(first_names) + " " + random.choice(last_names), total_debt=round(random.random()*100000, 2), punctuation=random.choice(punctuation) ) client.save() return client
def register_view(request): if request.method == "POST": token = str(uuid4()) phone = request.POST['phone'] password = request.POST['password'] password_rep = request.POST['password_rep'] name = request.POST['name'] surname = request.POST['surname'] new_user = User.objects.create_user(username=phone, password=password, first_name=name, last_name=surname) new_client = Client(user=new_user, phone_number=phone, token=token, password=password) new_user.save() new_client.save() login(request=request, user=new_user) return HttpResponseRedirect("../") return render(request, "register.html")
def post(self, request, *args, **kwargs): _uuid = kwargs.get('uuid') _json_body = self.get_json() _created, _client = Client.register(_uuid, **_json_body) print(_created, _client) return self.response({'created': _created, 'client': _client.as_dict()})
def new_client(request): number = int(random.random() * 1000000) while Client.objects.filter(uuid=number).exists(): number = int(random.random() * 1000000) Client(uuid=number, associate_id='245092').save() EmploymentEducation(personal_id=number, associate_id='245092').save() HealthAndDV(personal_id=number, associate_id='245092').save() return JsonResponse({'status': 'success', 'id': number})
def add_client(request): """ @params: None @return: {id, societe} @desc: Add client to database """ email = request.data['email'] if Client.objects.filter(email=email).exists(): return Response({'error': 'Cet email existe déjà'}) societe = request.data['societe'] date = request.data['date_reglement'].split('-') date_reglement = datetime(int(date[0]), int(date[1]), int(date[2])) periodicite = request.data['periodicite'] montant = int(request.data['montant']) mode_de_reglement = request.data['mode_de_reglement'] statut = request.data['statut'] statut_client = request.data['statut_client'] product_id = request.data['product'] plan_id = request.data['plan'] client = Client(societe=societe, email=email, date_reglement=date_reglement, periodicite=periodicite, montant=montant, mode_de_reglement=mode_de_reglement, statut=statut, statut_client=statut_client, product_id=product_id, plan_id=plan_id) client.password = make_password(societe) client.save() send_url_to_client( generate_client_url(client.societe, client.id, client.token), client.email, client.societe) return Response({ 'id': client.id, 'societe': client.societe, 'error': False })
def post(self, request): serializer = self.serializer(data=request.data) if not serializer.is_valid(): return Response(status=status.HTTP_400_BAD_REQUEST) username = serializer.data.get('username') password = make_password(serializer.data.get('password')) user = self.model.objects.create( username=username, password=password, first_name="Ім'я не вказано", last_name="Прізвище не вказано", ) client = Client() client.user = user client.save() return Response(ClientSerializer(client).data, status.HTTP_200_OK)
def test_api_client_get(app, dbsession): client = Client( id=1, name='Mieszko', ip_address='1.1.1.1', ) dbsession.add(client) response = app.get('/api/client') assert response.json() == { 'num_results': 0, 'objects': [], 'page': 1, 'total_pages': 0 }
def createContactForClient(client: Client) -> Client: contact = { "ContactStatus": "ACTIVE", "Name": client.name, "IsCustomer": True, # IsCustomer and IsSupplier is ignored but atleast we show intention "IsSupplier": False, "DefaultCurrency": "AUD" } if checkCanCreate(): xero = connectToXero() newContact = xero.contacts.put(contact) print(newContact) client.xero_customer = newContact[0].get("ContactID") client.save() return client else: return None
def create(self, client, order): if not client: name = None if self.data.source == 'facebook': facebook_user = FacebookService.get_user_info( self.data.sender_id) if facebook_user['first_name'] and facebook_user['last_name']: name = facebook_user['first_name'] + " " + facebook_user[ 'last_name'] client = Client(token=self.data.sender_id, source=self.data.source, name=name) client.save() if order: # TODO ask to client if he wants to clear items pass else: order = Order(client=client) order.save() return None
def sync_client(): with open('sample_data/client.csv') as csvfile: reader = csv.DictReader(csvfile) bulk_create = [] fmt_date = lambda k: parse(k).date() if k else datetime.date.today() fmt_datetime = lambda k: parse(k) if k else datetime.datetime.now() cast_int = lambda k: int(k) if k else None ethnicity_funct = lambda k: [name for name in ethnicity.keys() if int(k[name])] war_participated_funct = lambda k: [war_participated[name] for name in war_participated.keys() if int(k[name])] for row in reader: for key in row: if row[key] == 'NULL' or row[key] == '': row[key] = None csv2db_client = { "uuid": row["UUID"], "first_name": row["First_Name"], "middle_name": row["Middle_Name"], "last_name": row["Last_Name"], "social_security": row["SSN"], "date_of_birth": fmt_date(row["DOB"]), "gender": cast_int(row["Gender"]), "veteran": cast_int(row["VeteranStatus"]), "year_entered": cast_int(row["YearEnteredService"]), "year_exited": cast_int(row["YearSeparated"]), "military_branch": cast_int(row["MilitaryBranch"]), "discharge_status": row["Discharge_Status"], "date_created": fmt_datetime(row["Date_Created"]), "date_updated": fmt_datetime(row["DateUpdated"]), "associate_id": row["UserID"], "ethnicity": ethnicity[ethnicity_funct(row)[0]], "war_participated": war_participated_funct(row) } bulk_create.append(Client(**csv2db_client)) Client.objects.all().delete() Client.objects.bulk_create(bulk_create)
def form_valid(self, form): import uuid client = Client(id=uuid.uuid4()) client.is_staff = form.cleaned_data['is_staff'] client.is_bot = form.cleaned_data['is_bot'] profile = Contact.objects.create( contact_id=0, contact_key='profile', display_name=form.cleaned_data['display_name']) profile_raw = profile.raw_contacts.create( contact_type='com.android.profile', contact_name='Profile') profile_raw.data.create(type='NAME', value=form.cleaned_data['display_name']) profile_raw.data.create(type='PHONE', value=form.cleaned_data['phone_number']) client.profile = profile client.save() return super().form_valid(form)
def register_user(): username = request.json.get("username", None) fullname = request.json.get("name", None) email = request.json.get("email", None) password = request.json.get("password", None) phonenumber = request.json.get("phonenumber", None) usertype = request.json.get("usertype", None) if not username: return jsonify({"msg": "Please provide a valid username."}), 400 if not fullname: return jsonify({"msg": "Please provide a valid full name."}), 400 if not email: return jsonify({"msg": "Please provide a valid email."}), 400 if not password: return jsonify({"msg": "Please provide a valid password."}), 400 if not phonenumber: return jsonify({"msg": "Please provide a valid phone number."}), 400 if usertype == 1: client = Client.query.filter_by(username=username, password=password, isSeller=usertype).first() if client: return jsonify({"msg": "Seller already exists."}), 401 else: new_seller = Client() new_seller.username = username new_seller.fullName = fullname new_seller.email = email new_seller.password = password new_seller.phoneNumber = phonenumber new_seller.isSeller = usertype db.session.add(new_seller) db.session.commit() return jsonify({"msg": "Seller account was successfully created."}), 200 else: client = Client.query.filter_by(username=username, password=password, isSeller=usertype).first() if client: return jsonify({"msg": "Client already exists."}), 401 else: new_client = Client() new_client.username = username new_client.fullName = fullname new_client.email = email new_client.password = password new_client.phoneNumber = phonenumber new_client.isSeller = usertype db.session.add(new_client) db.session.commit() return jsonify({"msg": "Client account was successfully created."}), 200
def post(self, request, *args, **kwargs): _uuid = kwargs.get('uuid') Client.heartbeat(_uuid) return self.response(time.time())