def homepage(): if request.method == 'POST': if request.form.get('content'): note = Note.create(content=request.form['content']) rendered = render_template('note.html', note=note) return jsonify({'note': rendered, 'success': True}) notes = Note.public().limit(50) return jsonify({'success': False})
def homepage(): if request.method == 'POST': if request.form.get('content'): note = Note.create(content=request.form['content']) rendered = render_template('note.html', note=note) return redirect(url_for('homepage')) return jsonify({'success': False}) notes = Note.public().limit(50) return render_template('homepage.html', notes=notes)
def homepage(): if not session.get('logged_in'): return redirect(url_for('login')) if request.method == 'POST': if request.form.get('content'): note = Note.create(content=request.form['content']) flash('New entry posted') return redirect(url_for('homepage')) notes = Note.public().paginate(get_page(), 50) return render_template('homepage.html', notes=notes)
def create(request): NoteForm = get_note_form(request) form = NoteForm() if request.method == 'POST': form = NoteForm(request.POST) if form.is_valid(): if request.user.is_authenticated(): author = request.user else: if 'email' in form.cleaned_data: users_list = User.objects.filter( email=form.cleaned_data['email']) if len(users_list) > 0: author = users_list[0] else: user = User() user.username = form.cleaned_data['email'] user.email = form.cleaned_data['email'] user.save() author = user note = Note( text=form.cleaned_data['text'], type=form.cleaned_data['type'], pub_date=datetime.datetime.now(), author=author, ) if 'public' in form.cleaned_data: note.public = True note.save() save_bookmark_to_note(request, note) send_note_email(note, 'http://' + request.get_host()) if request.is_ajax: _note = note.as_json() _note['url'] = request.get_host() + reverse(detail, args=(note.id, )) if request.user.is_authenticated() and ( note.author == request.user or user.is_staff): _note['editable'] = True return HttpResponse(json.dumps(_note), 'application/json') return HttpResponseRedirect(reverse(detail, args=(note.id, ))) if request.is_ajax(): return HttpResponse( json.dumps({ "form": render_to_string("notes/form.html", { "form": form, }, context_instance=RequestContext(request)) }), 'application/json') return render_to_response('notes/form_page.html', {'form': form}, context_instance=RequestContext(request))
def homepage(): if request.method == 'POST': if request.form.get('content'): # New note note = Note.create(content = request.form['content']) # Make a note panel and jsonify rendered = render_template('note.html', note = note) return jsonify({'note': rendered, 'success': True}) # no content, return failure return jsonify({'success': False}) notes = Note.public().limit(50) return render_template('homepage.html', notes = notes)
def homepage(): if request.method == 'POST': #create a new note in the db if request.form.get('content'): note = Note.create(content=request.form['content']) # Render a single note panel and return the HTML. rendered = render_template('note.html', note=note) return jsonify({'note': rendered, 'success': True}) return jsonify({'success': False}) notes = Note.public().paginate(get_page(), 50) return render_template('homepage.html', notes=notes)
def index(page=1): per_page = flask.current_app.config["PER_PAGE"] number_of_notes = len(list(Note)) pages = number_of_notes // per_page + (number_of_notes % per_page > 0) # TODO: Select category form = dict(flask.request.form) cids = [] if "apply_filter" in list(form): form.pop("apply_filter") cids = [ int(re.match("category:([0-9]*)", category).group(1)) for category in list(form) ] categories = utils.categories(cids=cids) keywords = flask.request.form.get("search", "", type=str) notes = Note.search(keywords) if not notes: notes = Note.public() nids = [] for note in notes: # TODO: Better solution for deleting all empty notes if not note.title and not note.content: note.delete_instance() # TODO: Improve filtering of notes if all([ NoteCategory.select().where( NoteCategory.note == note.id, NoteCategory.category == cid, ).exists() for cid in cids ]): nids.append(note.id) # Filter notes notes = notes.where(Note.id.in_(nids)) return flask.render_template( "index.html", notes=notes.paginate(page, per_page), page=page, pages=pages, categories=categories, keywords=keywords, )
def homepage(): if request.method == 'POST': if request.form.get('content'): # Create a new note in the db. note = Note.create(content=request.form['content']) # Render a single note panel and return the HTML. rendered = render_template('note.html', note=note) return jsonify({'note': rendered, 'success': True}) # If there's no content, indicate a failure. return jsonify({'success': False}) notes = Note.public().limit(50) return render_template('homepage.html', notes=notes)
def homepage(): if request.method == 'POST': print('/ request method is post') if request.form.get('content'): print('/ request metho is post,content is ', request.form['content']) note = Note.create(content=request.form['content']) rendered = render_template('note.html', note=note) return jsonify({'note': rendered, 'success': True}) return jsonify({'success': False}) print('/ request method is get') notes = Note.public().paginate(get_page(), 50) return render_template('homepage.html', notes=notes)
def homepage(): """ Displays the list of notes and creates new ones """ if request.method == 'POST': if request.form.get('content'): # Create a new note in the db. note = Note.create(title=request.form['title'], content=request.form['content'], categories=request.form['categories']) # Render a single note panel and return the HTML. rendered = render_template('note.html', note=note) return jsonify({'note': rendered, 'success': True}) # If there's no content, indicate a failure. return jsonify({'success': False}) # For now it will only show the 50 most recent notes, # for us not to worry with pagination. notes = Note.public().limit(50) return render_template('homepage.html', notes=notes)
def get_query(self): return Note.public()