Exemple #1
0
def update_restaurant_form(request, restaurant_id):
    restaurant = Restaurant.objects.get(id=restaurant_id)
    if request.method != "POST":
        form = RestaurantForm(instance=restaurant)
    else:
        form = RestaurantForm( request.POST )
        if form.is_valid():
            cd = form_cleaned_data
            message = u'Name: ' + cd['name'] + '(' + restaurant.id +')\r\n'
            message += u'Address: ' + cd['address'] +'\r\n'
            message += u'City: ' + cd['city'] +'\r\n'
            message += u'State: ' + cd['state'] +'\r\n'
            message += u'Zip Code: ' + cd['zip_code'] +'\r\n'
            message += u'Website: ' + cd['website'] +'\r\n'
            message += u'Phone: ' + cd['phone'] +'\r\n'
            message += u'Hours: ' + cd['hours'] + '\r\n'
            message += u'Description: ' + cd['description'] + '\r\n'
            message += u'\r\n\r\n\r\nDebug Information\r\rUser Agent: ' + request.META['HTTP_USER_AGENT'] +'\r\n' 
            message += u'IP Address: ' + request.META['REMOTE_ADDR'] +'\r\n' 
            message += u'Referer: ' + request.META['HTTP_REFERER'] +'\r\n'
            
            send_mail(
                'News-Leader.com Restaurant:' +  restaurant.name + ' Submission: ' + str(cd['name']),
                message,
                '*****@*****.**',
                [to,'*****@*****.**','*****@*****.**',],
                )

    return render_to_response('restaurants/update_restaurant_form.html',
        {
            'restaurant': restaurant,
            'form': form,
            #'submit': submit 
        }, context_instance=RequestContext(request))
Exemple #2
0
 def test_invalid_form(self):
     name = "Some restaurant"
     description = "Some random description"
     data = {
         'name':name,
         'description': description,
     }
     form = RestaurantForm(data=data)
     self.assertFalse(form.is_valid())
Exemple #3
0
 def test_invalid_form(self):
     name = "Some restaurant"
     description = "Some random description"
     data = {
         'name':name,
         'description': description,
     }
     form = RestaurantForm(data=data)
     self.assertFalse(form.is_valid())
Exemple #4
0
def restaurant_create(request):
    print(request.POST)
    form = RestaurantForm
    if request.method == "POST":
        form = RestaurantForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect("restaurant-list")
    context = {
        'form': form,
    }
    return render(request, 'create.html', context)
Exemple #5
0
def create(request):
    context = {}

    if request.method == "POST":
        restaurant_form = RestaurantForm(data=request.POST)
        if restaurant_form.is_valid():
            restaurant = restaurant_form.save()
            return HttpResponseRedirect("/restaurants/all")
        else:
            context['restaurant_form'] = restaurant_form

    if 'restaurant_form' not in context:
        context['restaurant_form'] = RestaurantForm()
    return render_to_response('create.html', RequestContext(request, context))
Exemple #6
0
 def test_valid_form(self):
     name = "Some random restaurant"
     description = "Some random description"
     opening_time = "12:15"
     closing_time = "10:15"
     data = {
         'name':name,
         'description': description,
         'opening_time': opening_time,
         'closing_time': closing_time
     }
     form = RestaurantForm(data=data)
     self.assertTrue(form.is_valid())
     self.assertEqual(form.cleaned_data.get('name'), name)
     self.assertEqual(form.cleaned_data.get('description'), description)
Exemple #7
0
 def test_valid_form(self):
     name = "Some random restaurant"
     description = "Some random description"
     opening_time = "12:15"
     closing_time = "10:15"
     logo="http://icons.veryicon.com/png/Movie%20%26%20TV/Free%20Star%20Wars/Darth%20Vader.png"
     data = {
         'name':name,
         'description': description,
         'opening_time': opening_time,
         'closing_time': closing_time,
         'logo': logo,
     }
     form = RestaurantForm(data=data)
     self.assertTrue(form.is_valid())
     self.assertEqual(form.cleaned_data.get('name'), name)
     self.assertEqual(form.cleaned_data.get('description'), description)
Exemple #8
0
 def test_valid_form(self):
     name = "Some random restaurant"
     description = "Some random description"
     opening_time = "12:15"
     closing_time = "10:15"
     logo = "http://icons.veryicon.com/png/Movie%20%26%20TV/Free%20Star%20Wars/Darth%20Vader.png"
     data = {
         'name': name,
         'description': description,
         'opening_time': opening_time,
         'closing_time': closing_time,
         'logo': logo,
     }
     form = RestaurantForm(data=data)
     self.assertTrue(form.is_valid())
     self.assertEqual(form.cleaned_data.get('name'), name)
     self.assertEqual(form.cleaned_data.get('description'), description)
Exemple #9
0
def new_restaurant(request):
    if request.user.groups.filter(name="Customer").exists():
        messages.warning(request, "Você não pode acessar essa página")
        return redirect('orders_list')

    try:
        restaurant = Restaurant.objects.filter(manager=request.user)
        if restaurant:
            messages.warning(request, "Já existe um restaurante cadastrado")
            return redirect('dashboard')
    except Restaurant.DoesNotExist:
        pass

    if request.method == 'POST':
        form = RestaurantForm(request.POST, request.FILES)
        if form.is_valid():
            restaurant = form.save(commit=False)
            restaurant.manager = request.user
            restaurant.save()
            messages.success(request, "Novo restaurante cadastrado.")
            return redirect('dashboard')
    else:
        form = RestaurantForm()

    return render(request, 'restaurants/new.html', {'form': form})
def sign_up(request):
    user_form = UserForm()
    restaurant_form = RestaurantForm()

    if request.method == "POST":
        user_form = UserForm(request.POST)
        restaurant_form = RestaurantForm(request.POST, request.FILES)

        if user_form.is_valid() and restaurant_form.is_valid():
            new_user = User.objects.create_user(**user_form.cleaned_data)
            new_restaurant = restaurant_form.save(commit=False)
            new_restaurant.user = new_user
            new_restaurant.save()

            login(
                request,
                authenticate(username=user_form.cleaned_data["username"],
                             password=user_form.cleaned_data["password"]))

            return redirect(home)

    return render(request, 'restaurant/sign_up.html', {
        "user_form": user_form,
        "restaurant_form": restaurant_form
    })
Exemple #11
0
def restaurant_create(request):
    form = RestaurantForm()
    if request.method == "POST":
        form = RestaurantForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            return redirect('restaurant-list')
    context = {
        "form": form,
    }
    return render(request, 'create.html', context)
Exemple #12
0
def restaurant_update(request, restaurant_id):
    restaurant_obj = Restaurant.objects.get(id=restaurant_id)
    form = RestaurantForm(instance=restaurant_obj)
    if request.method == "POST":
        form = RestaurantForm(request.POST,
                              request.FILES,
                              instance=restaurant_obj)
        if form.is_valid():
            form.save()
            return redirect('restaurant-list')
    context = {
        "restaurant_obj": restaurant_obj,
        "form": form,
    }
    return render(request, 'update.html', context)
def restaurant_edit(request, id):
    restaurant = Restaurant.objects.get(pk=id)
    if request.method == 'POST':
        form = RestaurantForm(request.POST, instance=restaurant)
        if form.is_valid():
            resto = form.save()
            return redirect(reverse('restaurant_show', args=[restaurant.pk]))
    else:
        form = RestaurantForm(instance=restaurant)
        title = "Edit {}".format(restaurant.name)
        context = {'restaurant': restaurant, 'form': form, 'title': title}
        return render(request, 'restaurant_edit.html', context)
Exemple #14
0
def my_restaurant(request):
    restaurant = Restaurant.objects.get(manager=request.user)
    if request.method == 'POST':
        form = RestaurantForm(request.POST, request.FILES, instance=restaurant)
        if form.is_valid():
            restaurant = form.save(commit=False)
            restaurant.manager = request.user
            restaurant.save()
            messages.success(request, "Restaurante atualizado.")
            return redirect('dashboard')
    else:
        form = RestaurantForm(instance=restaurant)

    return render(request, 'restaurants/new.html', {'form': form})
def account(request):
    user_form = UserFormForEdit(instance=request.user)
    restaurant_form = RestaurantForm(instance=request.user.restaurant)

    if request.method == "POST":
        user_form = UserFormForEdit(request.POST, instance=request.user)
        restaurant_form = RestaurantForm(request.POST,
                                         request.FILES,
                                         instance=request.user.restaurant)

        if user_form.is_valid() and restaurant_form.is_valid():
            user_form.save()
            restaurant_form.save()

    return render(request, 'restaurant/account.html', {
        "user_form": user_form,
        "restaurant_form": restaurant_form
    })
Exemple #16
0
def restaurant_update(request, restaurant_id):

	if request.user.is_anonymous:
		messages.success(request, 'You have to signin first!')
		return redirect('signin')

	restaurant = Restaurant.objects.get(id=restaurant_id)
	if not (restaurant.owner == request.user):
		messages.success(request, 'Restaurant\'s owner only has a permission to update this restaurant info!')
		return redirect('restaurants-list')

	form = RestaurantForm(instance=restaurant)
	if request.method == 'POST':
		form = RestaurantForm(request.POST, request.FILES, instance=restaurant)
		if form.is_valid():
			form.save()
			messages.success(request, 'Successfully updated!')
			return redirect('restaurants-list')

	context = {
		'form': form,
		'restaurant': restaurant,
	}
	return render(request, 'restaurants/update.html', context)
def restaurant_edit(request, id):
    user = request.user
    restaurant = user.restaurants.objects.get(pk=id)
    if restaurant.user == request.user.is_authenticated:
        if request.method == 'POST':
            form = RestaurantForm(request.POST, instance=restaurant)
            if form.is_valid():
                resto = form.save()
                return redirect(
                    reverse('restaurant_show', args=[restaurant.pk]))
        else:
            form = RestaurantForm(instance=restaurant)
            title = "Edit {}".format(restaurant.name)
            context = {'restaurant': restaurant, 'form': form, 'title': title}
            return render(request, 'restaurant_edit.html', context)
    else:
        context = {
            'error_message':
            'Sorry, you are not authorized to edit this restaurant.'
        }
        return render(request, 'restaurant_edit.html', context)
Exemple #18
0
def restaurant_create(request):

	if request.user.is_anonymous:
		messages.success(request, 'You have to signin first!')
		return redirect('signin')
	
	form = RestaurantForm()
	if request.method == "POST":
		form = RestaurantForm(request.POST, request.FILES)
		if form.is_valid():
			restaurant = form.save(commit=False)
			restaurant.owner = request.user
			restaurant.save()

			messages.success(request, "Successfully Created!")
			return redirect('restaurants-list')

	context = {
		'form': form,
	}
	return render(request, 'restaurants/create.html', context)