Guest User

Untitled

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