def post(self, request): form = PostForm(request.POST) if not form.is_valid(): context = {'form': form} return render(request, self.template_name, context) return HttpResponse('ok')
def newpost(request): form = PostForm(request.POST) if form.is_valid(): cur_user = request.user title = form.cleaned_data.get('title') price = form.cleaned_data.get('price') description = form.cleaned_data.get('description') poster = cur_user.id category = form.cleaned_data.get('category') subcategory = form.cleaned_data.get('subcategory') Post.objects.create(title=title, price=price, description=description, poster=poster, category=category) HttpResponseRedirect('/newpostsuccess') else: print('form not valid') HttpResponseRedirect('/')
def topic(request, topic_id): now = datetime.now() topic = get_object_or_404(Topic, pk=topic_id) posts = Post.objects.filter(topic=topic) if request.method == 'POST': form = PostForm(request.POST) if form.is_valid(): post = form.cleaned_data['post'] Post.objects.create( topic=topic, user=request.user, created=now, updated=now, body=post, body_html=post, body_text=post) return redirect('profile') else: form = PostForm() return render( request, 'core/topic.html', { 'form': form, 'topic': topic, 'posts': posts })
def novo(request): form = PostForm(request.POST or None) if request.method == 'POST': if form.is_valid(): form.save() return redirect(lista) return render(request, 'core/novo.html', {'form': form})
def atualiza(request, id): post = Post.objects.get(id=id) form = PostForm(request.POST or None, instance=post) if form.is_valid(): form.save() return redirect(lista) return render(request, 'core/novo.html', {'form': form})
def post(request): if request.POST: novo = PostForm(request.POST) if novo.is_valid(): novo.save() else: novo = PostForm contexto = {'title': 'Post', 'post': Post.objects.all()} return render(request, 'post.html', contexto)
def new(request): form = PostForm(request.POST or None) if request.method == 'POST': if form.is_valid(): form.save() return redirect('index') return render(request, 'core/new.html', {'form': form})
def add_post(request): form = PostForm(request.POST or None) if form.is_valid(): post = form.save(commit=False) post.author = request.user post.save() return redirect(post) return render_to_response('core/add_post.html', { 'form': form }, context_instance=RequestContext(request))
def update(request, id): post = Post.objects.get(id=id) form = PostForm(request.POST or None, instance=post) if request.method == 'POST': if form.is_valid(): form.save() return redirect('index') return render(request, 'core/edit.html', {'form': form})
def edit_save_post(id_post): form = PostForm(request.form) if request.method == 'POST' and form.validate(): blog = Routes.response_sql() title = form.title.data content = form.content.data p = Post.query.filter_by(id_post=id_post, status=1) if p.count() == 1: p.update(dict(title=title, content=content)) db.session.commit() return redirect(url_for('admin.default'))
def home(): form = PostForm() if form.validate_on_submit(): post = Post(fact=form.fact.data, source=form.source.data, author=current_user) db.session.add(post) db.session.commit() flash('Your post has been added!', 'success') return redirect(url_for('home')) posts = Post.query.order_by(Post.date_posted.desc()).all() return render_template('home.html', form=form, posts=posts, current_user=current_user)
def index(request): newpostform = PostForm() return render(request, 'core/index.html', { 'categories': get_categories(), 'form': newpostform })
def post_edit(request, pk): page = "post-edit-page" current_user = request.user post = Post.objects.get(pk=pk) if current_user.userprofile != post.creator: context = { 'current_user': current_user, 'page': page, } return render(request, 'access-denied.html', context) if request.method == 'GET': post_form = PostForm(instance=post) context = { 'post': post, 'post_form': post_form, 'current_user': current_user, 'page': page, } return render(request, 'post-edit.html', context) post_form = PostForm(request.POST, request.FILES, instance=post) if post_form.is_valid(): post_form.save() return redirect('post details', post.pk) context = { 'post_form': post_form, 'current_user': current_user, 'page': page, } return render(request, 'post-edit.html', context)
def update_post(post_id): post = Post.query.get_or_404(post_id) if post.author != current_user: abort(403) form = PostForm() if form.validate_on_submit(): post.fact = form.fact.data post.source = form.source.data db.session.commit() flash('Your post has been updated!', 'success') return redirect(url_for('home')) elif request.method == 'GET': form.fact.data = post.fact form.source.data = post.source return render_template('update_post.html', title='Update Post', form=form, legend='Update Post')
def index(): form = PostForm() if form.validate_on_submit(): language = guess_language(form.post.data) if language == 'UNKNOWN' or len(language) > 5: language = '' post = Post(body=form.post.data, author=current_user, language=language) db.session.add(post) db.session.commit() flash('Your post is now live!') return redirect(url_for('index')) page = request.args.get('page', 1, type=int) posts = current_user.followed_posts().paginate( page, app.config['POSTS_PER_PAGE'], False) return render_template('index.html', title='Home', form=form, posts=posts.items)
def save_post(): form = PostForm(request.form) if request.method == 'POST' and form.validate(): blog = Routes.response_sql() title = form.title.data content = form.content.data p = Post( title=title, content=content, blog_id=blog.id_blog, create_date=datetime.datetime.now(), update_date=datetime.datetime.now(), status=1, ) if 'tag' in request.form.keys() and request.form['tag'] != '': tag_post = request.form['tag'].split() tag_list = list() for tag in tag_post: tag_query = Tag.query.filter_by(name=tag_post) if tag_query.count() == 1: id_tag = tag_query.first().id_tag else: tag_model = Tag( name=tag, create_date=datetime.datetime.now(), update_date=datetime.datetime.now(), status=1, ) tag_list += [tag_model] if len(tag_list) > 0: db.session.add_all(tag_list) db.session.commit() id_tag = db.session.query(Tag).order_by( Tag.id_tag.desc()).first().id_tag p.tag_id = id_tag db.session.add(p) db.session.commit() return redirect(url_for('admin.default'))
def post_new(request): if request.method == "POST": form = PostForm(request.POST) if form.is_valid(): post = form.save(commit=False) post.posted_by = request.user post = form.save() return redirect(post.get_absolute_url()) else: form = PostForm() return render(request, 'core/post_new.html', {'form': form})
def add_post(request): if request.method == 'POST': form = PostForm(request.POST, request.FILES) currentuser = request.user if form.is_valid(): obj = form.save(commit=False) obj.create_by = request.user obj.slug = slugify(obj.title) obj.save() form.save_m2m() return redirect('home') else: form = PostForm() return render(request, 'core/postform.html', {'form': form})
def new_post(request): if request.method == "POST": form = PostForm(request.POST) if form.is_valid(): post = form.save(commit=False) post.user = request.user post.save() return redirect('index') else: form = PostForm() return render(request, 'user_post.html', {'form': form})
def postCreate(request): if request.method == "POST": form = PostForm(request.POST, request.FILES) if form.is_valid(): post = form.save(commit=False) post.author = request.user post.image = request.FILES.get('image') post.video = request.FILES.get('video') post.save() return redirect("core:post", pk=post.pk) else: form = PostForm() return render(request, "core/post_create.html", {"form": form})
def post_create(req): page = "post-create-page" if req.method == 'GET': context = { 'current_user': req.user, 'form': PostForm(), 'page': page, } return render(req, 'post-create.html', context) creator_obj = req.user.userprofile creator_post = Post(creator=creator_obj) form = PostForm(req.POST, req.FILES, instance=creator_post) if form.is_valid(): form.save() return redirect('post list') context = { 'form': form, 'current_user': req.user, 'page': page, } return render(req, 'post-create.html', context)
def get(self, request): context = {} context['form'] = PostForm() return render(request, self.template_name, context)