def new(request): # Create if request.method == 'POST': form = PostForm(request.POST) if form.is_valid(): p = form.save() p.hash = (os.urandom(16)).encode('hex') p.set_isbn_int() # Send edit link to user send_mail( 'TimBoekTU edit link for ' + p.title, render_to_string('email_edit.html', {'post' : p}), '*****@*****.**', [p.email], fail_silently=True) p.save() return HttpResponseRedirect(reverse('timboektu.books.views.confirm', kwargs={'post_hash': p.hash})) # New else: form = PostForm() return render(request, 'edit.html', { 'form': form, })
def adddog(): ''' Post page ''' form = PostForm() if request.method == 'POST' and form.validate_on_submit(): new = Post(title=form.title.data, text=form.post.data, user=current_user, gender=form.gender.data, age=form.age.data) for split in form.tags.data.split(' '): tag = Tag.query.filter_by(tag_name=split).first() if tag is not None: new.tags.append(tag) images = request.files.getlist("upload") for img in images: ext = img.filename.split(".")[1] filename = str(int(time.time() * 1e6) + randint(300, 43242)) + '.' + ext image_file = os.path.join(APP.config['UPLOAD_FOLDER'], filename) img.save(image_file) new.images.append(Image(name=filename)) DB.session.add(new) DB.session.commit() return redirect(url_for('index')) return render_template('post.html', form=form, tags=TAGS)
def new_post(): form = PostForm() if form.validate_on_submit(): form.post.author_id = current_user.id db.session.add(form.post) db.session.commit() fragment.reset(posts_list) fragment.reset(user_info, current_user.id) flash('Your post has saved successfully.', 'info') return redirect(url_for('index')) return render_template('newpost.html', form=form)
def create_post(): form = PostForm(request.form) if form.validate_on_submit(): post = Post(form.title.data, form.author.data, form.published.data, form.permalink.data) db.session.add(post) try: db.session.commit() flash("Post added successfully!") except Exception, e: flash("%s", e) return redirect(url_for("backend.backend_list"))
def edit(request, post_hash): p = get_object_or_404(Post, hash=post_hash) # Update if request.method == 'POST': form = PostForm(request.POST, instance=p) if form.is_valid(): p.set_isbn_int() p.save() return HttpResponseRedirect(reverse('timboektu.books.views.index')) # Edit else: form = PostForm(instance=p) return render(request, 'edit.html', { 'form': form, 'post' : p })
def edit(request, post_hash): p = get_object_or_404(Post, hash=post_hash) # Update if request.method == 'POST': form = PostForm(request.POST, instance=p) if form.is_valid(): p.set_isbn_int() p.save() return HttpResponseRedirect(reverse('timboektu.books.views.detail', kwargs={'post_id': p.id})) # Edit else: form = PostForm(instance=p) return render(request, 'edit.html', { 'form' : form, 'post' : p, 'delete' : DELETE_THRESHOLD })
def new(request): c = {} c.update(csrf(request)) if request.method == 'POST': p = Post(date_published=datetime.now()) form = PostForm(request.POST, instance=p) if form.is_valid(): post = form.save(commit=False) post.save() return HttpResponseRedirect('/') else: form = PostForm() return render_to_response('ultra-simple-blog/new.html',{'form': form,})
def edit(request, post_id): c = {} c.update(csrf(request)) if request.method == 'POST': p = Post.objects.get(pk=post_id) form = PostForm(request.POST, instance=p) if(form.is_valid()): post = form.save(commit=False) post.date_modified = datetime.now() post.save() return HttpResponseRedirect('/ultra-simple-blog/' + str(post.id) + '/') else: post = Post.objects.get(pk=post_id) form = PostForm(instance=post) return render_to_response('ultra-simple-blog/edit.html', {'form': form, 'post': post})
def create(request): """Create a post. GET shows a blank form, POST processes it.""" user = users.GetCurrentUser() if user is None: # Now make them login. # See what we did in websites.py - this should happen here as well. login_url = users.create_login_url(request.get_full_path()) return http.HttpResponseRedirect(login_url) form = PostForm(data=request.POST or None) if not request.POST: return views.respond(request, user, 'posts/create', {'form': form}) errors = form.errors if not errors: try: post = form.save(commit=False) except ValueError, err: errors['__all__'] = unicode(err)
def profile(uid): tab = 'home' q = db.query(User).filter(User.id == uid) if q.count() == 0: abort(404) u = q.one() tpl = 'profile.html' form = PostForm(request.form) articles = db.query(Article).filter(Article.user_id == uid).limit(30) return render_template('/user/' + tpl, user=u, post_form=form, articles=articles, tab=tab)
def edit(request, key): """Edit a post. GET shows a blank form, POST processes it.""" user = users.GetCurrentUser() if user is None: return http.HttpResponseForbidden('You must be signed in to add or edit a post') post = None if key: post=Post.get(db.Key(unquote(key))) if post is None: return http.HttpResponseNotFound("No Post exists with that key") if post.author.user!=user: return http.HttpResponseForbidden('You can only edit your own posts') form = PostForm(data=request.POST or None, instance=post) if not request.POST: return views.respond(request, user, 'posts/edit', {'form': form, 'post': post}) errors = form.errors if not errors: try: post = form.save(commit=False) except ValueError, err: errors['__all__'] = unicode(err)
def new_post(request): #Return form for new Post if request.method == 'POST': form = PostForm(request.POST) post = form.save(commit=False) post.created = datetime.datetime.now() post.likes = 0 post.dislikes = 0 if request.user.is_authenticated(): post.owner = request.user else: post.owner = None if form.is_valid(): form.save() # Need to pass a message like "Thanks for making the world a geekier place!" return HttpResponseRedirect('/') else: form = PostForm() return short_render(request, 'new_post.html', {'form': form})