Example #1
0
def add_page(request, category_name_slug):

    try:
        cat = Category.objects.get(slug=category_name_slug)
    except Category.DoesNotExist:
                cat = None

    if request.method == 'POST':
        form = PageForm(request.POST)
        if form.is_valid():
            if cat:
                page = form.save(commit=False)
                page.category = cat
                page.views = 0
                page.save()
                # probably better to use a redirect here.
                return category(request, category_name_slug)
        else:
            print form.errors
    else:
        form = PageForm()

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

    return render(request, 'Rango/add_page.html', context_dict)
Example #2
0
 def get(self, request, category_name_slug):
     category= self.getBasics(category_name_slug)
     form = PageForm()  
     #you cannot add a page to a category that does not exist
     if category is None:
         return redirect('/Rango/')
        #will handle the bad form, new3 form or no form supplied cases
     #Render the form with error messages (if any).
     context_dict = {'form': form, 'category': category}
     return render(request, 'Rango/add_page.html', context=context_dict)
Example #3
0
def add_page(request, category_name_slug):

    try:
        cat = Category.objects.get(slug=category_name_slug)
    except Category.DoesNotExist:
        cat = None

    if request.method == 'POST':
        form = PageForm(request.POST)
        if form.is_valid():
            if cat:
                page = form.save(commit=False)
                page.category = cat
                page.views = 0
                page.save()
                # probably better to use a redirect here.
                return category(request, category_name_slug)
        else:
            print form.errors
    else:
        form = PageForm()

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

    return render(request, 'Rango/add_page.html', context_dict)
Example #4
0
 def post(self, request, category_name_slug):
     category= self.getBasics(category_name_slug)
     form = PageForm(request.POST)
     # have we been provided with a valid form?
     if form.is_valid():
         if category:
             #save the new category to the database
             page = form.save(commit=False)
             page.category = category
             page.views = 0
             page.last_view = timezone.now()
             page.save()
         # Now that the category is saved, we could confirm this.
         # For now, just redirect the user back to the index view
         return redirect(reverse('Rango:show_category', 
                                 kwargs={'category_name_slug':category_name_slug}))
     else:
         # the supplied form has errors
         # just print them to the terminal
         print(form.errors)
         #will handle the bad form, new3 form or no form supplied cases
     #Render the form with error messages (if any).
     context_dict = {'form': form, 'category': category}
     return render(request, 'Rango/add_page.html', context=context_dict)
Example #5
0
def add_page(request, category_name_url):
    try:
        category = Category.objects.get(slug=category_name_url)
    except Category.DoesNotExist:
        print('no category exit')
        category = None
    form = PageForm()
    if request.method == 'POST':
        form = PageForm(request.POST)
        if form.is_valid():
            if category:
                page = form.save(commit=False)
                page.view = 0
                page.category = category
                page.save()
                return show_category(request, category_name_url)
        else:
            print(form.errors)
    context_dict = {'form': form, 'category': category}
    return render(request, 'rango/add_page.html', context_dict)
Example #6
0
def add_page(request, category_name_slug):
    try:
        category = Category.objects.get(slug=category_name_slug)
    except Category.DoesNotExist:
        category = None

    form = PageForm()
    if request.method == "POST":
        form = PageForm(request.POST)
        if form.is_valid():
            if category:
                page = form.save(commit=False)
                page.category = category
                page.views = 0
                page.save()
                return show_category(request, category_name_slug)
        else:
            print(form.errors)
    context = {'category': category, 'form': form}
    return render(request, 'Rango/add_page.html', context)