def active_account(self): self.is_suspended = False self.save() self.send_mail(subject='Account Activated', message='Your account has been reactivated.\n ') from customer.utils_db import send_notification send_notification(self.id, "Welcome Back, " + self.username)
def send_notification_to_admin(message): admins = User.objects.filter(is_superuser=True) if not admins.exists(): return for admin in admins: from customer.utils_db import send_notification send_notification(admin.id, message)
def acceptOrder(request): order_id = request.POST.get('order_id') order = Order.objects.get(id=order_id) order.order_status = order.PROCESSING order.save() from customer.utils_db import send_notification send_notification(order.user.id, "Your order:" + str( order.id) + " from " + order.branch.branch_name + " has been confirmed and pending for delivery.") send_to_close_deliverymen(order) return JsonResponse({'order': 'placed'})
def send_to_close_deliverymen(order): branch = order.branch from accounts.models import DeliveryMan deliverymen = DeliveryMan.objects.filter(address=branch.location_area, user__is_suspended=False) if deliverymen.exists(): for deliveryman in deliverymen: from customer.utils_db import send_notification send_notification( deliveryman.user.id, "A new order with id: " + str(order.id) + " arrived for delivery from " + branch.branch_name)
def suspend_account(self): self.is_suspended = True self.save() self.send_mail( subject='Account Deactivated', message='Your account has been deactivated for bad reputation.\n ' + 'We are verifying your account.\n ' + 'You will be mailed via this email when we are done.') from customer.utils_db import send_notification if self.is_customer: send_notification( self.id, "Your account has been suspended due to lower rating. You cannot order any items until you contact us." ) elif self.is_delivery_man: send_notification( self.id, "Your account has been suspended due to lower rating. You cannot accept any delivery until you contact us" )
def offerSubmit(request): from customer.utils_db import send_notification id = request.POST.get('id') discount = request.POST.get('discount_amnt') buy_amnt = request.POST.get('buy_amnt') get_amnt = request.POST.get('get_amnt') offer_type = request.POST.get('offer_type') start_date = request.POST.get('start_date') end_date = request.POST.get('end_date') print(start_date, ' ', end_date) if offer_type == 'buy_get': offer_type = 'B' elif offer_type == 'discount': offer_type = 'D' elif offer_type == 'none': offer_type = 'N' if offer_type == PackageBranchDetails.DISCOUNT: update_offer_branch(request.user, id, offer_type, start_date, end_date, discount_val=discount) branch_pkg = PackageBranchDetails.objects.get(id=id) send_notification(branch_pkg.package.restaurant.user.id, branch_pkg.branch.branch_name + " added " + branch_pkg.get_offer_details() + " on " + branch_pkg.package.pkg_name) elif offer_type == PackageBranchDetails.BUY_N_GET_N: update_offer_branch(request.user, id, offer_type, start_date, end_date, buy_n=buy_amnt, get_n=get_amnt) branch_pkg = PackageBranchDetails.objects.get(id=id) send_notification(branch_pkg.package.restaurant.user.id, branch_pkg.branch.branch_name + " added " + branch_pkg.get_offer_details() + " on " + branch_pkg.package.pkg_name) elif offer_type == PackageBranchDetails.NONE: update_offer_branch(request.user, id, offer_type, start_date, end_date) branch_pkg = PackageBranchDetails.objects.get(id=id) send_notification(branch_pkg.package.restaurant.user.id, branch_pkg.branch.branch_name + " cleared offers" + " on " + branch_pkg.package.pkg_name) return JsonResponse({'updated': True})
def acceptDelivery(request): print(request) order_id = request.POST.get('order_id') deliveryman = DeliveryMan.objects.get(user=request.user) print(order_id) print(deliveryman) if order_id is None: return JsonResponse({"accepted": False}) status = request.POST.get('delivery_option') order = Order.objects.get(id=order_id) if status == 'take': if order.order_status != Order.PROCESSING: return JsonResponse({"accepted": False}) order.assignDeliveryman(deliveryman) from customer.utils_db import send_notification send_notification( order.user.id, "Your order: " + str(order.id) + " from " + order.branch.branch_name + " has been proceeded to deliver.\n" "Wait for deliveryman to reach at your delivery address.") send_notification( request.user.id, "You accepted delivery for order id:" + str(order.id) + " to deliver to " + order.user.username) elif status == 'deliver': order.submitDelivery() from customer.utils_db import send_notification send_notification( order.user.id, "Your order: " + str(order.id) + " from " + order.branch.branch_name + " was delivered to your delivery address.") send_notification( request.user.id, "You delivered order id:" + str(order.id) + " to " + order.user.username) return JsonResponse({"accepted": True})
def post(self, request, *args, **kwargs): """PackageID is id of PackageBranchDetails""" print(pretty_request(request)) if not (self.request.user.is_authenticated and self.request.user.is_customer): return pkg_list = json.loads(request.POST.get('item-list'))['pkg-list'] houseNo = request.POST.get('house-no') roadNo = request.POST.get('road-no') blockNo = request.POST.get('block-no') apartmentNo = request.POST.get('apartment-no') area = request.POST.get('area') mobileNo = request.POST.get('mobile-no') branchID = request.POST.get('branch-id') # location = request.POST.get('delivery-location') branch = RestaurantBranch.objects.get(id=branchID) delivery = Delivery.objects.create(address=area, address_desc=apartmentNo + ', ' + houseNo + ', ' + roadNo + ', ' + blockNo) total_price = 0 for pkg in pkg_list: total_price += pkg['price'] from webAdmin import utils total_price += utils.get_delivery_charge(total_price) payment = None ref = None if request.POST.get('bkash_payment') is not None: print('success') ref = getUniqueBkashRef(12) payment = Payment.objects.create(price=total_price, payment_type=Payment.ONLINE, bkash_ref=ref, payment_status=Payment.DUE) else: print('cash') payment = Payment.objects.create(price=total_price, payment_type=Payment.CASH, payment_status=Payment.DUE) from django.utils.timezone import datetime time = datetime.now() order = Order.objects.create(user=self.request.user, mobileNo=mobileNo, delivery=delivery, branch=branch, payment=payment, time=time) for pkg in pkg_list: package = PackageBranchDetails.objects.get(id=pkg['id']).package OrderPackageList.objects.create(order=order, package=package, quantity=int(pkg['quantity']), price=pkg['price']) from customer.utils_db import send_notification send_notification( order.user.id, "Your order: " + str(order.id) + " from " + order.branch.branch_name + " with " + str(len(pkg_list)) + " items has been placed in manager's queue for confirmation.") send_notification( order.branch.user.id, "You have a new order with id: " + str(order.id) + ' of ' + str(len(pkg_list)) + ' items') if request.POST.get('bkash_payment') is not None: return redirect( reverse('browse:bkashPayment') + '?ref-no=' + order.payment.bkash_ref) else: return redirect("/")
def post(self, request, *args, **kwargs): print(pretty_request(request)) if request.POST.get('password') != request.POST.get('re_pass'): return render(request, 'accounts/message_page.html', { 'header': "Error !", 'details': ' Invalid Password' }) # -------------------------------------------------- user_form = UserForm(request.POST) if not user_form.is_valid(): return render(request, 'accounts/message_page.html', { 'header': "Error !", 'details': ' Invalid Form or pass' }) if not Restaurant.objects.filter( restaurant_key=request.POST['rest_key']).exists(): return render(request, 'accounts/message_page.html', { 'header': "Error !", 'details': ' Not Valid secret key' }) if request.POST['lat'] is None or request.POST['lon'] is None: return render(request, 'accounts/message_page.html', { 'header': "Error !", 'details': ' No Location Provided' }) branch = RestaurantBranch() branch.branch_name = request.POST['branch_name'] branch.restaurant = Restaurant.objects.get( restaurant_key=request.POST['rest_key']) branch.branch_location = request.POST['lat'] + ',' + request.POST['lon'] if request.POST.get('extra_details') is not None: branch.branch_location_details = request.POST.get('extra_details') try: branch.location_area = geolocator.reverse( branch.branch_location, language='en').raw['address']['suburb'] except Exception: try: branch.location_area = geolocator.reverse( branch.branch_location, language='en').raw['address']['neighbourhood'] except Exception: print("Location NOT Reversed") user = user_form.save(commit=False) user.is_branch_manager = True user.save() branch.user = user branch.save() login(request, user) from customer.utils_db import send_notification send_notification( branch.restaurant.user.id, branch.branch_name + " was added under your restaurant") print(branch) from browse.models import Package for package in Package.objects.filter(restaurant=branch.restaurant): from browse.models import PackageBranchDetails PackageBranchDetails.add_package_to_all_branches( package.restaurant, package) return redirect('/homepage')