Beispiel #1
0
def delete_note(noteid):
    user = get_jwt_identity()
    note = NoteModel.find_by_id(noteid)
    if not note or note.userid != user:
        return {'message': 'no such note'}, 404

    try:
        NoteModel.delete_by_id(noteid)
    except Exception as e:
        app.logger.error(f'error deleting note', exc_info=e)
        return {'message': 'something went wrong'}, 500

    return {'message': f'deleted note \'{noteid}\'.'}
Beispiel #2
0
def post_note():
    body = request.get_json()
    if body is None or 'title' not in body or 'markdown' not in body:
        return {'message': 'note title or markdown not supplied'}, 400

    user = get_jwt_identity()
    try:
        tags = body.get('tags', [])
        new_note = NoteModel(title=body['title'],
                             markdown=body['markdown'],
                             userid=user,
                             tags=tags)
        new_note.insert()
    except Exception as e:
        app.logger.error(f'error saving note', exc_info=e)
        return {'message': 'something went wrong'}, 500

    return {'message': f'note \'{new_note.id}\' created', 'id': new_note.id}
Beispiel #3
0
def create_note():
    title = request.json.get('title', '')
    content = request.json.get('content', '')

    note = NoteModel(title=title, content=content)

    db.session.add(note)
    db.session.commit()

    return note_schema.jsonify(note)
Beispiel #4
0
def rate(event_id, value):
    """
    Marks an event

    Paramters
    ---------
    event_id: the id of the event to mark
    value: the rate gived to the event
    """
    try:
        assert 1 <= value and value <= 5

        note = NoteModel(event_id, value)
        try:
            note.save()
            return "Your note is saved."
        except:
            return "No event with the id {} founded".format(event_id)
    except AssertionError:
        return "rate value must be between 1 and 5"
Beispiel #5
0
def get_notes():
    user = get_jwt_identity()
    notes = NoteModel.find_all_by_userid(user)
    # note: the html/markdown is escaped in the client before rendering
    return_notes = [{
        'id': n.id,
        'title': n.title,
        'markdown': n.markdown,
        'tags': n.tags if n.tags is not None else []
    } for n in notes]
    return {'notes': return_notes}
Beispiel #6
0
 def insert(self, note):
     logging.debug('inserting note: %s' % str(note))
     note_model = NoteModel(name=note.name,
                            type=note.type,
                            meeting_id=note.meeting_id,
                            time=note.time,
                            start_time_delta=note.start_time_delta,
                            assignee=note.assignee,
                            description=note.description)
     note_key = note_model.put()
     logging.debug('successfully inserted note, id %d' % note_key.id())
     return note_key.id()
Beispiel #7
0
def put_note(noteid):
    user = get_jwt_identity()
    note = NoteModel.find_by_id(noteid)
    if note is None or note.userid != user:
        return {'message': 'no such note'}, 404

    body = request.get_json()
    if body is None or ('title' not in body and 'markdown' not in body
                        and 'tags' not in body):
        return {'message': 'no note fields supplied'}, 400

    try:
        if 'title' in body:
            note.title = body['title']
        if 'markdown' in body:
            note.markdown = body['markdown']
        if 'tags' in body:
            note.tags = list(set(body['tags']))
        note.update()
    except Exception as e:
        app.logger.error(f'error updating note', exc_info=e)
        return {'message': 'something went wrong'}, 500

    return {'message': 'note updated'}
Beispiel #8
0
def add_file(name,content,p_dir,user):
    p_dir=from_dict(p_dir) 
    f = NoteModel(name=name,content=content,p_dir=p_dir,owner=user)
    f.save()
    return {'file':to_dict(f)}