Guest User

Untitled

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