Example #1
0
def delete(doc_id, methods=['DELETE']):
    """Delete a document"""
    document.delete_document(doc_id)
    return redirect(url_for('main'))
def delete(doc_id, methods=['DELETE']):
    """Delete a document"""
    document.delete_document(doc_id)
    return redirect(url_for('main'))
Example #3
0
def printjob():
    '''API endpoint to submit a print job.

    Example of JSON expected as POST data:
    {
        file_id: oid
        color: True
        double_sided: False
        collate: True
        copies: 3,
        staple: True
    }
    where oid is the string representation of the objectid returned by Mongo.

    Response body is empty.
    Response codes:
        201 - print job submission successful
        400 - invalid request - missing parameter(s) or file not found in database
        401 - invalid credentials
        409 - token not found
        504 - database error
        502 - error submitting job to Google
    '''
    try:
        file_id = request.form.get('file_id')
        copies = int(request.form.get('copies'))
        color = _parse_bool(request.form.get('color'))
        collate = _parse_bool(request.form.get('collate'))
        double_sided = _parse_bool(request.form.get('double_sided'))
        staple = _parse_bool(request.form.get('staple'))
    except ValueError:
        abort(400)
    if None in (file_id, copies, color, collate, double_sided, staple):
        abort(400, 'Missing required argument.')
    if copies < 1:
        abort(400, 'Cannot print fewer than 1 copy.')

    try:
        email, password = util.get_current_user_credentials()
    except ValueError:
        abort(401)

    try:
        token = oauthcredentials.get_token(email)
    except oauthcredentials.WebServiceError:
        abort(504)
    if token is None:
        abort(409)

    try:
        file_handle = document.get_document(file_id, email)
    except document.DatabaseError:
        abort(504)
    if file_handle is None:
        abort(400)

    try:
        cloudprint.submit_job(token,
                              file_handle,
                              color=color,
                              duplex=double_sided,
                              copies=copies,
                              collate=collate,
                              staple=staple)
    except cloudprint.JobSubmissionError:
        abort(502)
    finally:
        document.delete_document(file_id, email)

    file_handle.close()
    return '', 201
Example #4
0
def printjob():
    '''API endpoint to submit a print job.

    Example of JSON expected as POST data:
    {
        file_id: oid
        color: True
        double_sided: False
        collate: True
        copies: 3,
        staple: True
    }
    where oid is the string representation of the objectid returned by Mongo.

    Response body is empty.
    Response codes:
        201 - print job submission successful
        400 - invalid request - missing parameter(s) or file not found in database
        401 - invalid credentials
        409 - token not found
        504 - database error
        502 - error submitting job to Google
    '''
    try:
        file_id = request.form.get('file_id')
        copies = int(request.form.get('copies'))
        color = _parse_bool(request.form.get('color'))
        collate = _parse_bool(request.form.get('collate'))
        double_sided = _parse_bool(request.form.get('double_sided'))
        staple = _parse_bool(request.form.get('staple'))
    except ValueError:
        abort(400)
    if None in (file_id, copies, color, collate, double_sided, staple):
        abort(400, 'Missing required argument.')
    if copies < 1:
        abort(400, 'Cannot print fewer than 1 copy.')

    try:
        email, password = util.get_current_user_credentials()
    except ValueError:
        abort(401)

    try:
        token = oauthcredentials.get_token(email)
    except oauthcredentials.WebServiceError:
        abort(504)
    if token is None:
        abort(409)

    try:
        file_handle = document.get_document(file_id, email)
    except document.DatabaseError:
        abort(504)
    if file_handle is None:
        abort(400)

    try: 
        cloudprint.submit_job(token, file_handle, color=color, duplex=double_sided,
                              copies=copies, collate=collate, staple=staple)
    except cloudprint.JobSubmissionError:
        abort(502)
    finally:
        document.delete_document(file_id, email)

    file_handle.close()
    return '', 201