def new_note(request): if request.method == 'POST' and 'b2' in request.POST : form = NewNote(request.POST) if form.is_valid(): new = Note() new.owner = request.session['username'] new.head = form.cleaned_data["heading"] new.content = form.cleaned_data["content"] con = Markdown() new.md = con.convert(new.content) new.save() return HttpResponseRedirect("./") if request.method == 'POST' and 'b1' in request.POST : form = NewNote(request.POST) if form.is_valid(): con=Markdown() request.session['temp'] = con.convert(form.cleaned_data['content']) return HttpResponseRedirect('preview') data = [i for i in Note.objects.all() if i.owner == request.session['username']] context = dict() context['data'] = data context['form'] = NewNote() context['username'] = request.session['username'] temp = loader.get_template('notes/newnote.html') return HttpResponse(temp.render(context, request))
def newnote(): try: from models import Note note = Note() note.category_id = request.form['category'] note.content = request.form['content'] note.title = request.form['title'] db.session.add(note) db.session.flush() db.session.commit() return jsonify({'id': note.id}) except: db.session.rollback() abort(500)
def _ajax(request): """Wrapper""" if not request.is_ajax(): return {'status': 403} a = request.POST.get('a') if a not in ['move', 'edit', 'delete', 'new']: return {'status': 403} if a in ['move', 'edit', 'delete']: n = request.POST.get('note') id = int(n[5:]) note = get_object_or_404(Note, pk=id) try: note = Note.objects.get(pk=id) except ObjectDoesNotExist: return {'status': 403} if a in ['edit', 'new']: content = request.POST.get('content') if a == 'move': st = request.POST.get('section') if st not in STATES: return {'status': 403} note.state = st elif a == 'delete': note.delete() return {'status': 200} elif a == 'new': p = request.POST.get('project') p = get_object_or_404(Project, id=p) note = Note( content=content, author=request.user, project=p) note.save() return { 'status': 200, 'content': _note(note) } else: note.content = content note.save() return {'status': 200}
def create_note_api(): kind_id = flask.request.form.get('kind_id') quantity = flask.request.form.get('quantity') content = flask.request.form.get('content') user_id = int(flask.session['user_id']) # Check kind owner note_kind = NoteKind.fetchone(pk=kind_id, user_id=user_id) if not note_kind: raise error.KindNotExistError() note = Note() note.kind_id = kind_id note.user_id = user_id note.content = content note.quantity = quantity note.save() return {'pk': note.pk}
def post(self): user = self.user if user: content = self.request.get('note') note = Note() note.content = content note.user = user.key note.put() # show confirma tion of successful post creation template_values = { 'message': 'Note created successfully' } templates.render_page("notes/created", template_values, self) else: # error about login return return
def note(): """ Save a note related to a query. """ logger.debug("NOTE endpoint called") user = current_user content = request.form['content'] query_id = request.form['query_id'] # save note tmp = Note() tmp.user = user tmp.content = content tmp.query_id = query_id db.session.add(tmp) db.session.commit() return redirect('/admin/queryview/', code=302)