def post(self): """A post request to this endpoint takes the base_image and user_image submitted via json and checks the database to ensure a match before issuing a token""" current_user = get_jwt_identity() if current_user is None: response = jsonify({"msg": "unauthenticated"}) return (response.json), 401 if not request.is_json: response = jsonify({"msg": "Missing JSON in request"}) return (response.json), 400 mac_address = request.json.get('mac', None) ip_address = request.json.get('ip', None) status = request.json.get('status', None) version = request.json.get('version', None) if not mac_address: response = jsonify({"msg": "Missing mac parameter"}) return (response.json), 400 query = users.User.query.filter_by(username=current_user).first() cluster = clusters.Cluster(query.uuid, mac_address, ip_address, status, version) db.add(cluster) db.commit() response = jsonify(status=status, id=cluster.uuid) return (response.json), 200
def post(self): if not request.content_type == 'application/json': return response('failed', 'Content-type must be application/json', 401) data = request.get_json() fields = ['bill_number', 'client', 'cashier', 'paid','date', 'amount'] string = '' for i in fields: if not data.get(f'{i}'): string = string+f'\"{i}\", ' if string: return response('Invalid POST Request', f'These fields should be included in the POST Request. {string}', 404) client1 = Clients.query.filter(Clients.id_ == data.get('client')).first() bill = Bills( bill_number=data.get('bill_number'), client=client1, cashier=data.get('cashier'), paid=data.get('paid'), date=data.get('date'), amount=data.get('amount') ) db_session.add(bill) db_session.commit() return response('Added Successfully.', f'Successfully added the Bill with Code {str(bill.bill_number)}', 200, bill_schema.dump(bill))
def import_kb(source_dir, metadata_dir): metadata = { "total_count": None, "sources": [], } source_dir = Path(source_dir) for filename in source_dir.glob("**/*.json"): with open(filename, "r") as f: data = json.load(f) # TODO: Fix source_id = data["metadata"]["source_id"] source_metadata = data["metadata"] metadata["sources"].append(source_metadata) for item in data["collection"]: obj = KnowledgeBase(**item, sources=[source_id]) db_session.add(obj) db_session.commit() metadata["total_count"] = db_session.query(KnowledgeBase.uid).count() with open(Path(metadata_dir).joinpath("./kb_metadata.json"), "w") as f: json.dump(metadata, f, ensure_ascii=False, indent=2)
def post(self): if not request.content_type == 'application/json': return response('failed', 'Content-type must be application/json', 401) data = request.get_json() payment_type1 = Payment_Types.query.filter( Payment_Types.type_name == data.get('payment_types')).first() payment_method1 = Payment_Methods.query.filter( Payment_Methods.method_name == data.get('payment_methods')).first() payment = Payments( amount=data.get('amount'), date=data.get('date'), due_date=data.get('due_date'), paid=False, payment_methods=payment_method1, payment_types=payment_type1 ) db_session.add(payment) db_session.commit() return payment_schema.jsonify(payment)
def post(self): """function for "POST /clients/" endpoint Returns: { "address": "Address 1", "created_at": "2019-09-20T06:07:23.611071", "email": "*****@*****.**", "id_": 1, "name": "Client 1", "telephone": "123456789", "updated_at": null } """ if not request.content_type == 'application/json': return response('failed', 'Content-type must be application/json', 401) data = request.get_json() clients = Clients(name=data.get('name'), address=data.get('address'), telephone=data.get('telephone'), email=data.get('email')) db_session.add(clients) db_session.commit() client = Clients.query.filter(Clients.name == data.get('name')).first() return client_schema.jsonify(client)
def post(self): if not request.content_type == 'application/json': return response('Failed', 'Content-type must be application/json', 401) data = request.get_json() fields = ['item_code', 'name', 'qty', 'retail_price', 'wholesale_price', 'mfd_date', 'exp_date'] string = '' for i in fields: if not data.get(f'{i}'): string = string+f'\"{i}\", ' if string: return response('Invalid POST Request', f'These fields should be included in the POST Request. {string}', 404) item = Items( item_code=data.get('item_code'), name=data.get('name'), qty=data.get('qty'), retail_price=data.get('retail_price'), wholesale_price=data.get('wholesale_price'), mfd_date=data.get('mfd_date'), exp_date=data.get('exp_date') ) db_session.add(item) db_session.commit() return response('Added Successfully.', f'Successfully added the item with Item Code {str(item.item_code)}', 200, item_schema.dump(item))
def post(self): current_user = get_jwt_identity() api_key = create_access_token(identity=current_user, expires_delta=False) api_key_jti = get_jti(encoded_token=api_key) revoked = False query = users.User.query.filter_by(username=current_user).first() db.add(users.Tokens(query.uuid, revoked, api_key_jti)) db.commit() response = jsonify(api_key=api_key) return (response.json), 200
def post(self): if not request.content_type == 'application/json': return response('failed', 'Content-type must be application/json', 401) data = request.get_json() distributors = Distributors(name=data.get('name'), address=data.get('address'), telephone=data.get('telephone'), email=data.get('email')) db_session.add(distributors) db_session.commit() distributor = Distributors.query.filter( Distributors.name == data.get('name')).first() return distributor_schema.jsonify(distributor)
def post(self): """A post request to this method will take the username and password from json and add them to the database. Passwords are salted before being placed into the database""" if not request.is_json: response = jsonify({"msg": "Missing JSON in request"}) return (response.json), 400 username = request.json.get('username', None) password = request.json.get('password', None) role = request.json.get('role', 'member') admin_token = request.headers.get('X-Auth-Token') if not username: response = jsonify({"msg": "Missing username parameter"}) return (response.json), 400 if not password: response = jsonify({"msg": "Missing password parameter"}) return (response.json), 400 if admin_token: if admin_token != ADMIN_TOKEN: response = jsonify({"msg": "invalid admin token"}) return (response.json), 401 elif admin_token == ADMIN_TOKEN: db.add(users.User(username, password, role)) db.commit() response = jsonify(status='registered', username=username) return (response.json), 200 current_user = get_jwt_identity() query = users.User.query.filter_by(username=current_user).first() if query.role == 'admin': db.add(users.User(username, password, role)) db.commit() response = jsonify(status='registered', username=username) return (response.json), 200 response = jsonify({"msg": "admin user account required"}) return (response.json), 400
def insert(self, kwargs): task = AsyncTasks(**kwargs) db_session.add(task) db_session.commit() return task
def insert(self, kwargs): pod = V2Pod(**kwargs) db_session.add(pod) db_session.commit() return pod
def insert(self, kwargs): image = V2Image(**kwargs) db_session.add(image) db_session.commit() return image
def insert(self, kwargs): openrc = V2Openrc(**kwargs) db_session.add(openrc) db_session.commit() return openrc
def insert(self, kwargs): environment = V2Environment(**kwargs) db_session.add(environment) db_session.commit() return environment
def insert(self, kwargs): project = V2Project(**kwargs) db_session.add(project) db_session.commit() return project
def insert(self, kwargs): container = V2Container(**kwargs) db_session.add(container) db_session.commit() return container
def insert(self, kwargs): project = V2Project(**kwargs) db_session.add(project) db_session.commit() return project
def insert(self, kwargs): task = V2Task(**kwargs) db_session.add(task) db_session.commit() return task
def insert(self, kwargs): environment = V2Environment(**kwargs) db_session.add(environment) db_session.commit() return environment
def insert(self, kwargs): openrc = V2Openrc(**kwargs) db_session.add(openrc) db_session.commit() return openrc
def insert(self, kwargs): pod = V2Pod(**kwargs) db_session.add(pod) db_session.commit() return pod
def insert(self, kwargs): image = V2Image(**kwargs) db_session.add(image) db_session.commit() return image
from api.distributors.models import Distributors from api.clients.models import Clients from api.payments.models import Payment_Types, Payment_Methods, Payments from api.bill.models import Bills from api.users.models import User, Role, RolesUsers # When adding object contaning another object, In the first object there should be # backref to second object. For more information see Payment model. # Execute these commands in 'flask shell' item1 = Items(name="Baby Soap") item2 = Items(name="Rice") item3 = Items(name="Sugar") db_session.add(item1) db_session.add(item2) db_session.add(item3) db_session.commit() stock1 = Stock(item=item1, qty=10, retail_price=45, wholesale_price=40, mfd_date=date(2019, 4, 20), exp_date=date(2020, 4, 20)) stock2 = Stock(item=item2, qty=100, retail_price=80, wholesale_price=75, mfd_date=date(2019, 6, 15),
def insert(self, kwargs): container = V2Container(**kwargs) db_session.add(container) db_session.commit() return container