Exemplo n.º 1
0
def home():
	list = current_user.get_notes()
	form = forms.NoteForm()
	if form.validate_on_submit():
		models.Note.create(user=g.user.id, text=form.text.data, timestamp=datetime.now())
		return redirect(url_for("home"))
	return render_template("home.html", form=form, list=list)	
Exemplo n.º 2
0
def mynotes():
    form = NoteForm()
    noteID = request.args.get('noteID')
    #if creating a new note
    if form.validate_on_submit() and noteID is None:
        if 'submit' in request.form:
            note = Note(body=form.note.data,
                        due_date=form.due_date.data,
                        author=current_user,
                        priority=form.priorityLevel.data,
                        title=form.title.data)  #changed
            db.session.add(note)
            db.session.commit()
        return redirect(url_for('mynotes'))
    notes = current_user.get_notes().all()
    #will run when click submit after editing an existing note
    noteData = Note.query.filter_by(id=noteID).first()
    if form.validate_on_submit() and noteID is not None:
        if 'submit' in request.form:
            noteData.body = form.note.data
            noteData.due_date = form.due_date.data
            noteData.priority = form.priorityLevel.data
            noteData.author = current_user
            noteData.title = form.title.data  #changed
            db.session.commit()
        return redirect(url_for('mynotes'))
    #This puts the existing notes data into the note field for editing
    if noteID is not None:
        form.note.data = noteData.body
        form.due_date.data = noteData.due_date
        form.priorityLevel.data = noteData.priority
        form.title.data = noteData.title

    #display note to edit
    return render_template('mynotes.html', form=form, notes=notes)
Exemplo n.º 3
0
def gp_notebook():
	if request.method == "GET":
		notes = current_user.get_notes()
		if notes:
			return {
				"code": 200,
				"message":"Notes retrieved", 
				"success": True,
				"notes": notes_schema.dump(notes),
				}, 200
		return {
			"code": 200,
			"message":"No Notes found", 
			"success": True,
			"notes": [],
			}, 200
	if request.method == "POST":
		json_data = request.get_json()
		title = json_data.get("title")
		body = json_data.get("body")
		color = json_data.get("color")
		tags = json_data.get("tags")
		validate = notes_validator(title, 
		body, 
		color, 
		tags)
		if not validate[0]:
			return {
				"code": 400,
				"message":"Please review the errors", 
				"success": False,
				"errors": validate[1],
				}, 400
		note = Notes(
			user_id=current_user.id, 
			title=title, 
			body=body, 
			color=color,
			tags_string=tags)
		if is_empty(tags, minimum=2):
			tags = None
		else:
			tags = [note.tags.append(add_tags(tag.strip())) for tag in tags.split(",")]
		db.session.add(note)
		db.session.commit()
		if note:
			return {"code": 200,
				"message":"Note added successfully!", 
				"success": True,
				"note": note_schema.dump(note),
				}, 200
		return {    
			"code": 400,
			"message":"Could not add to database. "
			"Might be an enternal error. Please try again later.", 
			"success": False,
			"note": None
			}, 400
Exemplo n.º 4
0
def index():
    note_form = NoteForm()
    login_form = LoginForm()
    if note_form.validate_on_submit():
        note = Note(note=note_form.note.data,
                    author=current_user._get_current_object())
        db.session.add(note)
        db.session.commit()
        return redirect(url_for('.index'))
    notes = []
    completion = 0
    if current_user.is_authenticated:
        notes = current_user.get_notes(date.today())
        completion = User.completion_rate(notes)
    return render_template('index.html',
                           note_form=note_form,
                           notes=notes,
                           completion=completion)
Exemplo n.º 5
0
def delete_note():
    form = NoteDeleteForm()
    if form.is_submitted():
        if 'submit' in request.form:
            note = Note.query.filter_by(user_id=current_user.id)
            for n in note:
                db.session.delete(n)
                db.session.commit()
        if 'submitSingle' in request.form:
            singleID = int(request.form['submitSingle'])
            note = Note.query.filter_by(id=singleID).first()
            db.session.delete(note)
            db.session.commit()
            if Note.query.filter_by(
                    user_id=current_user.id).first() is not None:
                return redirect(url_for('delete_note'))
        return redirect(url_for('mynotes'))
    notes = current_user.get_notes().all()
    return render_template('delete-notes.html', form=form, notes=notes)