• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python forms.CategoryForm类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_blank_data

 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,代码行数:7,代码来源:test_forms.py


示例2: add_category

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,代码行数:28,代码来源:views.py


示例3: add_category

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,代码行数:25,代码来源:views.py


示例4: add_category

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,代码行数:26,代码来源:views.py


示例5: add_category

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,代码行数:28,代码来源:views.py


示例6: add_category

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})
开发者ID:aeklant,项目名称:tango_with_django,代码行数:32,代码来源:views.py


示例7: add_category

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,代码行数:27,代码来源:views.py


示例8: add_category

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)
开发者ID:jpmbrito,项目名称:Tango-with-Django,代码行数:28,代码来源:views.py


示例9: add_category

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,代码行数:25,代码来源:views.py


示例10: add_category

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})
开发者ID:STAbraham,项目名称:ProjectTango,代码行数:25,代码来源:views.py


示例11: add_category

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,代码行数:27,代码来源:views.py


示例12: add_category

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,代码行数:33,代码来源:views.py


示例13: add_category

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)
开发者ID:jochasinga,项目名称:tango-django,代码行数:35,代码来源:views.py


示例14: add_category

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,代码行数:26,代码来源:views.py


示例15: add_category

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,代码行数:29,代码来源:views.py


示例16: add_page

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,代码行数:31,代码来源:views.py


示例17: add_category

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)
开发者ID:dasgoll,项目名称:tango_with_django,代码行数:30,代码来源:views.py


示例18: add_category

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,代码行数:26,代码来源:views.py


示例19: add_category

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,代码行数:26,代码来源:views.py


示例20: add_category

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})
开发者ID:MehmetZorlu07,项目名称:tango_with_django_project,代码行数:10,代码来源:views.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python forms.PageForm类代码示例发布时间:2022-05-26
下一篇:
Python bing_search.run_query函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap