def hospital_register(request): username = request.POST.get('username') password = request.POST.get('password') name = request.POST.get('name') state = request.POST.get('state') city = request.POST.get('city') address = request.POST.get('address') contact = request.POST.get('contact') latitude = request.POST.get('latitude') longitude = request.POST.get('longitude') hospital = get_or_none(User, username=username) assert_true(hospital != None, "Account with this username already exists") hospital_user_obj = User.objects.create_user(username=username, password=password) hospital_user_obj.save() hospital_obj = Hospital.objects.create(username=hospital_user_obj, name=name, state=state, city=city, address=address, contact=contact) hospital_obj.save() for a, b in BLOOD_GROUP: blood_bank_obj = BloodBankStock.objects.create(hospital=hospital_obj, blood_group=b) blood_bank_obj.save() response = {} response['success'] = False reponse['data'] = get_model_json(hospital_obj) return respond(reponse)
def user_register(request): username = request.POST.get('username') password = request.POST.get('password') first_name = request.POST.get('first_name') last_name = request.POST.get('last_name') state = request.POST.get('state') city = request.POST.get('city') address = request.POST.get('address') contact = request.POST.get('contact') weight = request.POST.get('weight') gender = request.POST.get('gender') user = get_or_none(User, username=username) assert_true(user != None, "Account with this username already exists") user_obj = User.objects.create_user(username=username, password=password) user_obj.save() user_detail_obj = UserDetail.objects.create(username=user_obj, first_name=first_name, last_name=last_name, state=state, city=city, address=address, contact=contact, weight=weight, gender=gender) user_detail_obj.save() response = {} response['success'] = False reponse['data'] = get_model_json(user_detail_obj) return respond(reponse)
def upload_product(request): data = json.loads(request.body) token = request.META.get('token') user = get_user(token) merchant_obj = get_or_none(Merchant, user__user=user) assert_found(merchant_obj, "No merchant object found") name = data['name'] product_type = data['product_type'] price = data['price'] quantity = data['quantity'] quantity_type = data['quantity_type'] # image = request.FILES.get('product_image') product_obj = Product.objects.create(merchant=merchant_obj, name=name, product_type=product_type, price=price, quantity=quantity, quantity_type=quantity_type) product_obj.save() response = {} response['success'] = True response['message'] = "Product uploaded successfully" response['details'] = get_model_json(product_obj) return respond(response)
def donor_list(request): donors = Donor.objects.all() donors_list = [] for obj in donors: temp = get_model_json(obj) donor_list.append(temp) response = {} respond['success'] = True response['data'] = donors_list return respond(reponse)
def register_merchant(request): data = json.loads(request.body) token = request.META.get("token") user = get_user(token) name = data['name'] email = data['email'] address = data['address'] contact = data['contact'] user_detail_object = get_or_none(UserDetail, user = user) assert_found(user_detail_object, "No user detail object found") merchant_obj = Merchant.objects.create(user = user_detail_object, name = name, email = email, address = address, contact = contact) merchant_obj.save() response = {} response['success'] = True response['message'] = "Merchant created successfully" response['details'] = get_model_json(merchant_obj) return respond(response)
def generate_token(user): data = {'user': get_model_json(user)} return jwt.encode(data, settings.SECRET_KEY, algorithm='HS256').decode('utf-8')
def generate_token(user): data = {'user': get_model_json(user)} return jwt.encode(data, SECRET_KEY, algorithm='HS256')