def delete_quote(id):
    note = Note.objects(id=id).first()

    deleteNote = deleteQuoteForm(request.form)
    if request.method == 'POST':
        deleteNote = deleteQuoteForm(request.form)

        if deleteNote.validate == False:
            flash('Faliure', 'danger')
            return redirect(url_for('profile') + ('/' + current_user.slug))

        if deleteNote.validate_on_submit():
            note = Note.objects(id=id).first()

            current_user.notes.remove(note)
            current_user.save()

            note.delete()

            flash('Successfully deleted', 'warning')

    return render_template("delete.html",
                           title="delete",
                           delete_note=deleteNote,
                           note=note)
Пример #2
0
def delete_checked():
    try:
        Note.objects(checked=True).delete()
    except:
        return jsonify({"success": False, "message": "cannot delete"})

    return jsonify({"success": "true"})
Пример #3
0
def get(id):
    note = Note.objects(id=id).first()
    if not note:
        return "", 400
    if not note.title:
        note.title = note.content[:Config.COUNT_OF_FIRST_N_LETTERS]
    title = note.title
    content = note.content
    return jsonify({'id': id, 'title': title, 'content': content})
Пример #4
0
def update(id):
    title = request.get_json().get('title')
    content = request.get_json().get('content')
    if content or title:
        note = Note.objects(id=id).upsert_one(title=title, content=content)
        if not note:
            return "", 400
        note.save()
        return "", 202
    else:
        return "", 204
Пример #5
0
def get_query():
    query = request.args.get('query')
    if query:
        result = []
        notes = Note.objects(title__icontains=query)
        for note in notes:
            if note:
                if not note.title:
                    note.title = note.content[:Config.COUNT_OF_FIRST_N_LETTERS]
                result.append({
                    'id': note.id,
                    'title': note.title,
                    'content': note.content
                })
        notes = Note.objects(content__icontains=query)
        for note in notes:
            if note:
                if not note.title:
                    note.title = note.content[:Config.COUNT_OF_FIRST_N_LETTERS]
                result.append({
                    'id': note.id,
                    'title': note.title,
                    'content': note.content
                })
        if result:
            return jsonify(result)
        else:
            return "", 400
    else:
        notes = Note.objects
        result = []
        for note in notes:
            if not note.title:
                note.title = note.content[:Config.COUNT_OF_FIRST_N_LETTERS]
            result.append({
                'id': note.id,
                'title': note.title,
                'content': note.content
            })
        return jsonify(result)
Пример #6
0
def delete(id):
    note = Note.objects(id=id).first()
    if not note:
        return "", 400
    Note.objects(id=id).delete()
    return "", 200