Beispiel #1
0
def get_user_diary():
    diary = Diary()
    try:
        return jsonify(diaries=[ob.serialize() for ob in diary.getAllByUniqueID(stack.top.uniqueID,
                                                                                utils.Time.Iso8601ToDatetime(request.args.get('from', None)),
                                                                                utils.Time.Iso8601ToDatetime(request.args.get('until', None)))])
    except ValueError as error:
        raise MethodNotAllowed(error.message)
    except db.BadValueException as error:
        raise MethodNotAllowed(error.message)    
Beispiel #2
0
def get_user_diary():
    diary = Diary()
    try:
        return jsonify(diaries=[ob.serialize() for ob in diary.getAllByUniqueID(stack.top.uniqueID,
                                                                                utils.Time.Iso8601ToDatetime(request.args.get('from', None)),
                                                                                utils.Time.Iso8601ToDatetime(request.args.get('until', None)))])
    except ValueError as error:
        raise MethodNotAllowed(error.message)
    except db.BadValueException as error:
        raise MethodNotAllowed(error.message)
Beispiel #3
0
def add_diary():
    diary = Diary()
    consent = request.get_json(silent=True, force=True)
    
    try:
        validate(consent, inputs.diary)
    except ValidationError as error:
        raise MethodNotAllowed(error.message)
        
    try:
        return jsonify(success=bool(diary.addByUniqueID(stack.top.uniqueID, consent['diary'])))
    except ValueError as error:
        raise MethodNotAllowed(error.message)
    except db.BadValueException as error:
        raise MethodNotAllowed(error.message)
Beispiel #4
0
def add_diary():
    diary = Diary()
    consent = request.get_json(silent=True, force=True)

    try:
        validate(consent, inputs.diary)
    except ValidationError as error:
        raise MethodNotAllowed(error.message)

    try:
        return jsonify(success=bool(diary.addByUniqueID(stack.top.uniqueID, consent['diary'])))
    except ValueError as error:
        raise MethodNotAllowed(error.message)
    except db.BadValueException as error:
        raise MethodNotAllowed(error.message)
Beispiel #5
0
def update_user_diary_by_id(_id):
    diary = Diary()
    consent = request.get_json(silent=True, force=True)
    
    try:
        diary.getByUniqueIDAndID(stack.top.uniqueID, _id).serialize()
    except:
        raise DiaryNotFound(_id)
    
    try:
        validate(consent, inputs.diary)
    except ValidationError as error:
        raise MethodNotAllowed(error.message)
    
    try:
        return jsonify(success=bool(diary.updateByUniqueIDAndID(stack.top.uniqueID, _id, consent['diary'])))
    except ValueError as error:
        raise MethodNotAllowed(error.message)
    except db.BadValueException as error:
        raise MethodNotAllowed(error.message)
Beispiel #6
0
def update_user_diary_by_id(_id):
    diary = Diary()
    consent = request.get_json(silent=True, force=True)

    try:
        diary.getByUniqueIDAndID(stack.top.uniqueID, _id).serialize()
    except:
        raise DiaryNotFound(_id)

    try:
        validate(consent, inputs.diary)
    except ValidationError as error:
        raise MethodNotAllowed(error.message)

    try:
        return jsonify(success=bool(diary.updateByUniqueIDAndID(stack.top.uniqueID, _id, consent['diary'])))
    except ValueError as error:
        raise MethodNotAllowed(error.message)
    except db.BadValueException as error:
        raise MethodNotAllowed(error.message)
Beispiel #7
0
def create_or_update():
    form = DiaryCreateForm()

    if not form.validate_on_submit():
        return jsonify({'status': 'error', 'form': form.errors}), 400

    date = form.date.data
    day = Diary.query.filter_by(user=current_user).filter_by(date=date).first()

    if day:
        day.save_title(form.title.data)
        day.save_content(form.content.data)

        db.session.commit()

        return jsonify({'status': 'update'})
    else:
        diary = Diary(
            user=current_user,
            date=datetime.strptime(form.date.data, '%Y-%m-%d'),
        )

        diary.save_title(form.title.data)
        diary.save_content(form.content.data)

        db.session.add(diary)
        db.session.commit()

        return jsonify({'status': 'added'})
Beispiel #8
0
def get_user_diary_by_id(_id):
    diary = Diary()
    try:
        return jsonify(diary.getByUniqueIDAndID(stack.top.uniqueID, _id).serialize())
    except:
        raise DiaryNotFound(_id)
Beispiel #9
0
def get_user_diary_by_id(_id):
    diary = Diary()
    try:
        return jsonify(diary.getByUniqueIDAndID(stack.top.uniqueID, _id).serialize())
    except:
        raise DiaryNotFound(_id)