Esempio n. 1
0
    def matlab(self):
        matlab_path = DirectoryRequestHandler.requestfilepath(self.request)

        with open_resource(matlab_path) as matlab_file:
            source = matlab_file.read()
            matlab_html = render('template/matlab.pt', {"request": self.request, "html": source})
        return dict(request=self.request, html=matlab_html, files=dict(), folders=['.', '..'],
                    logged_in=self.request.authenticated_userid)
Esempio n. 2
0
 def markdown(self):
     markdown_path = DirectoryRequestHandler.requestfilepath(self.request)
     with open_resource(markdown_path) as markdown_file:
         source = markdown_file.read()
         source = str(source)
         html = hoedown.Markdown(
             hoedown.HtmlRenderer(hoedown.HTML_TOC_TREE),
             hoedown.EXT_TABLES).render(source)
         html = render('template/markdown.pt', {"request": self.request, "html": html})
     return dict(request=self.request, html=html, files=dict(), folders=['.', '..'],
                 logged_in=self.request.authenticated_userid)
Esempio n. 3
0
    def csv_table(self):
        relative_path = DirectoryRequestHandler.requestfilepath(self.request)
        delimit = CSVHandler.getdelimiter(relative_path, self.request.matchdict)

        with open_resource(relative_path) as csv_file:
            reader = csv.reader(csv_file, delimiter=delimit)
            table = PageTemplate('''<table class="table table-striped table-bordered table-condensed">
                <tr tal:repeat="row table"><td tal:repeat="cell row" tal:content="cell"/></tr>
                </table>''')
            table_html = table(table=reader)
        return dict(request=self.request, html=table_html, files=dict(), folders=['.', '..'],
                    logged_in=self.request.authenticated_userid)
Esempio n. 4
0
    def login(self):
        login_url = self.request.resource_url(self.request.context, "login")
        referrer = self.request.url
        if referrer == login_url:
            referrer = "/"  # never use the login form itself as came_from
        came_from = self.request.params.get("came_from", referrer)
        message = ""
        login = ""
        password = ""
        if "form.submitted" in self.request.params:
            login = self.request.params["login"]
            password = self.request.params["password"]
            usermanager = self.request.registry.settings["usermanager"]

            if usermanager.validate_password(login, password):
                headers = remember(self.request, login)
                return HTTPFound(location=came_from, headers=headers)
            message = "Failed login"

        description_is_private = False
        if "privacy.description" in self.request.registry.settings:
            description_is_private = self.request.registry.settings["privacy.description"] == "private"

        # load the information
        try:
            relative_path = DirectoryRequestHandler.requestfolderpath(self.request)
            description = os.path.join(relative_path, ".description.json")
            if not os.path.exists(description) or description_is_private:
                information = None
            else:
                with open_resource(description) as file:
                    json_file = file.read()
                    description_obj = jsonpickle.decode(json_file)
                    information = description_obj["shortdescription"]
        except BaseException as e:
            information = "Error: {0}".format(e.message)
            log = logging.getLogger(__name__)
            log.error(e.message)

        return dict(
            message=message,
            url=self.request.application_url + "/login",
            came_from=came_from,
            login=login,
            password=password,
            information=information,
        )
Esempio n. 5
0
    def getdelimiter(path, requestdictionary):
        auto_detect_delimiter = False
        if 'delimiter' in requestdictionary:
            delimit = str(requestdictionary['delimiter'])
            if delimit in ['tab', '/t']:
                delimit = str('\t')
            elif delimit == 'space':
                delimit = str(' ')
            elif delimit == 'auto':
                auto_detect_delimiter = True
                delimit = str(',')
        else:
            auto_detect_delimiter = True
            delimit = str(',')

        if auto_detect_delimiter:
            with open_resource(path) as csv_file:
                possible_delimiters = ['\t', ',', ';', ' ']
                delimit = path._detect_csv_delimiter(csv_file.read(), possible_delimiters)
        return delimit
Esempio n. 6
0
    def jsonview(self):
        """
        Returns the json file either in a formatted way or as plain text
        :return:
        """
        jsonpath = DirectoryRequestHandler.requestfilepath(self.request)
        if not os.path.exists(jsonpath):
            return dict(request=self.request, html='', files=dict(), folders=['.', '..'])

        params_json = dict(self.request.params)
        if 'updatelocalsettingsfile' in params_json and 'newsettings' in params_json:
            return DirectoryUpdateLocalSettings.handle_request(self.request, jsonpath, None)

        with open_resource(jsonpath) as json:
            source = json.read()
            if self.request.matched_route.name == 'jsonviewer_plain':
                return source

            json_html = render('template/json_view.pt', dict(request=self.request,
                                                             jsonencoded=source,
                                                             filename=self.request.matchdict['file']))
            return dict(request=self.request, html=json_html, files=dict(), folders=['.', '..'],
                        logged_in=self.request.authenticated_userid)