当前位置: 首页>>代码示例>>Python>>正文


Python CategoryForm.is_valid方法代码示例

本文整理汇总了Python中rango.forms.CategoryForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python CategoryForm.is_valid方法的具体用法?Python CategoryForm.is_valid怎么用?Python CategoryForm.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rango.forms.CategoryForm的用法示例。


在下文中一共展示了CategoryForm.is_valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_category

# 需要导入模块: from rango.forms import CategoryForm [as 别名]
# 或者: from rango.forms.CategoryForm import is_valid [as 别名]
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})
开发者ID:vansant,项目名称:Tango-With-Django,代码行数:28,代码来源:views.py

示例2: test_blank_data

# 需要导入模块: from rango.forms import CategoryForm [as 别名]
# 或者: from rango.forms.CategoryForm import is_valid [as 别名]
 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.']})
开发者ID:pavdmyt,项目名称:django_rango,代码行数:9,代码来源:test_forms.py

示例3: add_category

# 需要导入模块: from rango.forms import CategoryForm [as 别名]
# 或者: from rango.forms.CategoryForm import is_valid [as 别名]
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)
开发者ID:Silber8806,项目名称:BizzTell,代码行数:28,代码来源:views.py

示例4: add_category

# 需要导入模块: from rango.forms import CategoryForm [as 别名]
# 或者: from rango.forms.CategoryForm import is_valid [as 别名]
def add_category(request, placeholder=''):
	# HTTP POST?
	if request.method == 'POST':
		form = CategoryForm(request.POST)

		# valid form provided?
		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) deprecated
			return redirect('rango:index')
		else:
			# The supplied form contained errors
			print(form.errors)
	else:
		# If the request was not a POST, display the form to enter details.
		if placeholder == '':
			form = CategoryForm()
		else:
			form = CategoryForm(initial={ 'name' : placeholder })
		# form = CategoryForm()
	return render(request, 'rango/add_category.html', {'form':form})
开发者ID:trendsetter37,项目名称:tango_with_django_project,代码行数:27,代码来源:views.py

示例5: add_category

# 需要导入模块: from rango.forms import CategoryForm [as 别名]
# 或者: from rango.forms.CategoryForm import is_valid [as 别名]
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)
开发者ID:advena,项目名称:tango_with_django,代码行数:35,代码来源:views.py

示例6: add_category

# 需要导入模块: from rango.forms import CategoryForm [as 别名]
# 或者: from rango.forms.CategoryForm import is_valid [as 别名]
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)
开发者ID:cyberjoac,项目名称:tango_with_django_project,代码行数:30,代码来源:views.py

示例7: add_category

# 需要导入模块: from rango.forms import CategoryForm [as 别名]
# 或者: from rango.forms.CategoryForm import is_valid [as 别名]
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)
开发者ID:justuno,项目名称:DjangoPractice,代码行数:29,代码来源:views.py

示例8: add_category

# 需要导入模块: from rango.forms import CategoryForm [as 别名]
# 或者: from rango.forms.CategoryForm import is_valid [as 别名]
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)
开发者ID:ronhemmers,项目名称:rango,代码行数:31,代码来源:views.py

示例9: add_category

# 需要导入模块: from rango.forms import CategoryForm [as 别名]
# 或者: from rango.forms.CategoryForm import is_valid [as 别名]
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)            
开发者ID:niparis,项目名称:TangoWRango,代码行数:30,代码来源:views.py

示例10: add_category

# 需要导入模块: from rango.forms import CategoryForm [as 别名]
# 或者: from rango.forms.CategoryForm import is_valid [as 别名]
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})
开发者ID:HorridTom,项目名称:my_rango,代码行数:27,代码来源:views.py

示例11: add_category

# 需要导入模块: from rango.forms import CategoryForm [as 别名]
# 或者: from rango.forms.CategoryForm import is_valid [as 别名]
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)
开发者ID:muya,项目名称:tango-with-django,代码行数:28,代码来源:views.py

示例12: add_category

# 需要导入模块: from rango.forms import CategoryForm [as 别名]
# 或者: from rango.forms.CategoryForm import is_valid [as 别名]
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)
开发者ID:geekpradd,项目名称:Blog-By-Pradd,代码行数:29,代码来源:views.py

示例13: add_page

# 需要导入模块: from rango.forms import CategoryForm [as 别名]
# 或者: from rango.forms.CategoryForm import is_valid [as 别名]
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)
开发者ID:wlowry88,项目名称:tango,代码行数:33,代码来源:views.py

示例14: add_category

# 需要导入模块: from rango.forms import CategoryForm [as 别名]
# 或者: from rango.forms.CategoryForm import is_valid [as 别名]
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)
开发者ID:andydtaylor,项目名称:rango,代码行数:28,代码来源:views.py

示例15: add_category

# 需要导入模块: from rango.forms import CategoryForm [as 别名]
# 或者: from rango.forms.CategoryForm import is_valid [as 别名]
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)
开发者ID:lf2225,项目名称:TangoWithDjango,代码行数:27,代码来源:views.py


注:本文中的rango.forms.CategoryForm.is_valid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。