Example #1
0
def document_map(project_id, document_file_id):
    """
    The map xml action, which is used create a structure map file for document.

    :param int doc_id: The document to retrieve details for.
    """
    try:
        document = DocumentFile.query.get(document_file_id)
    except TypeError:
        return app.login_manager.unauthorized()

    access_granted = current_user.has_document_file(
        DocumentFile.query.get(document_file_id))

    # Test if this user can see it
    if not access_granted:
        return app.login_manager.unauthorized()

    filename = os.path.split(document.path)[1]
    project = Project.query.get(project_id)
    map_document = forms.MapDocumentForm()
    return render_template("document_map.html",
                           document=document,
                           project=project,
                           filename=filename,
                           map_document=map_document)
Example #2
0
def document_map(project_id, document_file_id):
    """
    The map xml action, which is used create a sturctuve file map for document.

    :param int doc_id: The document to retrieve details for.
    """
    print "DOC MAP"
    try:
        document = DocumentFile.query.get(document_file_id)
    except TypeError:
        return app.login_manager.unauthorized()

    access_granted = current_user.has_document_file(
        DocumentFile.query.get(document_file_id))

    # Test if this user can see it
    if not access_granted:
        return app.login_manager.unauthorized()

    filename = os.path.split(document.path)[1]
    project = Project.query.join(User).filter(User.id == current_user.id).\
        filter(DocumentFile.id == document_file_id).one()
    map_document = forms.MapDocumentForm()
    return render_template("document_map.html",
        document=document,
        project=project,
        filename=filename,
        map_document = map_document,
        document_url="%s%s"%(app.config["UPLOAD_ROUTE"],document.id))
Example #3
0
def document_show(project_id, document_file_id):
    """The show action, which shows details for a particular DocumentFile.

    :param int document_file_id: The DocumentFile to retrieve details for.
    """
    #TODO: good spot for a helper
    #document = helpers.get_object_or_exception(Unit,
    #   Unit.id == document_id, exceptions.DocumentNotFoundException)
    try:
        document_file = DocumentFile.query.get(document_file_id)
    except TypeError:
        return app.login_manager.unauthorized()

    access_granted = current_user.has_document_file(document_file)

    # Test if this user can see it
    if not access_granted:
        return app.login_manager.unauthorized()

    filename = os.path.split(document_file.path)[1]
    #TODO: move to objects

    project = Project.query.join(User).filter(User.id == current_user.id).\
        filter(DocumentFile.id == document_file_id).one()
    # NOTE: do you mean projects? why do you only load one project when
    # documents can be part of more than one project? This should likely
    # just be document.projects

    return render_template("document_show.html",
        document_file=document_file,
        project=project,
        filename=filename)
Example #4
0
def document_map(project_id, document_file_id):
    """
    The map xml action, which is used create a structure map file for document.

    :param int doc_id: The document to retrieve details for.
    """
    try:
        document = DocumentFile.query.get(document_file_id)
    except TypeError:
        return app.login_manager.unauthorized()

    access_granted = current_user.has_document_file(
        DocumentFile.query.get(document_file_id))

    # Test if this user can see it
    if not access_granted:
        return app.login_manager.unauthorized()

    filename = os.path.split(document.path)[1]
    project = Project.query.get(project_id)
    map_document = forms.MapDocumentForm()
    return render_template(
        "document_map.html",
        document=document,
        project=project,
        filename=filename,
        map_document=map_document
    )
Example #5
0
def get_file(file_id):
    """If the user has permission to view this file, then return it.
    """

    document_file = DocumentFile.query.get(file_id)
    try:
        access_granted = current_user.has_document_file(document_file)
    except TypeError:
        return app.login_manager.unauthorized()
    # TODO: clearer error handling

    # Test if this user can see it
    if not access_granted:
        return app.login_manager.unauthorized()
    directory, filename = os.path.split(document_file.path)

    return send_from_directory(directory, filename)
Example #6
0
def get_file(filetype, file_id):
    """If the user has permission to view this file, then return it.
    """

    if filetype == "doc":
        document_file = DocumentFile.query.get(file_id)
        try:
            access_granted = current_user.has_document_file(document_file)
        except TypeError:
            return app.login_manager.unauthorized()
    elif filetype == "struc":
        document_file = StructureFile.query.get(file_id)
        try:
            access_granted = current_user.has_structure_file(document_file)
        except TypeError:
            return app.login_manager.unauthorized()

    # Test if this user can see it
    if not access_granted:
        return app.login_manager.unauthorized()
    directory, filename = os.path.split(document_file.path)

    return send_from_directory(directory, filename)