Пример #1
0
def add_bar(request, tapa_name_slug):

    try:
        cat = Tapas.objects.get(slug=tapa_name_slug)
    except Tapas.DoesNotExist:
                cat = None

    if request.method == 'POST':
        form = BaresForm(request.POST)
        if form.is_valid():
            if cat:
                bar = form.save(commit=False)
                bar.tapa = cat
                bar.n_visitas = 0
                bar.save()
                # probably better to use a redirect here.
                return tapa(request, tapa_name_slug)
        else:
            print form.errors
    else:
        form = BaresForm()

    context_dict = {'form':form, 'tapa': cat}

    return render(request, 'rango/add_bar.html', context_dict)
Пример #2
0
def add_bares(request):
    if request.method == "POST":
        form = BaresForm(request.POST)

        if form.is_valid():

            form.save(commit=True)

            return index(request)
        else:

            print form.errors
    else:

        form = BaresForm()

    return render(request, "rango/add_bares.html", {"form": form})
Пример #3
0
def add_bares(request):
    if request.method == 'POST':
        form = BaresForm(request.POST)

        # Have we been provided with a valid form?
        if form.is_valid():
            # Save the new bares to the database.
            form.save(commit=True)

            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 = BaresForm()

    return render(request, 'rango/add_bares.html', {'form': form})
Пример #4
0
def add_bar(request, tapa_name_slug):

    try:
        cat = Tapas.objects.get(slug=tapa_name_slug)
    except Tapas.DoesNotExist:
        cat = None

    if request.method == 'POST':
        form = BaresForm(request.POST)
        if form.is_valid():
            if cat:
                bar = form.save(commit=False)
                bar.tapa = cat
                bar.n_visitas = 0
                bar.save()
                # probably better to use a redirect here.
                return tapa(request, tapa_name_slug)
        else:
            print form.errors
    else:
        form = BaresForm()

    context_dict = {'form': form, 'tapa': cat}

    return render(request, 'rango/add_bar.html', context_dict)
Пример #5
0
def add_category(request):
    # A HTTP POST?
    if request.method == 'POST':
        form = BaresForm(request.POST)

        # Have we been provided with a valid form?
        if form.is_valid():
            # Save the new category to the database.
            form.save(commit=True)

            # Now call the index() view.
            # The user will be shown the homepage.
            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 = BaresForm()

    # Bad form (or form details), no form supplied...
    # Render the form with error messages (if any).
    return render(request, 'rango/add_category.html', {'form': form})
Пример #6
0
def add_bares(request):
    if request.method == 'POST':
        form = BaresForm(request.POST)

        # Have we been provided with a valid form?
        if form.is_valid():
            # Save the new bares to the database.
            form.save(commit=True)

            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 = BaresForm()

    return render(request, 'rango/add_bares.html', {'form': form})
Пример #7
0
def add_category(request):
    # A HTTP POST?
    if request.method == 'POST':
        form = BaresForm(request.POST)

        # Have we been provided with a valid form?
        if form.is_valid():
            # Save the new category to the database.
            form.save(commit=True)

            # Now call the index() view.
            # The user will be shown the homepage.
            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 = BaresForm()

    # Bad form (or form details), no form supplied...
    # Render the form with error messages (if any).
    return render(request, 'rango/add_category.html', {'form': form})