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.82 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 :
  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.                 if email_id_verified:
  41.                     return set_email_id_verified(new_restaurant_id)
  42.                 else:
  43.                     pass
  44.                
  45.                 if mobile_number_verified and email_id_verified:
  46.                     restaurant = Restaurant_static_data.objects.get(restaurant_id=new_restaurant_id)
  47.                     restaurant.restaurant_is_Active = True
  48.  
  49.                 # Return appropiate response
  50.  
  51.             else:
  52.                 return utils.json_error_response(constants.INVALID_SIGNUP_DETAILS,
  53.                                                  constants.ERROR_STATUS_400)        #DECLARE CONSTANT INVALID_SIGNUP_DEATIALS
  54.         else:
  55.             return utils.json_error_response(constants.INVALID_DATA, constants.ERROR_STATUS_400)
  56.     else:
  57.         return utils.json_error_response(constants.INVALID_METHOD, constants.ERROR_STATUS_405)
  58.  
  59.  
  60.  
  61.  
  62. def create_new_restaurant(restaurant_name,restaurant_owner_name,restaurant_email_id,
  63.                          restaurant_address,restaurant_phone_no, restaurant_hub_id):
  64.     try:
  65.         Restaurant_static_data.objects.create(restaurant_name=restaurant_name,restaurant_owner_name=restaurant_owner_name,
  66.                                         restaurant_address=restaurant_address,restaurant_email_id=restaurant_email_id
  67.                                         restaurant_phone_no=restaurant_phone_no,restaurant_hub_id=restaurant_hub_id)
  68.        
  69.         return True
  70.     except:
  71.         return False
  72.  
  73.  
  74. def create_login_details(restaurant_id, restaurant_username, password):
  75.     try:
  76.         Restaurant_login_details.objects.create(restaurant_id = restaurant_id,
  77.                                         restaurant_username=restaurant_name,
  78.                                         password = password,is_restaurant_logged_in = True)
  79.  
  80.  
  81.  
  82. def mobile_number_verified():
  83.     pass
  84.     #code for gupshup service goes here
  85.  
  86. def set_mobile_verified(new_restaurant_id):
  87.     try:
  88.         restaurant = Restaurant_static_data.objects.get(restaurant_id=new_restaurant_id)
  89.         restaurant.mobile_verified = True
  90.         #create restaurant _mobile_verifed in static data
  91.  
  92. def email_id_verified():
  93.     pass
  94.     #Authentiacte using OAuth or whatever
  95.  
  96.  
  97. def set_email_verified(new_restaurant_id):
  98.     try:
  99.         restaurant = Restaurant_static_data.objects.get(restaurant_id=new_restaurant_id)
  100.         restaurant.email_verified = True
  101.  
  102.         #create restaurant _email_verifed in static data
Add Comment
Please, Sign In to add comment