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


Python ArticleForm.save方法代码示例

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


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

示例1: save_article

# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import save [as 别名]
def save_article(request, article_id=None):
    article = None
    if article_id:
        article = get_object_or_404(Article, id=article_id, user=request.user)
        form = ArticleForm(request.POST, instance=article)

        if 'delete' in request.POST:
            article.delete()
            messages.add_message(request, messages.INFO, _(u'The article “%s” has been deleted.') % article.name)
            return redirect('management:index')

    else:
        form = ArticleForm(request.POST)

    if form.is_valid():
        if article_id:
            form.save()
        else:
            article = form.save(commit=False)
            article.user = request.user
            article.save()
            article_id = article.id

        messages.add_message(request, messages.SUCCESS, _(u'The article is saved.'))
        return redirect('management:article', article_id=article_id)

    return response(request, 'edit_article.html', {
        'article': article,
        'article_form': form,
        'article_id': article_id,
        'page_type': 'article',
    })
开发者ID:vladmos,项目名称:photoblog,代码行数:34,代码来源:views.py

示例2: parse_xml_file

# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import save [as 别名]
def parse_xml_file(file):
	context = etree.iterparse(file)
	article_dict = {}
	date_dict = {}
	articles = []
	
	tokenizer = nltk.data.load('tokenizers/punkt/english.pickle')
	
	for action, elem in context:
		if not elem.text:
			text = "None"
		else:
			text = elem.text
		if elem.tag == "article":
			articles.append(article_dict)
			article = ArticleForm(article_dict, tokenizer=tokenizer)
			article.save()
			article_dict = {}
		elif elem.tag == "day" or elem.tag == "month" or elem.tag == "year":
			date_dict[elem.tag] = text
		elif elem.tag == "date":
			month_name = date_dict['month']
			month_number = strptime(month_name, '%B').tm_mon
			date = datetime.date(int(date_dict['year']), month_number, int(date_dict['day']))
			article_dict["date"] = date
			date_dict = {}
		else:
			article_dict[elem.tag] = text
开发者ID:archchoa,项目名称:netcentric,代码行数:30,代码来源:tools.py

示例3: submit_topic

# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import save [as 别名]
def submit_topic(request):
    if request.method == 'GET':
        form = ArticleForm()
        form.fields['in_event'].queryset = Event.objects.upcoming_events()

        context = {'form': form,
                   'tab': 'topic',
                }
        return render_to_response('core/submit_topic.html',
                                    context,
                                    context_instance=RequestContext(request))

    if request.method == 'POST' :
        form = ArticleForm(request.POST)
        topic = form.save(commit=False)
        if request.POST['captcha'] == '':
            topic = form.save(commit=False)
            topic.set_author(request.user)
            topic.save()
            topic.send_notification_mail('created')
        
        context = {
            'form': form,
            'save_success': True
        }
        
        return render_to_response('core/submit_topic.html',
                                    context,
                                    context_instance=RequestContext(request))
开发者ID:haiger,项目名称:openparty,代码行数:31,代码来源:views.py

示例4: submit_topic

# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import save [as 别名]
def submit_topic(request):
    if request.method == 'GET':
        form = ArticleForm()
        form.fields['in_event'].queryset = Event.objects.upcoming_events()

        context = {
          'form': form,
          'tab': 'topic',
        }
        return render(request, 'core/submit_topic.html', context)

    if request.method == 'POST' :
        form = ArticleForm(request.POST)
        context = {
            'form': form,
            'save_success': False,
        }

        if form.is_valid():
          topic = form.save(commit=False)
          if request.POST['captcha'] == '':
              topic = form.save(commit=False)
              topic.set_author(request.user)
              topic.save()
              topic.send_notification_mail('created')
              context['save_success'] = True
          else:
              return HttpResponseForbidden()

        return render(request, 'core/submit_topic.html', context)
开发者ID:Suave,项目名称:openparty,代码行数:32,代码来源:views.py

示例5: form_article

# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import save [as 别名]
def form_article(request, id_article=None):
	if request.method == "POST":
		request.POST['last_editor_id'] = cache.get('user_id')
		if id_article:
			article = Article.objects.get(id=id_article)
			form = ArticleForm(request.POST, instance=article)
		else:
			request.POST['author_id'] = cache.get('user_id')
			form = ArticleForm(request.POST)

		if form.is_valid():
			form.save()
			return redirect(request.META.get('HTTP_REFERER','/'))
	else: #GET
		id_article = request.GET.get('id_article', None)
		args = {}
		args.update(csrf(request))
		if id_article:
			article = Article.objects.get(id=id_article)
			args['id_article'] = id_article
			args['form'] = ArticleForm(instance=article)
		else:
			args['form'] = ArticleForm()

		return render_to_response('edit_article.html', args)
开发者ID:RitaTim,项目名称:caminho_do_capo,代码行数:27,代码来源:views.py

示例6: nouveau

# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import save [as 别名]
def nouveau(request):
    form = ArticleForm(request.POST)
    if form.is_valid():
            form.save()
            envoi= True
    else:
        form = ArticleForm()

    return render(request, 'nouveau.html', locals())
开发者ID:cedricmeston,项目名称:pierrecedric,代码行数:11,代码来源:views.py

示例7: create

# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import save [as 别名]
def create(request):
	form = ArticleForm(request.POST, request.FILES)
	if form.is_valid():
		form.save()
		return HttpResponseRedirect('/articles/all')
	args = {}
	args.update(csrf(request))
	args['form'] = form
	return render_to_response('create_article.html', args)
开发者ID:itssiva,项目名称:django_test,代码行数:11,代码来源:views.py

示例8: article_name

# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import save [as 别名]
def article_name(request):
    if request.method == 'POST':
        form = ArticleForm(request.POST)
        if form.is_valid():
            print form.cleaned_data
            form.save()
        return HttpResponseRedirect('redirect/')
    else:
        form = ArticleForm()

    return render(request, 'article.html', {'form': form})
开发者ID:KeyFire,项目名称:renewed,代码行数:13,代码来源:views.py

示例9: create

# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import save [as 别名]
def create(request):
    if request.POST:
        form = ArticleForm(request.POST, request.FILES)  #this binds data to the form
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/articles/all')
    else:
        form = ArticleForm()
    args = {}
    args['form'] = form
    return render(request, 'article/create_article.html', args)
开发者ID:gyrodecl,项目名称:django_yt,代码行数:13,代码来源:viewsBackupToLesson19.py

示例10: create_article

# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import save [as 别名]
def create_article(request):
    values = {}
    values.update(csrf(request))
    values['form'] = ArticleForm()
    page = render_to_response("create_article.html", values)
    if request.POST:
        form = ArticleForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            page = HttpResponseRedirect('/articles/all')

    return page
开发者ID:Karlos7692,项目名称:UDemy,代码行数:14,代码来源:views.py

示例11: create

# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import save [as 别名]
def create(request):
    if request.method == "POST":
        form = ArticleForm(request.POST)
        if form.is_valid():
            form.save()
            return render_to_response('index.html')
    else:
        form = ArticleForm(request.POST)
        con = {}
        con.update(csrf(request))
        con['form'] = form
        return render_to_response("form.html",con)
开发者ID:Mayank91,项目名称:Login-Logout-Django,代码行数:14,代码来源:views.py

示例12: editwiki

# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import save [as 别名]
def editwiki(request, wiki_id):
    wiki = Article.objects.get(id = wiki_id)
    editform = ArticleForm(request.POST or None, instance=wiki)
    if request.method == 'POST':
        if editform.is_valid():
            editform.save()
            return HttpResponseRedirect('/wikis/all')
    args = {}
    args.update(csrf(request))
    args['editform'] = editform
    return render_to_response('editwiki.html',
                         args, context_instance=RequestContext(request))
开发者ID:param107,项目名称:wiki_article,代码行数:14,代码来源:views.py

示例13: modifier

# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import save [as 别名]
def modifier(request, id, slug):
     article = get_object_or_404(Article, id=id, slug=slug)
     form = ArticleForm(request.POST, instance=article)
     if form.is_valid():
            form.save()
            article = form.save()
            article.save()
            envoi= True
     else:
        form = ArticleForm(instance=article)

     return render(request, 'modifier.html', locals() )
开发者ID:cedricmeston,项目名称:pierrecedric,代码行数:14,代码来源:views.py

示例14: create

# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import save [as 别名]
def create(request):
    if request.POST:
        form = ArticleForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect("/")
    else:
        form = ArticleForm()

    args = {}
    args.update(csrf(request))
    args['form'] = form

    return render_to_response("create_article.html",args)
开发者ID:cyberomin,项目名称:GistSquare,代码行数:16,代码来源:views.py

示例15: create

# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import save [as 别名]
def create(request):
	if request.POST:
		form = ArticleForm(request.POST, request.FILES)
		if form.is_valid():
			form.save()
			
			return HttpResponseRedirect('/articles/all/')
	else:
		form = ArticleForm()

	context = {}
	context.update(csrf(request))
	context['form'] = form
	return render(request, 'create_article.html', context)
开发者ID:HansKappert,项目名称:MyProjects,代码行数:16,代码来源:views.py


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