Guest User

Untitled

a guest
Mar 15th, 2016
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.11 KB | None | 0 0
  1. from django.views.decorators.csrf import csrf_exempt
  2.  
  3. from sendfast.models import *
  4. from sendfast.common import constants, utils, pStrings, cachekeys, commonRestaurantFunctions
  5. from django.core.cache import cache
  6. import binascii
  7.  
  8. import logging
  9.  
  10. logger = logging.getLogger(__name__) #not sure what this does
  11.  
  12. @csrf_exempt
  13. def signup(request):
  14.     if request.method == pStrings.POST_METHOD:
  15.         restaurant_name = request.POST.get(pStrings.RESTAURANT_NAME, None)  #DECLARE NEW PSTRING RESTAURANT_NAME
  16.         restaurant_owner_name = request.POST.get(pStrings.RESTAURANT_OWNER_NAME, None) #DECLARE NEW PSTRING RESTAURANT_OWNER__NAME
  17.         restaurant_address = request.POST.get(pStrings.RESTAURANT_ADDRESS, None) #DECLARE NEW PSTRING RESTAURANT_ADDRESS
  18.         #resturant_hub_id = request.POST.get(pStrings.RESTAURANT_HUB_ID, None) #DECLARE NEW PSTRING RESTAURANT_HUB_ID
  19.         #It would be a good idea if latitude , longitude are set null and blank = True
  20.         #set all other as null =True in model
  21.         restaurant_email_id = request.POST.get(pStrings.RESTAURANT_EMAIL_ID, None)#DECLARE
  22.         restaurant_phone_no = request.POST.get(pStrings.RESTAURANT_PHONE_NO, None)#DECLARE
  23.         restaurant_username = request.POST.get(pStrings.RESTAURANT_USERNAME, None)#DECLARE
  24.         password = request.POST.get(pStrings.PASSWORD, None)
  25.         if restaurant_name is not None and restaurant_owner_name is not None and restaurant_address is not None  \
  26.         and restaurant_email_id is not None and restaurant_phone_no is not None and restaurant_hub_id is not None :
  27.             created = create_new_restaurant(restaurant_name=restaurant_name,restaurant_owner_name=restaurant_owner_name,
  28.                                         restaurant_address=restaurant_address,restaurant_email_id=restaurant_email_id
  29.                                         restaurant_phone_no=restaurant_phone_no)
  30.             if created:
  31.                 new_restaurant = Restaurant_static_data.get(restaurant_name=restaurant_name,restaurant_owner_name=restaurant_owner_name)
  32.                 new_restaurant_id = new_restaurant.restaurant_id
  33.                 create_login_details(restaurant_id = new_restaurant_id, restaurant_username=restaurant_username, password = password)
  34.                 if mobile_number_verified:
  35.                     return set_mobile_verified(new_restaurant_id)
  36.                 else:
  37.                     pass
  38.                     #depends on the code of mobile_number_verified
  39.  
  40.                 # Return appropiate response
  41.  
  42.             else:
  43.                 return utils.json_error_response(constants.INVALID_SIGNUP_DETAILS,
  44.                                                  constants.ERROR_STATUS_400)        #DECLARE CONSTANT INVALID_SIGNUP_DEATIALS
  45.         else:
  46.             return utils.json_error_response(constants.INVALID_DATA, constants.ERROR_STATUS_400)
  47.     else:
  48.         return utils.json_error_response(constants.INVALID_METHOD, constants.ERROR_STATUS_405)
  49.  
  50.  
  51.  
  52.  
  53. def create_new_restaurant(restaurant_name,restaurant_owner_name,restaurant_email_id,
  54.                          restaurant_address,restaurant_phone_no, restaurant_hub_id):
  55.     try:
  56.         Restaurant_static_data.objects.create(restaurant_name=restaurant_name,restaurant_owner_name=restaurant_owner_name,
  57.                                         restaurant_address=restaurant_address,restaurant_email_id=restaurant_email_id
  58.                                         restaurant_phone_no=restaurant_phone_no,restaurant_hub_id=restaurant_hub_id)
  59.        
  60.         return True
  61.     except:
  62.         return False
  63.  
  64.  
  65. def create_login_details(restaurant_id, restaurant_username, password):
  66.     try:
  67.         Restaurant_login_details.objects.create(restaurant_id = restaurant_id,
  68.                                         restaurant_username=restaurant_name,
  69.                                         password = password,is_restaurant_logged_in = True)
  70.  
  71.  
  72.  
  73. def mobile_number_verified():
  74.     pass
  75.     #code for gupshup service goes here
  76.  
  77. def set_mobile_verified(restaurant_id):
  78.     try:
  79.         restaurant = Restaurant_static_data.objects.get(restaurant_id=new_restaurant_id)
  80.         restaurant.mobile_verified = True
Add Comment
Please, Sign In to add comment