Example #1
0
def add_category(request):
    context_dict = {}

    print('[debug] what call is this?  {}'.format(request.method))

    # A HTTP POST?
    if request.method == 'POST':
        form = CategoryForm(request.POST)

        # Provided with a valid form?
        if form.is_valid():
            # Save the new category to the database
            cat = form.save(commit=True)
            print('[debug] {} - {}'.format(cat, cat.slug))

            # 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 (on submit), display the form to enter details.
        form = CategoryForm()

    # Bad form (or form details), no form supplied...
    # Render the form with error messages (if any).
    context_dict['form'] = form
    return render(request, 'rango/add_category.html', context_dict)
Example #2
0
def add_category(request):
    # Get the context from the request.
    context = RequestContext(request)

    # A HTTP POST?
    if request.method == 'POST':
        form = CategoryForm(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 = CategoryForm()

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

    cat_list = get_category_list()

    #HTTP POST
    if request.method == 'POST':
        form = CategoryForm(request.POST)

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

            #return to index view.
            #User will now see the homepage
            return index(request)
        else:
            #the supplied form contains errors - print these to terminal
            print form.errors
    else:
        #if the request was not a POST, display the form to enter details
        form = CategoryForm()

    # Bad form (or form details), no form supplied...
    # Render the form with error messages (if any).
    return render_to_response('rango/add_category.html', {'form': form, 'cat_list': cat_list}, context)
Example #4
0
def add_category(request):
    # Get the context from the request.
    context = RequestContext(request)
    cat_list = get_category_list()
    context_dict = {}
    context_dict['cat_list'] = cat_list

    # A HTTP POST?
    if request.method == 'POST':
        form = CategoryForm(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:
            # No form passed - ignore and keep going.
            pass
    else:
        # If the request was not a POST, display the form to enter details.
        form = CategoryForm()

    # Bad form (or form details), no form supplied...
    # Render the form with error messages (if any).
    context_dict['form'] = form
    return render_to_response('rango/add_category.html', context_dict, context)
Example #5
0
def add_category(request):
    # HTTP Post
    if request.method == 'POST':
        form = CategoryForm(request.POST)
        
        # Is form valid?
        if form.is_valid():

            # Save category to database
            form.save(commit=True)

            # Call index and go to homepage
            return index(request)

        # If not valid form
        else:
            # Form errors (printed to terminal)
            print(form.errors)

    # HTTP Get
    elif request.method == 'GET':
        # Create form
        form = CategoryForm

    # Render form - include any error messages
    return render(request, 'rango/add_category.html', {'form': form})
Example #6
0
 def test_blank_data(self):
     """
     Checks form with blank data and corresponding form errors.
     """
     form = CategoryForm(data={})
     self.assertFalse(form.is_valid())
     self.assertEqual(form.errors, {'name': ['This field is required.']})
Example #7
0
def add_category(request):
    # Get the context
    context = RequestContext(request)
    
    # A HTTP POST?
    if request.method == 'POST':
        form = CategoryForm(request.POST)
        
        # have we been provided with a valud form
        if form.is_valid():
            # Save  the new category to the database
            form.save(commit=True)
            
            # redirect to homepage
            return index(request)
        else:
            print form.errors
            
    else:
        # If the request was not a POST, display the form to enter details.
        form = CategoryForm()
        
    context_dict = {'form' : form}
    context_dict['cat_list'] = get_cat_list()

    # Bad form (or form details), no form supplied...
    # Render the form with error messages (if any).
    return render_to_response('rango/add_category.html', context_dict, context)            
Example #8
0
def add_category(request):
    # get context from request
    context = RequestContext(request)

    if request.method == 'POST':
        form = CategoryForm(request.POST)

        # check if form is valid
        if form.is_valid():
            # save new category to db
            form.save(commit=True)

            # now call the index() view
            # the user will be shown the homepage
            return index(request)
        else:
            # form had errors
            print form.errors
    else:
        # non-POST requests should display form to user
        form = CategoryForm()

    # bad form (or form details), no form supplied...
    # render form with error messages (if any)
    return render_to_response(
        'rango/add_category.html', {'form': form}, context)
Example #9
0
def add_category(request):
    """
    User must be logged in to use this functionality.
    Adds a new category corresponding to the information in the form filled
    by the user. If form empty, display form. If form filled and valid, create
    a new category. If form filled and not valid, display form errors.
    """

	# An HTTP POST?
    if request.method == 'POST':
        form = CategoryForm(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.
			#return HttpResponse(form.errors)
			#return index(request)
            print form.errors
    else:
		# If the request was not a POST, display the form to enter details.
        form = CategoryForm()

	# 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})
Example #10
0
def add_category(request):
    # A HTTP POST?
    if request.method == 'POST':
        form = CategoryForm(request.POST)

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

            # 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 = CategoryForm()

    context_dict = {'form': form}

    # Bad form (or form details), no form supplied...
    # Render the form with error messages (if any).
    return render(request, 'rango/add_category.html', context_dict)
Example #11
0
def add_page(request, category_name_url):
    context = RequestContext(request)

    category_name = decode_url(category_name_url)

    if request.method == 'POST':
        form = CategoryForm(request.POST)

        if form.is_valid():
            form.save(commit=False)

            try:
                cat = Category.objects.get(name=category_name)
                page.category = cat
            except Category.DoesNotExist:
                return render_to_response('rango/add_page.html', context_dict, context, context)
            
            page.views = 0

            page.save()

            return category(request, category_name_url)
        else:
            print form.errors
    else:
        form = PageForm()

    return render_to_response( 'rango/add_page.html',
            {'category_name_url': category_name_url,
                'category_name': category_name, 'form': form},
            context)
Example #12
0
def add_category(request):
    context = RequestContext(request)
    category_list = get_5_categories()

    if request.user.is_active and request.method == 'POST':

        #print request.method
        #print request.POST.copy()

        form = CategoryForm(request.POST)

        if form.is_valid():
            form.save(commit=True)
            return index(request)
        else:
            print form.errors

    else:

        #print request.method
        #print request.GET.copy()
        form = CategoryForm
    context_dict = {'form': form, 'categories': category_list}


    return render_to_response('rango/add_category.html', context_dict, context)
Example #13
0
def add_category(req):
    """View used to add new categories"""

    # Get the context from the request.
    context = RequestContext(req)

    # Retrieve categories list for the left navbar
    cat_list = get_category_list()

    # A HTTP POST? If so, provide a form for posting a new category
    if req.method == 'POST':
        form = CategoryForm(req.POST)

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

            # Now call the index() view.
            # The user will be served with the index.html template
            return index(req)

        else:
            # The supplied form contained errors - just print them to the terminal
            print form.errors

    else:
        # If the request wasn't a POST, display the form to enter details
        form = CategoryForm()

    context_dict = {'cat_list': cat_list, 'form': form}

    # Bad form (or form details), no form supplied...
    # Render the form with error messages (if any).
    return render_to_response('rango/add_category.html', context_dict, context)
def add_category(request):
    # Get the context from the request.
    context = RequestContext(request)
    cat_list = get_category_list()

    # A HTTP POST?
    if request.method == 'POST':
        form = CategoryForm(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
    # According to REST principles, if we didn't use POST, it has to be a GET, then display a form to submit it afterwards.
    else:
        # If the request was not a POST, display the form to enter details.
        form = CategoryForm()

    # Bad form (or form details), no form supplied...
    # Render the form with error messages (if any).
    return render_to_response('rango/add_category.html', {'form': form, 'cat_list': cat_list}, context)
Example #15
0
def add_category(request):
	#get the context form the request
	context = RequestContext(request)


	#A HTTP POST?
	if request.method == 'POST':
		form = CategoryForm(request.POST)

		#have them provided with a valid form
		if form.is_valid():
			form.save(commit=True)

			#now call the main() view
			#the user will be shown the homepage
			return main(request)
		else:
			print form.errors

	else:
		form = CategoryForm()

	#bad form of form details, no from suppied
	#render the form with error msgs if any
	return render_to_response('rango/add_category.html', {'form':form}, context)
Example #16
0
def add_category(request):
    context = RequestContext(request)

    #Checking whether the submit type is POST or not (becauase the form is submitted on POST)

    if request.method == 'POST':
        #Process the form data
        form = CategoryForm(request.POST)

        #Check the validity
        if form.is_valid():
            #Save the new category to our SQLite 3 Database
            form.save(commit=True)

            #Now load it up on the Index view as the new Category is saved...Easy!

            return index(request)
        else:
            #if containingf errors, print it out to the terminal )(will replace after dev)
            print form.errors

    else:
        #If not post , then display the form to the user.....(As both Post and get are dpne to the same thread unlike PHP)
        form = CategoryForm()

    #Invoked only when NOT SUCCESS
    return render_to_response('rango/add_category.html' , {"form"  :form} , context)
Example #17
0
def add_category(request):
    context = RequestContext(request)

    #Check the html message type
    if request.method == 'POST' :
        form = CategoryForm(request.POST)

        #Validate the form
        if form.is_valid():
            #Save the new object
            form.save(commit=True)
            #Redirect the user to the index
            return index(request)
        else:
            #Print errors on terminal
            print form.errors
    else:
        #Get the form attributes
        form = CategoryForm()

    #Bad Form (or form details)
    #Render the form with error messages
    return render_to_response('rango/add_category.html',
            {
            'form':form,
            'cat_list': get_category_list()
            },
            context)
Example #18
0
def add_category(request):

    form = CategoryForm()

    # A HTTP POST?
    if request.method == 'POST':
        form = CategoryForm(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 that the category is saved
            # We could give a confirmation message
            # But since the most recent category added is on the index page
            # then we can redirect the user back to the index page.
            return index(request)
        else:
            # The supplied form contained errors -
            # just print them to the terminal.
            print(form.errors)

    # Will handle the bad form, new form or
    # no form supplied cases.
    # Render the form with error messages (if any).
    return render(request, 'rango/add_category.html', {'form': form})
Example #19
0
def add_category(request):

	#get the context
	context = RequestContext(request)
	#create empty error dictionary
	errors = ''
	#check if POST
	if request.method == 'POST':
		form = CategoryForm(request.POST)

		#check if form is valid
		if form.is_valid():
			#save the new category to the database
			form.save(commit=True)

			#go back to the main page
			return index(request)

		else:
			# form contains some error extract them
			
			errors = form.errors

	else:
		# request is GET simply display the form to the user
		form = CategoryForm()

	#create dictionary with site context
	context_dict = {'form' : form,
					'errors' : errors,
					'categories' : get_category_list()}

	return render_to_response('add_category.html',context_dict, context)
Example #20
0
def add_category(request):
    # A HTTP POST?
    if request.method == 'POST':
        form = CategoryForm(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:
            # If the supplied form contained errors, making it NOT valid, print these
            # errors to the terminal
            print form.errors
    else:
        # If the request was not a POST, display the form to enter details
        # (i.e. upon first load)
        form = CategoryForm()

    # 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})
def add_category(request):
	form = CategoryForm()
	if request.method == 'POST':
		form = CategoryForm(request.POST)
		if form.is_valid():
			form.save(commit=True)
			return index(request)
		else:
			print(form.errors)
	return render(request, 'rango/add_category.html', {'form': form})
Example #22
0
def add_category(request):
    if request.method == 'POST':
        form = CategoryForm(request.POST)
        if form.is_valid():
            form.save(commit=True)
            return HttpResponseRedirect('/rango/')
        else:
            print form.errors
    else:
        form = CategoryForm()
    return render(request, 'rango/add_category.html', {'form': form})
Example #23
0
def add_category(request):
    if request.method == "POST":
        form = CategoryForm(request.POST)
        if form.is_valid():
            form.save(commit=True)
            return index(request)
        else:
            print form.errors
    else:
        form = CategoryForm()
    return render(request, "rango/add_category.html", {"form": form})
Example #24
0
def add_category(request):
    context = RequestContext(request)
    if request.method == 'POST':
        form = CategoryForm(request.POST)
        if form.is_valid():
            form.save(commit=True)
            return index(request)
        else:
            print form.errors
    else:
        form = CategoryForm()
    return render_to_response('rango/add_category.html',{'form':form}, context)
Example #25
0
def addCategory(request):
    template = "rango/addCategory.html"
    if request.method == "GET":
        return render(request, template, {"form": CategoryForm()})

    # request.method=='POST'
    form = CategoryForm(request.POST)
    if not form.is_valid():
        return render(request, template, {"form": form})

    form.save(commit=True)
    return rango(request)  # Call function rango()
Example #26
0
def add_category(request):
    if request.method == 'POST':
        form = CategoryForm(request.POST)

        if form.is_valid():
            cat = form.save()
            return redirect('category', cat.slug)
        else:
            print form.errors
    else:
        form = CategoryForm()

    return render(request, 'rango/add_category.html', {'form': form})
Example #27
0
def add_category(request):
	if request.method == "POST":
		form = CategoryForm(request.POST)
		if form.is_valid():
			form.save(commit = True)
			return redirect('/',request = request)
		else:
			print form.errors
			print "I have printed errors !\n"
			return render(request,'rango/add_category.html',{'form':form})
	else:
		form = CategoryForm()
	return render(request,'rango/add_category.html',{'form':form})
Example #28
0
File: views.py Project: thomec/tox
def add_category(request):

    # read the form data if we have a POST request
    form = CategoryForm(request.POST or None)
    context = {'form': form,}

    if form.is_valid():
        form.save(commit=True)
        return HttpResponseRedirect(reverse('rango:index'))
    else:
        print(form.errors)

    return render(request, 'rango/add_category.html', context)
Example #29
0
def add_category(request):
    if request.method == 'POST':
        form = CategoryForm(request.POST)
        if form.is_valid():
            form.save(commit=True)
            # return to homepage
            return index(request)
        else:
            print form.errors
    else:
        # display form
        form = CategoryForm()

    return render(request, 'rango/add_category.html', {'form': form})
Example #30
0
def add_category(request):
    if request.method == 'POST':
        form = CategoryForm(request.POST)
        # try:
        if form.is_valid():
            form.save(commit=True)
            return index(request)
        else:
            print form.errors
            # except Exception as e:
            #     print e
    else:
        form = CategoryForm()
    return render(request, 'rango/add_category.html', {'form': form})
Example #31
0
def add_category(request):
    form = CategoryForm()

    if request.method == 'POST':
        form = CategoryForm(request.POST)

        if form.is_valid():
            form.save(commit=True)

            return rango_index(request)

        else:
            print(form.errors)

    return render(request, 'rango/add_category.html', {'form': form})
Example #32
0
def add_category(request):
    if request.method == 'POST':
        form = CategoryForm(request.POST)

        if form.is_valid():
            form.save(commit=True)

            cat = form.save(commit=True)
            print cat, cat.slug

        else:

            print form.errors.as_json()

    else:

        form = CategoryForm()

    return render(request, 'rango/add_category.html', {'form': form})
def add_category(request):
    form = CategoryForm()

    # A HTTP POST?
    if request.method == 'POST':
        form = CategoryForm(request.POST)

    if form.is_valid():
        form.save(commit=True)
        return redirect('/rango/')

    else:
        # Form had errors, print to terminal
        print(form.errors)

    return render(request, 'rango/add_category.html', {'form': form})
Example #34
0
def add_category(request):
    if request.method == 'POST':
        form = CategoryForm(request.POST)

        if form.is_valid():
            form.save(commit=True)

            return HttpResponseRedirect('/rango')

        else:
            print form.errors

    else:
        form = CategoryForm()

    return render(request, 'rango/add_category.html', {'form': form})
Example #35
0
def add_category(request):
    form = CategoryForm()

    # a HTTP POST?
    if request.method == 'POST':
        form = CategoryForm(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)
            return index(request)
        else:
            print(forms.errors)

    return render(request, 'rango/add_category.html', {'form': form})
Example #36
0
def add_category(request):
    form = CategoryForm()

    #HTTP POST?
    if request.method == 'POST':
        form = CategoryForm(request.POST)
        #is the form data valid?
        if form.is_valid():
            # Save the new category to the database.
            form.save(commit=True)
            return index(request)  #return to index page
    else:
        # The supplied form contained errors
        print(form.errors)
    # Render the form with error messages (if any).
    return render(request, 'rango/add_category.html', {'form': form})
Example #37
0
def add_category(request):
    form = CategoryForm()

    #HTTP Post? (that is, did user supply data?)
    if request.method == 'POST':
        form = CategoryForm(request.POST)

        if form.is_valid():
            form.save(commit=True)
            # could also give confirmation message if you wanted
            return index(request)

        else:
            print(form.errors)

    return render(request, 'rango/add_category.html', {'form': form})
def add_category(request):
    form = CategoryForm()
    context_dict = {}
    # A HTTP POST?
    if request.method == 'POST':
        form = CategoryForm(request.POST)

        if form.is_valid():
            form.save(commit=True)
            return index(request)
        else:
            print(form.errors)

    context_dict['form'] = form

    return render(request, 'rango/add_category.html', context_dict)
Example #39
0
def add_category(request):

    if request.method == 'POST':
        form = CategoryForm(request.POST)

        if form.is_valid():
            form.save(
                commit=True)  # Save form if we are provided with valid data

            return index(request)
        else:
            print form.errors
    else:
        form = CategoryForm()

    return render(request, 'rango/add_category.html', {'form': form})
Example #40
0
def add_category(request):
    form = CategoryForm()

    if not request.user.is_authenticated:
        return redirect(reverse('rango:login'))

    if request.method == 'POST':
        form = CategoryForm(request.POST)

        if form.is_valid():
            form.save(commit=True)
            return redirect('/rango/')
        else:
            print(form.errors)

    return render(request, 'rango/add_category.html', {'form': form})
Example #41
0
def add_category(request):
    form = CategoryForm()
    if request.method == 'POST':
        form = CategoryForm(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)
            return index(request)
        else:
           # The supplied form contained errors -
           # just print them to the terminal.
            print(form.errors)
    # Will handle the bad form, new form, or no form supplied cases.
    # Render the form with error messages (if any).
    return render(request, 'rango/rango_add_category.html', {'form': form})
Example #42
0
def add_category(request):
    context_dict = {}
    context = RequestContext(request)
    cat_list = get_category_list()
    context_dict['cat_list'] = cat_list
    if request.method == 'POST':
        form = CategoryForm(request.POST)
        if form.is_valid():
            form.save(commit=True)
            return index(request)
        else:
            print(form.errors)
    else:
        form = CategoryForm()
    context_dict['form'] = form
    return render(request, 'rango/add_category.html', context_dict, context)
Example #43
0
def add_category(request):
	# A HTTP POST ?
	if request.method == 'POST':
		form = CategoryForm(request.POST)

		if form.is_valid():
			# Save the new ctegory to the database
			form.save(commit=True)
			return index(request)
		else:
			print form.errors
	else:
		# If the request was not a POST, display the form to enter details.
		form = CategoryForm()

	return render(request, 'rango/add_category.html', {'form': form})
Example #44
0
def add_category(request):
    context = RequestContext(request)

    if request.method == "POST":
        form = CategoryForm(request.POST)
        if form.is_valid():
            form.save(commit=True)
            return index(request)

        else:
            print(form.errors)
    else:
        # If the request was not a POST, display the form to enter details.
        form = CategoryForm()
    return render_to_response('rango/add_category.html', {'form': form},
                              context)
def add_category(request):
	form = CategoryForm()

	if request.method == 'POST':
		form = CategoryForm(request.POST)

		if form.is_valid():
			#save the new category to the db.
			form.save(commit=True)
			return redirect('/rango/')

		else:
			print(form.errors)

	#renders the form with error messages (if any)
	return render(request, 'rango/add_category.html', {'form': form})
Example #46
0
def add_category(request):
    form = CategoryForm()

    # A HTTP POST?
    if request.method == 'POST':
        form = CategoryForm(request.POST)

        if form.is_valid():
            # Save the new category to the database.
            form.save(commit=True)
            return redirect('/rango/')
        else:
            #The supplied form contained errors. Print them
            print(form.errors)
    #Handle bad form, new form, or no form supplied cases.
    return render(request, 'rango/add_category.html', {'form': form})
Example #47
0
def add_category(request):
    form = CategoryForm()

    # Did the user submit data via the form
    if request.method == 'POST':
        form = CategoryForm(request.POST)

        if form.is_valid():
            form.save(commit=True)

            return redirect('/rango/')
        else:
            # print errors to terminal
            print(form.errors)

    return render(request, 'rango/add_category.html', {'form': form})
Example #48
0
def add_category(request):
    form = CategoryForm()

    #if the user has submitted (posted) a form to be processed
    if request.method == 'POST':
        form = CategoryForm(request.POST)

        if form.is_valid():
            form.save(commit=True)
            #received the form, so return the user back to the index page
            return redirect('/rango/')
        else:
            #if the form submitted is invalid, print the errors for the user
            print(form.errors)

    return render(request, 'rango/add_category.html', {'form': form})
def add_category(request):
    form = CategoryForm()
    # A HTTP POST?
    if request.method == 'POST':
        form = CategoryForm(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 that the category is saved, we could confirm this.
            # For now, just redirect the user back to the index view.
            return redirect('/rango/')
        else:
            # The supplied form contained errors
            print(form.errors)
    return render(request, 'rango/add_category.html', {'form': form})
Example #50
0
def add_category(request):
    form = CategoryForm()

    # If method is GET, the blank form defined
    #  above gets returned and the user can
    #  fill in the form.
    if request.method == 'POST':
        form = CategoryForm(request.POST)

        if form.is_valid():
            form.save(commit=True)
            return index(request)
        else:
            print(form.errors)

    return render(request, 'rango/add_category.html', {'form': form})
Example #51
0
def add_category(request):
    if request.method == 'POST':     # a http POST request
        form = CategoryForm(request.POST)  # 根据POST的数据来创建一个CategoryForm对象

        if form.is_valid():        # 判断表单是否有效,有效则保存categroy对象至数据库
            form.save(commit=True)
            return index(request)    # 返回主页
        else:
            print(form.errors)

    else:
        form = CategoryForm()   # 如果request不是POST,显示填写form页面

    # ☆☆☆  这行错将form写成from,导致模板无法加载参数,页面没有表单
    # return render(request, 'rango/add_category.html', {'from': form})
    return render(request, 'rango/add_category.html', locals())
Example #52
0
def add_category(request):
    form = CategoryForm()

    # HTTP POST?
    if request.method == "POST":
        form = CategoryForm(request.POST)

        # Is form valid
        if form.is_valid():
            form.save(commit=True)

            return redirect('/rango')
        else:
            print(form.errors)

    return render(request, 'rango/add_category.html', {'form': form})
Example #53
0
def add_category(request):
    form = CategoryForm()

    if request.method == 'POST':
        form = CategoryForm(request.POST)

        if form.is_valid():
            form.save(commit=True)
            # We could give a confirmation message too
            # directs the user back to the index page
            return index(request)

        else:
            print(form.errors)

    return render(request, 'rango/add_category.html', {'form': form})
Example #54
0
def add_category(request):
    context = RequestContext(request)

    if request.method == 'POST':
        form = CategoryForm(request.POST)

        if form.is_valid():
            form.save(commit=True)
            return index(request)
        else:
            print form.errors
    else:
        form = CategoryForm()

    return render_to_response('rango/add_category.html', {'form': form},
                              context)
Example #55
0
def add_category(request):
    form = CategoryForm()

    if request.method == 'POST':
        form = CategoryForm(request.POST)
        if form.is_valid():
            cat = form.save(commit=True)
            print('New category added: ', cat, '(' + cat.slug + ')')
            return index(request)
        else:
            print(form.errors)

    return render(request, 'rango/add_category.html', {'form': form})
def add_category(request):
    form = CategoryForm()

    if request.method == 'POST':
        form = CategoryForm(request.POST)

        if form.is_valid():
            cat = form.save(commit=True)
            print(cat.slug)
            return redirect('/rango/')
        else:
            print(form.errors)
    return render(request, 'rango/add_category.html', {'form': form})
def add_category(request):
    form = CategoryForm()

    # A HTTP POST?
    if request.method == 'POST':
        form = CategoryForm(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)
            return redirect(reverse('rango:index'))
        else:
            # The form contained errors - print
            print(form.errors)

    return render(request, 'rango/add_category.html', {'form': form})
Example #58
0
def add_category(request):
    form = CategoryForm()
    # A HTTP POST?
    if request.method == 'POST':
        form = CategoryForm(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 that the category is saved
            # We could give a confirmation message
            # But since the most recent category added is on the index page
            # Then we can direct the user back to the index page.
            return index(request)
        else:
            print(form.errors)
    return render(request, 'rango/add_category.html', {'form': form})
Example #59
0
def add_category(request):
    form = CategoryForm()

    # An HTTP Post?
    if request.method == 'POST':
        form = CategoryForm(request.POST)

        # Have we been provided with a valid form?
        if form.is_valid():
            form.save(commit=True)
            # cat = form.save(commit=True)
            # print(cat, cat.slug)
            return redirect('/rango/')
        else:
            # if form contains error, print to terminal...
            print(form.errors)
    return render(request, 'rango/add_category.html', {'form': form})
Example #60
0
def add_category(request):
    form = CategoryForm()

    # A HTTP POST?
    if request.method == 'POST':
        form = CategoryForm(request.POST)

        # Have we been provided with a valid form?
        if form.is_valid():
            form.save(commit=True)
            return index(request)

        else:
            # The supplied form contained errors - just print them to the terminal.
            print(form.errors)

    return render(request, 'rango/add_category.html', {'form': form})