Guest User

signup api2

a guest
Mar 14th, 2016
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.42 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)
  16.         restaurant_owner_name = request.POST.get(pStrings.RESTAURANT_OWNER_NAME, None)
  17.         restaurant_address = request.POST.get(pStrings.RESTAURANT_ADDRESS, None)
  18.         resturant_hub_id = request.POST.get(pStrings.RESTAURANT_HUB_ID, None)
  19.         #It would be a good idea if latitude , longitude are set null and blank = True
  20.         restaurant_email_id = request.POST.get(pStrings.RESTAURANT_EMAIL_ID, None)
  21.         restaurant_phone_no = request.POST.get(pStrings.RESTAURANT_PHONE_NO, None)
  22.         restaurant_username = request.POST.get(pStrings.RESTAURANT_USERNAME, None)
  23.         password = request.POST.get(pStrings.PASSWORD, None)
  24.         if restaurant_name is not None and restaurant_owner_name is not None and restaurant_address is not None  \
  25.         and restaurant_email_id is not None and restaurant_phone_no is not None and restaurant_hub_id is not None :
  26.             created = create_new_restaurant(restaurant_name=restaurant_name,restaurant_owner_name=restaurant_owner_name,
  27.                                         restaurant_address=restaurant_address,restaurant_email_id=restaurant_email_id
  28.                                         restaurant_phone_no=restaurant_phone_no,restaurant_hub_id=restaurant_hub_id)
  29.             if created:
  30.                 new_restaurant = Restaurant_static_data.get(restaurant_name=restaurant_name,restaurant_owner_name=restaurant_owner_name)
  31.                 new_restaurant_id = new_restaurant.restaurant_id
  32.                 create_login_details(restaurant_id = new_restaurant_id, restaurant_username=restaurant_username, password = password)
  33.                 # Return appropiate response
  34.  
  35.             else:
  36.                 return utils.json_error_response(constants.INVALID_SIGNUP_DETAILS,
  37.                                                  constants.ERROR_STATUS_400)
  38.         else:
  39.             return utils.json_error_response(constants.INVALID_DATA, constants.ERROR_STATUS_400)
  40.     else:
  41.         return utils.json_error_response(constants.INVALID_METHOD, constants.ERROR_STATUS_405)
  42.  
  43.  
  44.  
  45.  
  46. def create_new_restaurant(restaurant_name,restaurant_owner_name,restaurant_email_id,
  47.                          restaurant_address,restaurant_phone_no, restaurant_hub_id):
  48.     try:
  49.         Restaurant_static_data.objects.create(restaurant_name=restaurant_name,restaurant_owner_name=restaurant_owner_name,
  50.                                         restaurant_address=restaurant_address,restaurant_email_id=restaurant_email_id
  51.                                         restaurant_phone_no=restaurant_phone_no,restaurant_hub_id=restaurant_hub_id)
  52.        
  53.         return True
  54.     else:
  55.         return False
  56.  
  57.  
  58. def create_login_details(restaurant_id, restaurant_username, password):
  59.     try:
  60.         Restaurant_login_details.objects.create(restaurant_id = restaurant_id,
  61.                                         restaurant_username=restaurant_name,
  62.                                         password = password,is_restaurant_logged_in = True)
Add Comment
Please, Sign In to add comment