def post(self, request): form = MemoForm(request.POST) if form.is_valid(): MemoModel.objects.create(username=form.clean_data['username'], message=form.clean_data['message'], time=datetime.now()) return HttpResponseRedirect('/memo/')
def create(): form = MemoForm(request.form) app.logger.debug("Create") app.logger.debug(form.validate_on_submit()) if form.validate_on_submit(): if "Memo" in request.form: dtDate = arrow.utcnow() put_memo(dtDate, request.form["Memo"]) return redirect(url_for('index')) return flask.render_template('create.html', form=form)
def memo_handler(request): if MemoModel.objects.count() >= 10: recent_message = MemoModel.objects.order_by('time')[-10:] else: recent_message = MemoModel.objects.all() if request.method == 'POST': form = MemoForm(request.POST) if form.is_valid(): print form.cleaned_data MemoModel.objects.create(username=form.cleaned_data['username'], message=form.cleaned_data['message'], time=datetime.now()) return render(request, 'memo.html', {'historys': recent_message})
def get(self, request): form = MemoForm() if MemoModel.objects.count() >= 10: recent_message = MemoModel.objects.order_by('time')[-10:] else: recent_message = MemoModel.objects.all() return render(request, 'memo.html', { 'form': form, 'historys': recent_message })
def show_main(request): if request.method == 'GET': template = 'memos/main.html' memos = Memo.objects.filter(user=request.user).order_by('-update_date') tags = Tag.objects.filter(user=request.user) return common_django.render(request, template, {'memos': memos, 'tags': tags}) else: template = 'memos/main.html' form = MemoForm(request.POST) if form.is_valid(): new_memo = form.save(commit=False) new_memo.user = request.user new_memo.save() new_memo.tags = request.POST.getlist("tags") new_memo.save() return HttpResponseRedirect('/memos/') else: memos = Memo.objects.filter(user=request.user).order_by('-update_date') tags = Tag.objects.filter(user=request.user) return common_django.render(request, template, {'form': form, 'memos': memos, 'tags': tags})