def new_blog_entry(request): """ TODO: Use Ajax in preview """ # user_profile = request.user.get_profile() # All accessible sites from the current user: # user_site_ids = user_profile.sites.values_list("id", "name") # m2m_limit = {"sites": user_site_ids} # Limit the site choice field with LimitManyToManyFields context = { "title": _("Create a new blog entry"), "form_url": request.path, "tag_cloud": BlogEntry.objects.get_tag_cloud(request), "add_tag_filter_link": False, # Don't add filters in tag cloud } if request.method == "POST": form = BlogEntryForm(request.POST) if form.is_valid(): instance = form.save() messages.success(request, _("New blog entry '%s' saved.") % instance.headline) return http.HttpResponseRedirect(instance.get_absolute_url()) else: # Get preferences pref_form = BlogPrefForm() initial = { "sites": get_site_preselection(pref_form, request), # preselect sites field "language": request.PYLUCID.current_language.pk, # preselect current language } form = BlogEntryForm(initial=initial) context["form"] = form return context
def create_blog(request): if request.method=='POST': # profile=User_record.objects.get(username=request.user.username).user_id form=BlogEntryForm(request.POST) if form.is_valid(): form.save(User_record.objects.get(username=request.user.username)) return HttpResponseRedirect('/') args={} args.update(csrf(request)) args['form']=BlogEntryForm return render_to_response('create_post.html',args )
def new_post(): form = BlogEntryForm(request.form) if request.method == 'POST' and form.validate(): blog_entry = BlogEntry(parent=utils.get_parent_key()) blog_entry.title = form.title.data blog_entry.body = form.body.data tag_str = form.tags.data blog_entry.tags = map(lambda x: x.strip(), tag_str.split(',')) blog_entry.save() return redirect(url_for('index')) return render_template('new_post.html', form=form)