def edit_post(request, post_id=None): item = get_object_or_404(Post, id=post_id) form = PostForm(request.POST or None, instance=item) if form.is_valid(): form.save() return redirect('/') return render(request, 'blog/post_form.html', {'form': form})
def classes_create(request): form = PostForm(request.POST or None, request.FILES or None) if form.is_valid(): create = form.save(commit=False) create.save() return redirect('home:class') args = {'form': form} return render(request, 'home/class_create.html', args)
def new_post(): form = PostForm() if form.validate_on_submit(): post = Post(title=form.title.data, content=form.content.data, author=current_user) db.session.add(post) db.session.commit() flash('Your Post has been created!', 'success') return redirect(url_for('home')) return render_template('create_post.html', title='New Post', form=form, legend='New Post')
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.title = form.title.data post.content = form.content.data db.session.commit() flash('Your post has been update!', 'success') return redirect(url_for('post', post_id=post.id)) form.title.data = post.title form.content.data = post.content return render_template('create_post.html', title='Update Post', form=form, legend='Update Post')
def classes_update(request, id): try: instance = Classes.objects.get(id=id) except Classes.DoesNotExist: instance = None form = PostForm(request.POST or None, instance=instance) if form.is_valid(): instance = form.save(commit=False) instance.save() return redirect(reverse('home:class')) context = { "title": instance.title, "instance": instance, 'form': form, } return render(request, "home/class_update.html", context)
def user_register(request): if (request.method=="POST"): postform = PostForm(request.POST, request.FILES) #print postform user_name = request.user postform.user = user_name if postform.is_valid(): profile = postform.save(commit=False) print profile.post profile.user = request.user profile.time=timezone.now() #print profile.user profile.save() messages.success(request, 'Your post submitted Successfully') else: postform = PostForm() return render(request, "home/post.html", { 'postform' : postform })
def add_post(request): if request.method == 'POST': form = PostForm(request.POST) next_url = request.POST.get('next', '/') if form.is_valid(): post = form.save(commit=False) post.user = request.user post.save() tags = form.cleaned_data['tags'].split(',') for tag in tags: post.tags.add(tag.strip()) post.save() return redirect(next_url) else: if 'public' in next_url: return public_posts(request, form) if 'user' in next_url: return user_page(request, request.user, form) return index(request, form) return redirect('home')
def post_create(request): if request.method == "POST": form = PostForm(request.POST) if form.is_valid() : form.save() return redirect('home:main') else : return HttpResponse("404") else : form = PostForm() return render(request, "home/post_create.html", {'form': form})
def post_new(request): form = PostForm() context = {} context['category'] = Category.objects.all() if request.method == "POST": form = PostForm(request.POST) context['form'] = form if form.is_valid(): post = form.save(commit=False) post.user = request.user # post.created = timezone.now() form.save() return redirect('/') return render(request, 'post_edit.html', context)
def post_update(request, slug_url): post = get_object_or_404(Post, slug=slug_url) if request.method == "POST": form = PostForm(request.POST, request.FILES, instance=post) if form.is_valid(): form.save() return redirect(post) else : return HttpResponse("404") else : form = PostForm(instance=post) return render(request, "home/post_create.html", {'form': form})
def add_post(request): if request.method == "POST": form = PostForm(request.POST) if form.is_valid(): post_item = form.save(commit=False) post_item.save() return redirect('/') else: form = PostForm() return render(request, 'blog/post_form.html', {'form': form})
def postblog(request): if request.method == "POST": title = request.POST.get('title', '') author = request.POST.get('author', '') content = request.POST.get('content', '') print('title: ', title, '\nauthor:', author, '\ncontetn:', content) postBlog = Post(title=title, author=author, content=content) postBlog.save() print(postBlog.save()) messages.success(request, "Successfully Posted Your Blog") return redirect('/postblog/') form = PostForm() return render(request, 'home/postYourBlog.html', {'form': form})
def get_write_post(request): update_context() pform = PostForm() if 'userid' not in request.session: return render(request, 'major/forbidden.html', context_default) classification = request.GET.get('board') board_rename = switch_urlname_to_board_name_trick(classification) addition = { 'form': pform, 'board_name': board_rename, 'classification': classification } merged = merge_dicts(context_default, document_context) return render(request, 'major/new_post.html', merge_dicts(merged, addition))
def CreatePost(request): if request.method == 'POST': form = PostForm(request.POST) if form.is_valid(): instance = form.save(commit=False) instance.author_name = request.user instance.save() messages.success(request, "Posted Successfully Article") return redirect('home:post_detail', instance.id) else: form = PostForm() context = {'form': form} return render(request, 'home/create_post.html', context)
def post(self, request): form = PostForm(request.POST) if form.is_valid(): post = form.save(commit=False) post.user = request.user post.save() text = form.cleaned_data['text'] form = PostForm() return redirect('home') args = {'form': form, 'text': text} return render(request, self.template_name, args)
def post(request): companies = Company.objects.get(id__exact=4) posts=Post.objects.get(Industry_id__exact=3) if request.method == 'POST': form = PostForm(request.POST, request.FILES or None) print(form.errors) if form.is_valid(): form.save() return redirect('home') else: form = PostForm() context = {'form' : form,'posts':posts,'companies':companies} return render(request,'home/contactform.html',context)
def post(self, request, pk): post = get_object_or_404(Post, pk=pk) form = PostForm(request.POST, instance=post) if form.is_valid(): post = form.save(commit=False) post.user = request.user post.save() text = form.cleaned_data['text'] form = PostForm(instance=post) return redirect('home') args = {'form': form, 'text': text} return render(request, self.template_name, args)
def post_edit(request, pk): post = get_object_or_404(forumPost, pk=pk) if request.method == "POST": form = PostForm(request.POST, instance=post) if form.is_valid(): post = form.save(commit=False) post.author = request.user post.is_edited = True post.publish() return thread_view(request, pk) else: form = PostForm(instance=post) return render(request, 'home/post_edit.html', {'form': form})
def post_edit(request, id): context = {} context['category'] = Category.objects.all() post = get_object_or_404(Post, id=id) if request.method == "POST": form = PostForm(request.POST, instance=post) context['form'] = form if form.is_valid(): post = form.save(commit=False) post.user = request.user post.created = timezone.now() post.save() return redirect('/post/%s' % id) else: form = PostForm(instance=post) return render(request, 'post_edit.html', context)
def post_new_thread(request, pk): if not request.user.is_authenticated(): return redirect('signlog_in') if request.method == "POST": form = PostForm(request.POST) else: form = PostForm() if form.is_valid(): post = form.save(commit=False) post.idUser = User.objects.get(username=request.user.username) post.forumSubCategory = forumSubCategory.objects.get(pk=pk) post.publish() post.save() return redirect('index') context = contextDefault.copy() title = 'Add new Post' context.update({'title': title, 'form': form}) return render(request, 'home/post_new.html', context)
def get(self, request): form = PostForm() args = {'form': form} return render(request, self.template_name, args)
def get(self, request, pk): post = get_object_or_404(Post, pk=pk) form = PostForm(instance=post) args = {'form': form} return render(request, self.template_name, args)
def submit_post(request): if (request.user.is_authenticated == False): return redirect("/signin") args = {'form_errors': [], 'recaptcha_errors': ''} if (request.method == "GET"): return render(request, "home/submit_post.html", args) elif (request.method == "POST"): is_nsfw = request.POST.get('isNsfw', False) is_spoiler = request.POST.get('isSpoiler', False) if (is_nsfw != False): is_nsfw = True if (is_spoiler != False): is_spoiler = True print("isNsfw: %s; isSpoiler: %s" % (is_nsfw, is_spoiler)) form = PostForm(request.POST) valid = True recaptcha_response = request.POST['g-recaptcha-response'] site_verify = "https://www.google.com/recaptcha/api/siteverify" secret = ReCaptcha_Secret verify_data = {'secret': secret, 'response': recaptcha_response} response = requests.post(site_verify, verify_data) list_response = json.loads(response.content) if (len(request.POST['title']) > 200 or len(request.POST['title']) == 0): valid = False args['form_errors'].append("Title must be 1-200 characters long") if (len(request.POST['content']) > 5000): valid = False args['form_errors'].append( "Content must be 5000 characters or less") if (str(list_response['success']) != 'True' and REQUIRE_VERIFIED_RECAPTCHA): valid = False args['recaptcha_errors'] = "Please Complete ReCaptcha Correctly" if (valid and form.is_valid()): submited_post = models.Post() submited_post.author = request.user.username submited_post.title = request.POST['title'] submited_post.content = request.POST['content'] submited_post.timestamp = datetime.datetime.utcnow() submited_post.isNsfw = is_nsfw submited_post.isSpoiler = is_spoiler tempId = "" foundId = False chars = string.ascii_uppercase + string.ascii_lowercase + string.digits + '-' + '_' while foundId == False: tempId = ''.join(random.choice(chars) for _ in range(7)) query = models.Post.objects.filter(post_id=tempId) if len(query) == 0: foundId = True submited_post.post_id = tempId submited_post.save() return redirect("/") return render(request, "home/submit_post.html", args)