# -*- coding: utf-8 -*-

import os

from flask import Blueprint, send_from_directory, current_app
from flask.views import View

bp_documents = Blueprint('documents', __name__)


class StaticFiles(View):
    def __init__(self, directory):
        self.directory = directory

    def dispatch_request(self, filename):
        if os.path.isabs(self.directory):
            directory = self.directory
        else:
            directory = os.path.join(current_app.root_path, self.directory)
        cache_timeout = current_app.get_send_file_max_age(filename)
        return send_from_directory(directory, filename,
                                   cache_timeout=cache_timeout)


bp_documents.add_url_rule('/images/<path:filename>',
                          view_func=StaticFiles.as_view('show_image',
                                                        '../content/images'))


bp_documents.add_url_rule('/documents/<path:filename>',
                          view_func=StaticFiles.as_view('show_document',
                                                        '../content/documents'))

@@ -91,16 +91,53 @@
 ent_app%0A
+from flask_login import current_user%0A
 from fla
@@ -257,32 +257,54 @@
 (self, directory
+, login_required=False
 ):%0A        self.
@@ -329,50 +329,226 @@
 ory%0A
-%0A    def dispatch_request(self, filename):
+        self.login_required = login_required%0A%0A    def dispatch_request(self, filename):%0A        if self.login_required and not current_user.is_authenticated:%0A            return current_app.login_manager.unauthorized()%0A
 %0A   
@@ -1314,12 +1314,319 @@
 ocuments'))%0A
+%0A%0Abp_documents.add_url_rule('/documents/restricted/%3Cpath:filename%3E',%0A                          view_func=StaticFiles.as_view('show_document_restricted',%0A                                                        '../content/documents/restricted',%0A                                                        True))%0A

Introduce restricted documents area