コード例 #1
0
    def get_profiles_list(self):
        force = request.values.get("force", "false") in valid_boolean_trues

        try:
            if (self.filamentManager != None):
                lm = self.filamentManager.get_profiles_lastmodified()
            else:
                self._logger.warn(
                    "self.filamentManager is not initialized yet")
                return
        except Exception as e:
            lm = None
            self._logger.error(
                "Failed to fetch profiles lastmodified timestamp: {message}".
                format(message=str(e)))
            self._logger.exception(
                "Failed to fetch profiles lastmodified timestamp: {message}".
                format(message=str(e)))

        etag = entity_tag(lm)

        if not force and check_lastmodified(lm) and check_etag(etag):
            return make_response("Not Modified", 304)

        try:
            all_profiles = self.filamentManager.get_all_profiles()
            response = jsonify(dict(profiles=all_profiles))
            return add_revalidation_header_with_no_max_age(response, lm, etag)
        except Exception as e:
            self._logger.error(
                "Failed to fetch profiles: {message}".format(message=str(e)))
            self._logger.exception(
                "Failed to fetch profiles: {message}".format(message=str(e)))
            return make_response(
                "Failed to fetch profiles, see the log for more details", 500)
コード例 #2
0
    def get_profiles_list(self):
        mods = self.filamentManager.get_profiles_modifications()
        lm = mods[0]["changed_at"] if len(mods) > 0 else 0
        etag = (hashlib.sha1(str(lm))).hexdigest()

        if check_lastmodified(int(lm)) and check_etag(etag):
            return make_response("Not Modified", 304)

        all_profiles = self.filamentManager.get_all_profiles()
        if all_profiles is not None:
            response = jsonify(dict(profiles=all_profiles))
            response.set_etag(etag)
            response.headers["Last-Modified"] = http_date(lm)
            response.headers["Cache-Control"] = "max-age=0"
            return response
        else:
            return make_response("Database error", 500)