Beispiel #1
0
    def utility_processor():
        """
        This defines the set of properties and functions that will be added
        to the default context for processing templates. All these items
        can be used in all templates
        """

        if authentication.is_authenticated(flask.session):
            user_name = flask.session["openid"]["fullname"]
        else:
            user_name = None

        page_slug = template_utils.generate_slug(flask.request.path)

        return {
            # Variables
            "LOGIN_URL": app.config["LOGIN_URL"],
            "SENTRY_PUBLIC_DSN": app.config["SENTRY_PUBLIC_DSN"],
            "COMMIT_ID": app.config["COMMIT_ID"],
            "ENVIRONMENT": app.config["ENVIRONMENT"],
            "path": flask.request.path,
            "page_slug": page_slug,
            "user_name": user_name,
            "VERIFIED_PUBLISHER": "verified",
            "webapp_config": app.config["WEBAPP_CONFIG"],
            "BSI_URL": app.config["BSI_URL"],
            # Functions
            "contains": template_utils.contains,
            "join": template_utils.join,
            "static_url": template_utils.static_url,
            "format_number": template_utils.format_number,
            "display_name": template_utils.display_name,
        }
Beispiel #2
0
    def utility_processor():
        """
        This defines the set of properties and functions that will be added
        to the default context for processing templates. All these items
        can be used in all templates
        """

        if authentication.is_authenticated(flask.session):
            user_name = flask.session['openid']['fullname']
        else:
            user_name = None

        page_slug = template_utils.generate_slug(flask.request.path)

        return {
            # Variables
            'LOGIN_URL': app.config['LOGIN_URL'],
            'SENTRY_PUBLIC_DSN': app.config['SENTRY_PUBLIC_DSN'],
            'COMMIT_ID': app.config['COMMIT_ID'],
            'ENVIRONMENT': app.config['ENVIRONMENT'],
            'path': flask.request.path,
            'page_slug': page_slug,
            'user_name': user_name,
            'VERIFIED_PUBLISHER': 'verified',
            'webapp_config': app.config['WEBAPP_CONFIG'],
            'BSI_URL': app.config['BSI_URL'],

            # Functions
            'contains': template_utils.contains,
            'join': template_utils.join,
            'static_url': template_utils.static_url,
            'format_number': template_utils.format_number,
        }
Beispiel #3
0
    def utility_processor():
        """
        This defines the set of properties and functions that will be added
        to the default context for processing templates. All these items
        can be used in all templates
        """

        if authentication.is_authenticated(flask.session):
            user_name = flask.session["openid"]["fullname"]
        else:
            user_name = None

        page_slug = template_utils.generate_slug(flask.request.path)

        return {
            # Variables
            "LOGIN_URL": app.config["LOGIN_URL"],
            "SENTRY_PUBLIC_DSN": app.config["SENTRY_PUBLIC_DSN"],
            "COMMIT_ID": app.config["COMMIT_ID"],
            "ENVIRONMENT": app.config["ENVIRONMENT"],
            "path": flask.request.path,
            "page_slug": page_slug,
            "user_name": user_name,
            "VERIFIED_PUBLISHER": "verified",
            "webapp_config": app.config["WEBAPP_CONFIG"],
            "BSI_URL": app.config["BSI_URL"],
            # Functions
            "contains": template_utils.contains,
            "join": template_utils.join,
            "static_url": template_utils.static_url,
            "format_number": template_utils.format_number,
            "display_name": template_utils.display_name,
        }
Beispiel #4
0
    def utility_processor():
        """
        This defines the set of properties and functions that will be added
        to the default context for processing templates. All these items
        can be used in all templates
        """

        if authentication.is_authenticated(flask.session):
            user_name = flask.session["publisher"]["fullname"]
            user_is_canonical = flask.session["publisher"].get(
                "is_canonical", False
            )
            stores = flask.session["publisher"].get("stores")
        else:
            user_name = None
            user_is_canonical = False
            stores = []

        page_slug = template_utils.generate_slug(flask.request.path)

        is_brand_store = False

        if "STORE_QUERY" in app.config["WEBAPP_CONFIG"]:
            is_brand_store = True

        return {
            # Variables
            "LOGIN_URL": app.config["LOGIN_URL"],
            "SENTRY_DSN": app.config["SENTRY_DSN"],
            "COMMIT_ID": app.config["COMMIT_ID"],
            "ENVIRONMENT": app.config["ENVIRONMENT"],
            "host_url": flask.request.host_url,
            "path": flask.request.path,
            "page_slug": page_slug,
            "user_name": user_name,
            "VERIFIED_PUBLISHER": "verified",
            "webapp_config": app.config["WEBAPP_CONFIG"],
            "BSI_URL": app.config["BSI_URL"],
            "IS_BRAND_STORE": is_brand_store,
            "now": datetime.now(),
            "user_is_canonical": user_is_canonical,
            # Functions
            "contains": template_utils.contains,
            "join": template_utils.join,
            "static_url": template_utils.static_url,
            "format_number": template_utils.format_number,
            "display_name": template_utils.display_name,
            "install_snippet": template_utils.install_snippet,
            "format_date": template_utils.format_date,
            "format_member_role": template_utils.format_member_role,
            "image": image_template,
            "stores": stores,
        }
Beispiel #5
0
    def test_generate_slug(self):
        result = template_utils.generate_slug("/snaps")
        self.assertEqual(result, "account")

        result = template_utils.generate_slug("/listing")
        self.assertEqual(result, "account")

        result = template_utils.generate_slug("/releases")
        self.assertEqual(result, "account")

        result = template_utils.generate_slug("/publicise")
        self.assertEqual(result, "account")

        result = template_utils.generate_slug("/publicise/badges")
        self.assertEqual(result, "account")

        result = template_utils.generate_slug("/publicise/cards")
        self.assertEqual(result, "account")

        result = template_utils.generate_slug("/settings")
        self.assertEqual(result, "account")

        result = template_utils.generate_slug("/account/details")
        self.assertEqual(result, "account")

        result = template_utils.generate_slug("/")
        self.assertEqual(result, "home")

        result = template_utils.generate_slug("/first-snap")
        self.assertEqual(result, "home")

        result = template_utils.generate_slug("/build")
        self.assertEqual(result, "build")

        result = template_utils.generate_slug("/blog")
        self.assertEqual(result, "blog")

        result = template_utils.generate_slug("/iot")
        self.assertEqual(result, "iot")

        result = template_utils.generate_slug("/any-route")
        self.assertEqual(result, "store")