Exemplo n.º 1
0
def result_page(request, slug):
	event_host_id = int(slug.split('-')[2])
	shards_to_query = bucket_users_into_shards([event_host_id])
	shardid = 0 
	event = None

	# This is shady, but basically theres only going to be 1
	# match for the event we're looking for
	for shard, id in shards_to_query.items():
		event = Event.objects.filter(slug__in=[slug])
		set_user_for_sharding(event, shard)
		shardid = shard
		event = event.first()
		
	set_user_for_sharding(EventSubmission.objects, shardid)
	submissions = EventSubmission.objects.filter(event_id=event.id)

	event_preferences=[]
	for submission in submissions:
		set_user_for_sharding(Restriction.objects, shardid)
		restrictions = Restriction.objects.filter(submission=submission)
		for restriction in restrictions:
			print(restriction.name)
			event_preferences.append(restriction.name)
	event_preferences=set(event_preferences)

	set_user_for_sharding(Restaurant.objects, shardid)
	result = yelp_call(event.radius,event.location,event_preferences)
	restaurant = Restaurant(user_id=shardid, event=event,restaurant_name=result[0],image_url=result[1],yelp_url=result[2],address=result[3])
	restaurant.save()

	return render(request,'../templates/successpage.html',{'restaurant':restaurant,'event':event})
Exemplo n.º 2
0
    def restaurant(current_user):
        if current_user.role != 'admin':
            response = jsonify({
                'message': 'Unauthorized command',
                'status': False
            })
            response.status_code = 401

            return response

        restaurant_name = str(request.data.get('restaurant_name'))
        restaurant_email = str(request.data.get('restaurant_email'))
        restaurant_county = str(request.data.get('restaurant_county'))
        restaurant_location = str(request.data.get('restaurant_location'))
        restaurant_minorder = str(request.data.get('restaurant_minorder'))
        restaurant_phone = str(request.data.get('restaurant_phone'))
        restaurant_mobile = str(request.data.get('restaurant_mobile'))
        restaurant_about = str(request.data.get('restaurant_about'))
        restaurant_delivery = str(request.data.get('restaurant_delivery'))

        if restaurant_name.isspace() or restaurant_email.isspace() or restaurant_county.isspace() or restaurant_location.isspace():
            response = jsonify({
                'message': 'All fields are required',
                'status': False
            })

            return response
        elif restaurant_minorder.isspace() or restaurant_phone.isspace() or restaurant_mobile.isspace():
            reponse = jsonify({
                'message': 'All fields are required',
                'status': False
            })

            return response
        elif restaurant_about.isspace() or restaurant_delivery.isspace():
            response = jsonify({
                'message': 'All fields are required',
                'status': False
            })

            return response
        else: 
            new_restaurant = Restaurant(restaurant_name, restaurant_email, restaurant_county, restaurant_location, restaurant_minorder, restaurant_phone, restaurant_mobile, restaurant_about, restaurant_delivery)
            new_restaurant.save()

            response = jsonify({
                'Message': 'Successfully added new Restaurant',
                'Status': True
            })

            response.status_code = 201
            return response
Exemplo n.º 3
0
def restaurantDetails(request):
    data = {'title': 'My Restaurant Details'}
    print("one")
    if request.method == "POST":
        name = request.POST.get('name')
        address1 = request.POST.get('address1', '')
        address2 = request.POST.get('address2', '')
        country = request.POST.get('country', 'India')
        state = request.POST.get('state', '')
        zip = request.POST.get('zip', '')
        location = request.POST.get('location', 'pala')
        tag = request.POST.get('tag', '')
        if not name:
            messages.error(request, 'cant save restaurant details')
            return redirect('restaurant_details')
        rest = Restaurant()
        try:
            rest = Restaurant.objects.create(user=request.user,
                                             name=name,
                                             address1=address1,
                                             address2=address2,
                                             country=country,
                                             state=state,
                                             zip=zip,
                                             location=location,
                                             tag=tag)
            messages.info(request, 'saved restaurant details')

        except IntegrityError:
            rest = Restaurant.objects.get(user=request.user)
            rest.name = name
            rest.address1 = address1
            rest.address2 = address2
            rest.country = country
            rest.state = state
            rest.zip = zip
            rest.location = location
            rest.tag = tag
            rest.save()
            messages.info(request, 'updated restaurant details.')
        except:
            messages.info(request, 'cant save restaurant details. try again')

        return redirect('restaurant_details')

    data['rest'] = Restaurant.objects.filter(
        user=request.user).order_by('id').first()
    print(data['rest'])
    return render(request, 'partner/owner/restaurant_details.html',
                  processData(request, data))
Exemplo n.º 4
0
def restaurantDetails(request):
    data = {'title': 'My Restaurant Details'}
    print("one")
    if request.method == "POST":
        name = request.POST.get('name')
        address1 = request.POST.get('address1', '')
        address2 = request.POST.get('address2', '')
        zip = request.POST.get('zip', '')
        tag = request.POST.get('tag', '')
        if not name:
            messages.error(request, 'cant save restaurant details')
            return redirect('restaurant_details')
        rest = Restaurant()
        try:
            rest = Restaurant.objects.create(user=request.user,
                                             name=name,
                                             address1=address1,
                                             address2=address2,
                                             zip=zip,
                                             tag=tag)
            messages.info(request, 'saved restaurant details')

        except IntegrityError:  #this error is generated on the loss of uniqueness of the assumed unique variable user
            rest = Restaurant.objects.get(user=request.user)
            rest.name = name
            rest.address1 = address1
            rest.address2 = address2
            rest.zip = zip
            rest.tag = tag
            rest.save()
            messages.info(request, 'updated restaurant details.')
        except:
            messages.info(
                request,
                'Loss of uniquness. Cant save restaurant details. Try again')

        return redirect('restaurant_details')

    data['rest'] = Restaurant.objects.filter(
        user=request.user).order_by('id').first()
    print(data['rest'])
    return render(request, 'partner/owner/restaurant_details.html',
                  processData(request, data))