Example #1
0
def attachments_resize(req, path, webid, width, height):
    attachment = Attachment(Attachment.web_to_id(webid))
    last_modified = Attachment.last_modified(req, webid)

    if last_modified is None:                   # file not found
        raise SERVER_RETURN(state.HTTP_NOT_FOUND)

    if 'If-Modified-Since' in req.headers_in:   # check cache header
        hdt = datetime.strptime(req.headers_in['If-Modified-Since'],
                                time_format)
        if last_modified <= hdt:
            req.headers_out.add_header('Last-Modified',
                                       last_modified.strftime(time_format))
            req.headers_out.add_header('Date',
                                       datetime.utcnow().strftime(time_format))
            raise SERVER_RETURN(state.HTTP_NOT_MODIFIED)

    attachment.get(req)                         # check resize hash
    if req.args.get('hash', '') != attachment.resize_hash("%dx%d" %
                                                          (width, height)):
        raise SERVER_RETURN(state.HTTP_FORBIDDEN)

    retval = attachment.resize(req, width, height)
    if retval is None:                          # it is not image
        raise SERVER_RETURN(state.HTTP_BAD_REQUEST)

    req.content_type = attachment.mime_type
    req.clength = len(retval)
    req.headers_out.add_header('Last-Modified',
                               last_modified.strftime(time_format))
    return retval
Example #2
0
def attachments_detach(req, object_type, object_id, path, webid):
    check_login(req)
    match_right(req, [R_ADMIN, 'attachments_author'])
    check_origin(req)
    attachment = Attachment(Attachment.web_to_id(webid))
    attachment.detach(req, object_type, object_id)
    if attachment.delete(req) is None:
        raise SERVER_RETURN(state.HTTP_NOT_FOUND)

    return js_items(req, object_type=object_type, object_id=object_id)
Example #3
0
def attachments_download(req, path, webid):
    attachment = Attachment(Attachment.web_to_id(webid))
    attachment.get(req)

    req.headers_out.add_header(
        'Content-Disposition',
        'attachment',
        # filename=attachment.file_name.encode('ascii','xmlcharrefreplace'))
        filename=attachment.file_name.encode('ascii', 'backslashreplace'))

    return send_file(req, req.cfg.attachments_path + '/' + path + '/' + webid,
                     content_type=attachment.mime_type)
Example #4
0
def attachments_normal(req, path, webid):
    attachment = Attachment(Attachment.web_to_id(webid))
    attachment.get(req)

    return send_file(req, req.cfg.attachments_path + '/' + path + '/' + webid,
                     content_type=attachment.mime_type)