本文整理汇总了Python中forms.ArticleForm类的典型用法代码示例。如果您正苦于以下问题:Python ArticleForm类的具体用法?Python ArticleForm怎么用?Python ArticleForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ArticleForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_xml_file
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
示例2: add_article
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()
示例3: submit_topic
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)
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_to_response('core/submit_topic.html',
context,
context_instance=RequestContext(request))
示例4: post_article
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))
示例5: new_article
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)
示例6: submit_topic
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)
topic.set_author(request.user)
topic.save()
topic.send_notification_mail('created')
context = {
'form': form,
'topic': topic,
'save_success': True
}
return render_to_response('core/submit_topic.html',
context,
context_instance=RequestContext(request))
示例7: edit_topic
def edit_topic(request, id):
this_topic = get_object_or_404(Topic, pk = id)
if this_topic.author.user != request.user:
return HttpResponseRedirect(reverse('topic', args=[this_topic.id]))
if request.method == 'GET':
context = {
'form': ArticleForm(instance = this_topic),
'topic': this_topic,
'tab': 'topic',
}
return render_to_response('core/edit_topic.html',
context,
context_instance=RequestContext(request))
if request.method == 'POST':
form = ArticleForm(request.POST, instance=this_topic)
topic = form.save(commit=False)
topic.set_author(request.user)
topic.save()
topic.send_notification_mail('updated')
context = {
'form': form,
'topic': topic,
'edit_success': True,
'tab': 'topic',
}
return render_to_response('core/edit_topic.html',
context,
context_instance=RequestContext(request))
示例8: index
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: create
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)
示例10: form_article
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: article_new
def article_new():
form = ArticleForm(request.form)
if form.validate():
try:
db.save(Article(current_user, form.title.data, form.content.data, form.plain_text.data))
except AssertionError, err:
current_app.logger.error(err)
return redirect(url_for('Common.index'))
示例12: nouveau
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: create
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)
示例14: add_article
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))
示例15: add_article
def add_article():
form = ArticleForm(request.form)
if request.method == 'POST' and form.validate():
sql = sqlpuzzle.insert_into('article').values({
'title': form.title.data,
'text': form.text.data,
})
cur = get_db().cursor()
cur.execute(str(sql))
return redirect(url_for('article_page.articles'))
return render_template('article/add.html', form=form)