本文整理汇总了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',
})
示例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
示例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))
示例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)
示例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)
示例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())
示例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)
示例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})
示例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)
示例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
示例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)
示例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))
示例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() )
示例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)
示例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)