def add_tapa(request, bar_name_url): context = RequestContext(request) try: bar = Bar.objects.get(slug=bar_name_url) except Bar.DoesNotExist: bar = None if request.method == 'POST': form = TapaForm(request.POST) if form.is_valid(): if bar: tapa = form.save(commit=False) tapa.bar = bar tapa.votos = 0 tapa.save() # probably better to use a redirect here. return bar(request, bar_name_url) else: print form.errors else: form = TapaForm() context_dict = {'form':form, 'bar': bar} context_dict['bar_name_url'] = bar_name_url return render(request, 'rango/add_tapa.html', context_dict)
def add_page(request,bar_name_slug): try: bar = Bar.objects.get(slug=bar_name_slug) except bar.DoesNotExist: bar = None if request.method == 'POST': form = TapaForm(request.POST) if form.is_valid(): if bar: tapa = form.save(commit=False) tapa.bar = bar tapa.views = 0 tapa.save() # probably better to use a redirect here. return listaBares(request) else: print form.errors else: form = TapaForm() context_dict = {'form':form, 'bar': bar} return render(request, 'rango/add_page.html', context_dict)
def add_tapa(request, bar_name_slug): try: bar = Bar.objects.get(slug=bar_name_slug) except Bar.DoesNotExist: bar = None if request.method == "POST": form = TapaForm(data=request.POST) if form.is_valid(): if bar: t = form.save(commit=False) t.bar = bar t.votos = 0 print '**************************************************************' if 'picture' in request.FILES: print '**************************************************************' t.picture = request.FILES['picture'] t.save() return bares(request, bar_name_slug) else: print form.errors else: form = TapaForm() bar_list = Bar.objects.order_by('-numero_visitas') context_dict = {'form':form, 'bar':bar, 'bar_name_slug':bar.slug} context_dict['bares'] = bar_list return render(request, 'rango/add_tapa.html', context_dict )
def add_tapa_save(request): # A HTTP POST? if request.method == 'POST': form = TapaForm(request.POST) # Have we been provided with a valid form? if form.is_valid(): # Save the new bar to the database. form.save(commit=True) # Now call the index() view. # The user will be shown the hometapa. return index(request) else: # The supplied form contained errors - just print them to the terminal. print form.errors else: # If the request was not a POST, display the form to enter details. form = TapaForm() # Bad form (or form details), no form supplied... # Render the form with error messages (if any). return render(request, 'rango/add_tapa.html', {'form': form})
def add_tapa(request, bar_name_slug): try: bar = Bar.objects.get(slug=bar_name_slug) except Bar.DoesNotExist: bar = None if request.method == "POST": form = TapaForm(request.POST) if form.is_valid(): if bar: tapa = form.save(commit=False) tapa.bar = bar tapa.votos = 0 tapa.save() # probably better to use a redirect here. return index(request) else: print form.errors else: form = TapaForm() context_dict = {"form": form, "bar": bar} return render(request, "rango/add_tapa.html", context_dict)