Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.views.decorators.csrf import csrf_exempt
- from sendfast.models import *
- from sendfast.common import constants, utils, pStrings, cachekeys, commonRestaurantFunctions
- from django.core.cache import cache
- import binascii
- import logging
- logger = logging.getLogger(__name__) #not sure what this does
- @csrf_exempt
- def signup(request):
- if request.method == pStrings.POST_METHOD:
- restaurant_name = request.POST.get(pStrings.RESTAURANT_NAME, None)
- restaurant_owner_name = request.POST.get(pStrings.RESTAURANT_OWNER_NAME, None)
- restaurant_address = request.POST.get(pStrings.RESTAURANT_ADDRESS, None)
- resturant_hub_id = request.POST.get(pStrings.RESTAURANT_HUB_ID, None)
- #It would be a good idea if latitude , longitude are set null and blank = True
- restaurant_email_id = request.POST.get(pStrings.RESTAURANT_EMAIL_ID, None)
- restaurant_phone_no = request.POST.get(pStrings.RESTAURANT_PHONE_NO, None)
- restaurant_username = request.POST.get(pStrings.RESTAURANT_USERNAME, None)
- password = request.POST.get(pStrings.PASSWORD, None)
- if restaurant_name is not None and restaurant_owner_name is not None and restaurant_address is not None \
- and restaurant_email_id is not None and restaurant_phone_no is not None and restaurant_hub_id is not None :
- created = create_new_restaurant(restaurant_name=restaurant_name,restaurant_owner_name=restaurant_owner_name,
- restaurant_address=restaurant_address,restaurant_email_id=restaurant_email_id
- restaurant_phone_no=restaurant_phone_no,restaurant_hub_id=restaurant_hub_id)
- if created:
- new_restaurant = Restaurant_static_data.get(restaurant_name=restaurant_name,restaurant_owner_name=restaurant_owner_name)
- new_restaurant_id = new_restaurant.restaurant_id
- create_login_details(restaurant_id = new_restaurant_id, restaurant_username=restaurant_username, password = password)
- # Return appropiate response
- else:
- return utils.json_error_response(constants.INVALID_SIGNUP_DETAILS,
- constants.ERROR_STATUS_400)
- else:
- return utils.json_error_response(constants.INVALID_DATA, constants.ERROR_STATUS_400)
- else:
- return utils.json_error_response(constants.INVALID_METHOD, constants.ERROR_STATUS_405)
- def create_new_restaurant(restaurant_name,restaurant_owner_name,restaurant_email_id,
- restaurant_address,restaurant_phone_no, restaurant_hub_id):
- try:
- Restaurant_static_data.objects.create(restaurant_name=restaurant_name,restaurant_owner_name=restaurant_owner_name,
- restaurant_address=restaurant_address,restaurant_email_id=restaurant_email_id
- restaurant_phone_no=restaurant_phone_no,restaurant_hub_id=restaurant_hub_id)
- return True
- else:
- return False
- def create_login_details(restaurant_id, restaurant_username, password):
- try:
- Restaurant_login_details.objects.create(restaurant_id = restaurant_id,
- restaurant_username=restaurant_name,
- password = password,is_restaurant_logged_in = True)
Add Comment
Please, Sign In to add comment