本文整理汇总了Python中forms.ArticleForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python ArticleForm.is_valid方法的具体用法?Python ArticleForm.is_valid怎么用?Python ArticleForm.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.ArticleForm
的用法示例。
在下文中一共展示了ArticleForm.is_valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import is_valid [as 别名]
def create(request):
# profile_id = random.randint(0,32768)
if request.method == "POST":
form = ArticleForm(request.POST, request.FILES)
if form.is_valid():
profile_id = request.POST["psrn"]
a = form.save()
a.psrn = profile_id
a.save()
print profile_id
jform = JobForm()
args = {}
args.update(csrf(request))
args["form"] = jform
args["profile_id"] = profile_id
return render_to_response("job.html", args)
else:
form = ArticleForm()
args = {}
args.update(csrf(request))
args["form"] = form
return render_to_response("create_profile.html", args)
示例2: submit_topic
# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import is_valid [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':
if request.method == 'POST':
form = ArticleForm(request.POST)
context = {}
if form.is_valid():
topic = form.save(commit=False)
topic.set_author(request.user)
topic.save()
context['topic'] = topic
context['save_success'] = True
topic.send_notification_mail('created')
else:
context['save_success'] = False
context['form'] = form
return render_to_response('core/submit_topic.html',
context,
context_instance=RequestContext(request))
示例3: add_article
# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import is_valid [as 别名]
def add_article(request):
args = {}
args.update(csrf(request))
form = ArticleForm()
if request.user.is_authenticated():
if request.POST:
article_form = ArticleForm(request.POST, request.FILES)
if article_form.is_valid():
new_article = models.Article(user=request.user, title=article_form.cleaned_data['title'],
text=article_form.cleaned_data['text'], image=request.FILES['image'])
# article_form.user_id = request.user.id
# article_form.likes = 0
# article_form.save()
new_article.save()
return response.HttpResponseRedirect('/article/getarticles/')
else:
args['form'] = form
return render_to_response('add_article.html', args)
else:
raise PermissionDenied()
示例4: new_article
# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import is_valid [as 别名]
def new_article(request):
blogger = user_in_group(request.user, 'Blogger')
if blogger:
if request.method == 'POST':
# if POST save the article
form = ArticleForm(request.POST)
if form.is_valid():
article = form.save(commit=False)
article.written_by = request.user
article.save()
return redirect(my_articles)
else:
# if GET create article form
form = ArticleForm()
data = {
'page_header': 'My Articles',
'page_subheader': 'New Article',
'form': form,
'admin': user_in_group(request.user, 'Admin'),
'blogger': blogger
}
return render_to_response('new_edit_article.html', data, context_instance=RequestContext(request))
else:
return HttpResponse(status=403)
示例5: submit_topic
# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import is_valid [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)
示例6: post_article
# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import is_valid [as 别名]
def post_article(request,
success_url = "/",
template="articles/post.html"):
""" Post new article """
if request.method == 'POST':
form = ArticleForm(request.POST)
if form.is_valid():
title = form.cleaned_data['title']
content = form.cleaned_data['content']
tags = form.cleaned_data['tags']
# new article
art = Article(title=title,content=content,slug=slugify(title),author=request.user)
art.save()
# add tags
for tag in tags:
try:
t = Tag.objects.get(name=tag)
except Tag.DoesNotExist:
t = None
# if t doesnt exist
if t is None:
t = Tag(name=tag,slug=slugify(tag))
t.save()
# add the tag to the article
art.tags.add(t)
# set meta
art.set_meta()
# done here
return HttpResponseRedirect(success_url)
else:
form = ArticleForm()
return render_to_response(template,
{'form':form},
context_instance=RequestContext(request))
示例7: save_article
# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import is_valid [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',
})
示例8: index
# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import is_valid [as 别名]
def index(request):
latest_article_list = Article.objects.all().order_by('-post_date')[:5]
form = ArticleForm()
template = loader.get_template('index.html')
# user = User.objects.get(pk=User.pk)
if request.user.is_active:
# if user is not None:
return render_to_response('index.html', { 'form': form, 'posts': latest_article_list })
elif request.user.is_active != False and latest_article_list is not None:
return render_to_response('index.html', { 'posts': latest_article_list })
else:
return render_to_response('index.html', { }, context_instance=RequestContext(request))
if request.method == 'POST':
if form.is_valid():
postedArticle = Article()
postedArticle.post_date = timezone.now()
postedArticle.title = request.POST.getlist('title')
postedArticle.article = request.POST.getlist('article')
postedArticle.save()
else:
form = ArticleForm(instance=article)
return render_to_response('index.html', { 'form': form, 'posts': latest_article_list }, context_instance=RequestContext(request))
示例9: article
# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import is_valid [as 别名]
def article(request, name = None):
context = get_context(request)
new = (name is None)
if new:
art = None
title = u'Nowy artykuł'
has_perm = request.user.has_perm('wwwapp.add_article')
else:
art = Article.objects.get(name=name)
title = art.title
has_perm = request.user.has_perm('wwwapp.change_article')
if has_perm:
if request.method == 'POST':
form = ArticleForm(request.user, request.POST, instance=art)
if form.is_valid():
article = form.save(commit=False)
article.modified_by = request.user
article.save()
form.save_m2m()
return redirect('article', form.instance.name)
else:
form = ArticleForm(request.user, instance=art)
else:
form = None
context['addArticle'] = new
context['title'] = title
context['article'] = art
context['form'] = form
return render(request, 'article.html', context)
示例10: form_article
# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import is_valid [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)
示例11: create
# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import is_valid [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)
示例12: nouveau
# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import is_valid [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())
示例13: add_article
# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import is_valid [as 别名]
def add_article(request):
form = ArticleForm(request.POST or None)
if form.is_valid():
article = form.save(commit=False)
article.author = request.user
article.save()
msg = "Article saved successfully"
messages.success(request, msg, fail_silently=True)
return redirect(article)
return render_to_response('wiki/article_form.html', {'form': form }, context_instance=RequestContext(request))
示例14: add_article
# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import is_valid [as 别名]
def add_article(request):
form = ArticleForm(request.Post or None)
if form.is_valid(): # if something was typed in the form do
article = form.save(commit = False)
article.author = request.user
article.save()
msg = " Article was saved successfully"
message.sucess(request , msg , fail_silently = True)
return redirect(article)
return render_to_response('wiki/article_form.html', dict (form = form ), context_instance = RequestContext(request))
示例15: create
# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import is_valid [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)