Exemplo n.º 1
0
def add_note():

    if 'logged_in' in session:
        form = forms.NoteForm(request.form)

        if request.method == 'POST' and form.validate():
            title = form.title.data
            description = form.description.data

            #create cursor

            cur = mysql.connection.cursor()

            cur.execute(
                "INSERT INTO notes(title, description, id_user) VALUES (%s,%s,%s)",
                (title, description, session['id_user']))

            mysql.connection.commit()

            cur.close()

            flash('agregaste la nota exitosamente', 'success')

            return redirect(url_for('add_note'))

        return render_template('add_note.html', form=form)

    else:
        return redirect(url_for('my_notes')), flash(
            "necesitas estar logueado para agregar notas", 'danger')
Exemplo n.º 2
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.º 3
0
def edit_note(id):
    cur = mysql.connection.cursor()

    cur.execute("SELECT * FROM notes WHERE id = %s", (id))
    note = cur.fetchone()

    cur.close()

    form = forms.NoteForm(request.form)
    form.title.data = note['title']
    form.description.data = note['description']

    if request.method == 'POST' and form.validate():
        print(request.method)
        title = request.form['title']
        description = request.form['description']
        #Create cursor
        cur = mysql.connection.cursor()
        #Execute
        cur.execute(
            "UPDATE notes SET title = %s, description = %s WHERE id = %s",
            (title, description, id))
        # Commit to DB
        mysql.connection.commit()
        # Close connection
        cur.close()
        return redirect(url_for('my_notes'))

    return render_template('edit_note.html', form=form)
Exemplo n.º 4
0
def edit_note(id):

    cur = mysql.connection.cursor()
    cur.execute("SELECT * FROM notes WHERE id = %s", (id))
    note = cur.fetchone()
    cur.close()

    form = forms.NoteForm(request.form)

    form.title.data = note['title']
    form.description.data = note['description']

    if request.method == 'POST' and form.validate:

        title = request.form['title']
        description = request.form['description']

        cur = mysql.connection.cursor()
        cur.execute(
            "UPDATE notes SET title = %s, description = %s WHERE id = %s",
            (title, description, id))
        mysql.connection.commit()
        cur.close()

        flash('Modificaste la nota exitosamente', 'success')

        return redirect(url_for('my_notes'))

    return render_template('edit_note.html', form=form)
Exemplo n.º 5
0
def note_update(note_id):
    """
    Note update api endpoint. Update a note
    """

    note = shortcuts.get_object_or_404(models.Note, note_id)
    form = forms.NoteForm(request.form, note)

    if form.validate():
        form.populate_obj(note)
        note.put()

        return jsonify(note.to_data())

    return jsonify(errors=form.errors)
Exemplo n.º 6
0
def note_create():
    """
    Note create api endpoint. Create a new note
    """

    form = forms.NoteForm(request.form)

    if form.validate():
        note = models.Note()
        form.populate_obj(note)
        note.put()

        return jsonify(note.to_data())

    return jsonify(errors=form.errors)
Exemplo n.º 7
0
def new_note():
    form = forms.NoteForm()
    user = g.user._get_current_object()
    categories = models.Category.select().where(
        models.Category.user == user.id)
    if form.validate_on_submit():
        models.Note.create(user=user,
                           content=form.content.data.strip(),
                           title=form.title.data,
                           category=form.category.data)
        flash(
            "New note created on " +
            "{:%B %d, %Y}".format(datetime.datetime.now()), "success")
        return redirect(url_for('notes'))
    return render_template('newnote.html', form=form, categories=categories)
Exemplo n.º 8
0
def edit_note(note_id):
    try:
        note = models.Note.select().where(models.Note.id == note_id).get()
    except models.DoesNotExist:
        abort(404)
    if note.user.id != g.user._get_current_object().id:
        flash("You do not have authorization for that note", "error")
        return redirect(url_for('notes'))
    form = forms.NoteForm(request.form, obj=note)
    if form.validate_on_submit():
        form.populate_obj(note)
        note.save()
        return redirect(url_for('note', note_id=note.id))
    categories = models.Category.select()
    return render_template('edit_note.html', form=form, categories=categories)
Exemplo n.º 9
0
def contact_edit(id):
    contact = models.Contact.select().where(models.Contact.id**id).get()
    notes = contact.notes
    form1 = forms.ContactForm()
    form2 = forms.NoteForm()
    # if form1.validate_on_submit():
    if request.method == 'POST':
        if request.form['submit'] == 'update':

            contact = models.Contact(id=id,
                                     first_name=form1.first_name.data,
                                     middle_name=form1.middle_name.data,
                                     last_name=form1.last_name.data,
                                     email=form1.email.data,
                                     phone=form1.phone.data,
                                     company=form1.company.data,
                                     position=form1.position.data,
                                     industry=form1.industry.data,
                                     address1=form1.address1.data,
                                     address2=form1.address2.data,
                                     alert=form1.alert.data,
                                     city=form1.city.data,
                                     state=form1.state.data,
                                     zipcode=form1.zipcode.data,
                                     country=form1.country.data,
                                     last_updated=dt.now(),
                                     alert_date=(dt.now() +
                                                 relativedelta(weeks=+1)))
            contact.save()
            return redirect(url_for('contact_edit', id=id))
        elif request.form['submit'] == 'save':
            note = models.Note.create(user=g.user._get_current_object(),
                                      contact_id=id,
                                      content=form2.content.data,
                                      important=form2.important.data)
            contact.last_updated = dt.now()
            contact.save()
            return redirect(url_for('contact_edit', id=id))

    return render_template("contact_edit.html",
                           contact=contact,
                           notes=notes,
                           form1=form1,
                           form2=form2)
Exemplo n.º 10
0
def add_note():
    form = forms.NoteForm(request.form)

    if request.method == 'POST' and form.validate():
        title = form.title.data
        description = form.description.data

        cur = mysql.connection.cursor()
        cur.execute(
            "INSERT INTO notes(title, description, user_id) VALUES (%s, %s, %s)",
            (title, description, session['user_id']))
        mysql.connection.commit()
        cur.close()

        flash('Agregaste la nota exitosamente', 'success')

        return redirect(url_for('add_note'))

    return render_template('add_note.html', form=form)
Exemplo n.º 11
0
def add_note():
    form = forms.NoteForm(request.form)
    print(request.method)

    if request.method == 'POST' and form.validate():
        title = form.title.data
        description = form.description.data

        #Create cursor
        cur = mysql.connection.cursor()

        #Execute
        cur.execute(
            "INSERT INTO notes(title, description, id_user) VALUES (%s,%s,%s)",
            (title, description, session['id_user']))
        mysql.connection.commit()
        cur.close()
        flash('Agregaste un post', 'success')
        return redirect(url_for('add_note'))

    return render_template('add_note.html', form=form)