示例#1
0
文件: seo.py 项目: viaict/viaduct
    def get_seo_fields(language="nl", module_name=None, request_path=None):
        """Get the seo fields as dict."""
        # Check if the module and path are set.
        if module_name is None:
            module_name = request.blueprint

        if request_path is None:
            request_path = request.path

        # Check which type of seo fields should be retrieved, based on
        # the module name.
        if module_name == "activity":
            # Get activity id
            activity_id = re.search(r"\/([0-9]+)\/", request_path)

            # Check seo existance
            if activity_id is not None:
                # Get the seo object of an activity
                seo = SEO.get_by_activity(activity_id.group(1))
            else:
                # No seo was found for this activity
                seo = None

        elif module_name == "page":
            # Retrieve the page for its id
            path = request_path[1:]
            page = Page.get_by_path(path)

            # Retrieve the revision by page id
            if page is not None:
                seo = SEO.get_by_page(page.id)
            else:
                seo = None
        else:
            # Retrieve seo fields based on the module name.
            seo = SEO.get_by_url(module_name)

        # Retrieve the seo fields based on the seo object
        # or global set values.
        if seo is not None:

            # Retrieve the language specific SEO fields
            if language == "nl":
                return {"title": seo.nl_title, "description": seo.nl_description, "tags": seo.nl_tags}
            elif language == "en":
                return {"title": seo.en_title, "description": seo.en_description, "tags": seo.en_tags}
        else:
            # TODO, good standard tags
            return {
                "title": "via",
                "description": "Studievereniging via - Informatica, "
                + "Informatiekunde, Informatica, "
                + "University of Amsterdam",
                "tags": "Studievereniging,via, informatica, " + "informatiekunde, University of Amsterdam",
            }
示例#2
0
文件: seo.py 项目: viaict/viaduct
    def get_seo(self, module_name=None, request_path=None):
        # Check if the module and path are set.
        if module_name is None:
            module_name = request.blueprint

        if request_path is None:
            request_path = request.path

        # Check which type of seo fields should be retrieved, based on
        # the module name.
        if module_name == "activity":
            # Get activity id
            activity_id = re.search(r"\/([0-9]+)\/", request_path)

            # Check seo existance
            if activity_id is not None:
                # Get the seo object of an activity
                return SEO.get_by_activity(activity_id.group(1))
            else:
                # No seo was found for this activity
                return None

        elif module_name == "page":
            # Retrieve the page for its id
            path = request_path[1:]
            page = Page.get_by_path(path)

            # Retrieve the revision by page id
            if page is not None:
                return SEO.get_by_page(page.id)
            else:
                return None
        else:
            # Retrieve seo fields based on the module name.
            seo = SEO.get_by_url(module_name)

            return seo

        return None