def new_post(): form = PostForm() if form.validate_on_submit(): post = Post(title=form.title.data, customer=form.customer.data, microscope=form.microscope.data, country=form.country.data, date_req = form.date_req.data, problem_disc = form.problem_disc.data, os = form.os.data, digistar = form.digistar.data, gis = form.gis.data, people_inv = form.people_inv.data, actions = form.actions.data, spares = form.spares.data, date_fix =form.date_fix.data, warranty = form.warranty.data, notes = form.notes.data, archived = form.archived.data, author=current_user) db.session.add(post) db.session.commit() flash('Post created!', 'success') return redirect(url_for('home')) return render_template('create_post.html', title='New Post', form=form, legend='New Post')
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('Post Successfully Updated', 'success') return redirect(url_for('post', post_id=post.id)) elif request.method == 'GET': 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 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.customer = form.customer.data post.microscope = form.microscope.data post.country = form.country.data post.date_req = form.date_req.data post.problem_disc = form.problem_disc.data post.os = form.os.data post.digistar = form.digistar.data post.gis = form.gis.data post.people_inv = form.people_inv.data post.actions = form.actions.data post.spares = form.spares.data post.date_fix =form.date_fix.data post.warranty = form.warranty.data post.notes = form.notes.data post.archived = form.archived.data db.session.commit() flash('Post updated', 'success') return redirect(url_for('post', post_id=post.id)) elif request.method == 'GET': form.title.data = post.title form.customer.data = post.customer form.country.data = post.country form.microscope.data = post.microscope form.date_req.data = post.date_req form.problem_disc.data = post.problem_disc form.os.data = post.os form.digistar.data = post.digistar form.gis.data = post.gis form.people_inv.data = post.people_inv form.actions.data = post.actions form.spares.data = post.spares form.date_fix.data = post.date_fix form.warranty.data = post.warranty form.notes.data = post.notes post.archived = form.archived.data return render_template('create_post.html', title='Update Post', form=form, legend='Update Post')
def update_post(request, pk): blog = Post.objects.get(id=pk) form = PostForm(instance=blog) if request.method == 'POST': form = PostForm(request.POST, request.FILES, instance=blog) if form.is_valid(): form.save() return redirect('admin') else: form = PostForm() context = {'blog': blog, 'form': form} return render(request, 'admin/update_post.html', context)
def new_post(): form = PostForm() if form.validate_on_submit(): if form.picture.data: picture_file = save_post_picture(form.picture.data) post = Post(title=form.title.data, content=form.content.data, image_file=picture_file, author=current_user) db.session.add(post) db.session.commit() else: 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 successfully!', 'success') return redirect(url_for('home')) return render_template('create_post.html', title='New Post', form=form)
def update_product(request, pk): items = Item.objects.get(id=pk) form = PostForm(instance=items) if request.method == 'POST': form = PostForm(request.POST, request.FILES, instance=items) if form.is_valid(): form.save() return redirect('admin') else: form = ItemForm() context = {'items': items, 'form': form} return render(request, 'admin/update_product.html', context)
def post(request): if request.method == 'POST': form = PostForm(request.POST, request.FILES) if form.is_valid(): form.save() return redirect('admin') else: form = PostForm() context = { 'form': form, } return render(request, 'admin/post.html', context)
def add_post(): form = PostForm(request.form) if request.method == 'POST': title = form.title.data text = form.text.data test_result = test_add_post(form) if test_result == "success": post = Post(current_user.id, title, text) db.session.add(post) db.session.commit() return redirect(url_for("stories")) else: data = {'err_msg':test_result} return render_template('add_post.html',form = form, data = data) else: return render_template('add_post.html', form=form)
def post(self, request): global seq, snon, columns columns = ['id', 'date', 'transfer', 'fee', 'total', 'bank'] form = PostForm(request.POST) but = request.POST.get('submit') if form.is_valid(): name = form.cleaned_data['name'] start = form.cleaned_data['start_date'] end = form.cleaned_data['end_date'] transactions = Transaction.objects.filter(name__contains=name, date__range=[start, end]) filename = 'C:/Users/acer e15/Desktop/aviata/docs/api.json' myfile = open(filename, 'r', encoding='Latin-1') json_data = json.load(myfile) equal = [] notequal = [] for data in json_data: if data['payment_code'] == name.upper(): tr = Transaction.objects.filter(id=data['order_id']) if len(tr) > 0: for i in tr: if i.transfer == data['payment_amount']: a = Data(i.id, i.date, i.transfer, i.fee, i.total, i.name) b = Data( data['order_id'], datetime.datetime.date( parser.parse(data['date_created'])), data['payment_amount'], 0, data['payment_amount'], 'Chocotravel/Aviata') equal.append(a) equal.append(b) else: a = Data(i.id, i.date, i.transfer, i.fee, i.total, i.name) b = Data( data['order_id'], datetime.datetime.date( parser.parse(data['date_created'])), data['payment_amount'], 0, data['payment_amount'], 'Chocotravel/Aviata') notequal.append(a) notequal.append(b) seq = equal snon = notequal args = {'form': form, 'equal': equal, 'notEqual': notequal} # tr = Transaction.objects.filter(id=4) # return redirect('/transaction') # check isequal or not # args = {'form': form, 'transactions': transactions} return render(request, self.template_name, args) if (but == "download"): global seq response = HttpResponse(content_type='text/csv') response[ 'Content-Disposition'] = 'attachment;filename=export_equal.csv' writer = csv.writer(response) writer.writerow(columns) for obj in seq: writer.writerow([getattr(obj, field) for field in columns]) return response if (but == "nondownload"): global snon response = HttpResponse(content_type='text/csv') response[ 'Content-Disposition'] = 'attachment;filename=export_not_equal.csv' writer = csv.writer(response) writer.writerow(columns) for obj in snon: writer.writerow([getattr(obj, field) for field in columns]) return response
def get(self, request): form = PostForm() return render(request, self.template_name, {'form': form})