Ejemplo n.º 1
0
def treatment_middelware_microsite(url):
    if 'plugins.microsite.middleware.MicrositeMiddleware' in settings.MIDDLEWARE_CLASSES:
        from plugins.microsite.config import PluginConfig
        url_prefixes = PluginConfig.url_prefixes[0][0]
        prefix_microsite = url_prefixes.get(get_url_default_lang(),
                                            url_prefixes.get('en'))
        url = re.sub('^/%s' % prefix_microsite, '', url)
    return url
Ejemplo n.º 2
0
def treatment_middelware_microsite(url):
    if 'plugins.microsite.middleware.MicrositeMiddleware' in settings.MIDDLEWARE_CLASSES:
        from plugins.microsite.config import PluginConfig
        url_prefixes = PluginConfig.url_prefixes[0][0]
        prefix_microsite = url_prefixes.get(get_url_default_lang(),
                                                url_prefixes.get('en'))
        url = re.sub('^/%s' % prefix_microsite, '', url)
    return url
Ejemplo n.º 3
0
    def get_url_prefixes(self):
        prefixes = []
        for url_prefix, url in self.url_prefixes:
            prefix = url_prefix
            if isinstance(url_prefix, dict):
                prefix = url_prefix.get(get_url_default_lang())
            prefixes.append((path.join(settings.BASE_URL[1:], prefix), url))

        return prefixes
Ejemplo n.º 4
0
    def get_url_prefixes(self):
        prefixes = []
        for url_prefix, url in self.url_prefixes:
            prefix = url_prefix
            if isinstance(url_prefix, dict):
                prefix = url_prefix.get(get_url_default_lang())
            prefixes.append((path.join(settings.BASE_URL[1:], prefix), url))

        return prefixes
Ejemplo n.º 5
0
 def breadcrumbs_first_item(self):
     from merengue.pluggable.utils import get_plugin_config
     plugin_dir = self._meta.app_label
     plugin_config = get_plugin_config(plugin_dir)
     if plugin_config is None:
         return None  # item model is outside plugin... no first item generated
     url_prefix = plugin_config.url_prefixes[0][0]
     if isinstance(url_prefix, dict):
         url_prefix = url_prefix.get(get_url_default_lang(), 'en')
     plugin_url = "/%s/" % url_prefix
     return (self._meta.verbose_name_plural, plugin_url)
Ejemplo n.º 6
0
 def process_request(self, request):
     path_info = request.get_full_path()
     url_args = [item for item in path_info.split('/') if item]
     from plugins.microsite.config import PluginConfig
     url_prefixes = PluginConfig.url_prefixes[0][0]
     prefix_microsite = url_prefixes.get(get_url_default_lang(), 'en')
     if len(url_args) > 1 and url_args[0] == prefix_microsite:
         del url_args[0]
         url_new = '/'.join(url_args)
         url_new = '/%s/' % url_new
         return HttpResponseRedirect(url_new)
Ejemplo n.º 7
0
def generate_sitemap(with_portal_links=True,
                     with_menu_portal=True,
                     with_sections=True,
                     with_menu_section=True,
                     with_contents=True,
                     priority_choices=None):
    priority_choices = priority_choices or PRIORITY_CHOICES
    domain = 'http://%s' % Site.objects.get_current().domain
    _treatment_url_microsites = False
    if with_sections or with_contents:
        if 'plugins.microsite.middleware.MicrositeMiddleware' in settings.MIDDLEWARE_CLASSES:
            _treatment_url_microsites = True
            from plugins.microsite.config import PluginConfig
            microsite_prefixes = PluginConfig.url_prefixes[0][0]
            microsite_prefix = microsite_prefixes.get(
                get_url_default_lang(),
                microsite_prefixes.get('en', '/microsite/'))
            microsite_replace = '%s/%s' % (domain, microsite_prefix)

    results = []
    if with_portal_links:
        for portal in PortalLink.objects.all():
            url = _treatment_url(domain, portal.get_absolute_url())
            if not url:
                continue
            results.append({
                'url': url,
                'modified_date': None,
                'priority': PRIORITY_CHOICES['high']
            })
    if with_menu_portal:
        menu_portal = Menu.objects.get(slug=settings.MENU_PORTAL_SLUG)
        for menu in menu_portal.get_descendants().filter(status='public'):
            url = _treatment_url(domain, menu.get_absolute_url())
            if not url:
                continue
            results.append({
                'url': url,
                'modified_date': None,
                'priority': PRIORITY_CHOICES['high']
            })
    if with_sections:
        sections = BaseSection.objects.published()
        for section in sections:
            section = section.get_real_instance()
            url = _treatment_url(domain, section.public_link())
            if not url:
                continue
            if _treatment_url_microsites and url.startswith(microsite_replace):
                url = url.replace(microsite_replace, domain)
            results.append({
                'url': url,
                'modified_date': None,
                'priority': PRIORITY_CHOICES['high']
            })
            if with_menu_section:
                menu_section = section.main_menu
                for menu in menu_section.get_descendants().filter(
                        status='public'):
                    url = _treatment_url(domain, menu.get_absolute_url())
                    if not url:
                        continue
                    if _treatment_url_microsites and url.startswith(
                            microsite_replace):
                        url = url.replace(microsite_replace, domain)
                    results.append({
                        'url': url,
                        'modified_date': None,
                        'priority': PRIORITY_CHOICES['medium']
                    })
    if with_contents:
        class_names = ('basesection', ) + settings.SMAP_EXCLUDE_CLASS_NAME
        subclasses = BaseSection.get_subclasses()
        class_names += tuple(
            [subclass.__name__.lower() for subclass in subclasses])
        contents = BaseContent.objects.published().exclude(
            class_name__in=class_names)
        for content in contents:
            content = content.get_real_instance()
            url = _treatment_url(domain, content.public_link())
            if not url:
                continue
            if _treatment_url_microsites and url.startswith(microsite_replace):
                url = url.replace(microsite_replace, domain)
            results.append({
                'url': url,
                'modified_date': content.modification_date,
                'priority': PRIORITY_CHOICES['low']
            })
    return render_to_string("seo/sitemap.xml", {'results': results})
Ejemplo n.º 8
0
 def get_section_prefixes(self):
     return (u'/%s/' % self.url_prefixes[0][0][get_url_default_lang()], )
Ejemplo n.º 9
0
def generate_sitemap(with_portal_links=True, with_menu_portal=True,
                     with_sections=True, with_menu_section=True,
                     with_contents=True, priority_choices=None):
    priority_choices = priority_choices or PRIORITY_CHOICES
    domain = 'http://%s' % Site.objects.get_current().domain
    _treatment_url_microsites = False
    if with_sections or with_contents:
        if 'plugins.microsite.middleware.MicrositeMiddleware' in settings.MIDDLEWARE_CLASSES:
            _treatment_url_microsites = True
            from plugins.microsite.config import PluginConfig
            microsite_prefixes = PluginConfig.url_prefixes[0][0]
            microsite_prefix = microsite_prefixes.get(get_url_default_lang(),
                               microsite_prefixes.get('en', '/microsite/'))
            microsite_replace = '%s/%s' % (domain, microsite_prefix)

    results = []
    if with_portal_links:
        for portal in PortalLink.objects.all():
            url = _treatment_url(domain, portal.get_absolute_url())
            if not url:
                continue
            results.append({'url': url,
                            'modified_date': None,
                            'priority': PRIORITY_CHOICES['high']})
    if with_menu_portal:
        menu_portal = Menu.objects.get(slug=settings.MENU_PORTAL_SLUG)
        for menu in menu_portal.get_descendants().filter(status='public'):
            url = _treatment_url(domain, menu.get_absolute_url())
            if not url:
                continue
            results.append({'url': url,
                            'modified_date': None,
                            'priority': PRIORITY_CHOICES['high']})
    if with_sections:
        sections = BaseSection.objects.published()
        for section in sections:
            section = section.get_real_instance()
            url = _treatment_url(domain, section.public_link())
            if not url:
                continue
            if _treatment_url_microsites and url.startswith(microsite_replace):
                url = url.replace(microsite_replace, domain)
            results.append({'url': url,
                            'modified_date': None,
                            'priority': PRIORITY_CHOICES['high']})
            if with_menu_section:
                menu_section = section.main_menu
                for menu in menu_section.get_descendants().filter(status='public'):
                    url = _treatment_url(domain, menu.get_absolute_url())
                    if not url:
                        continue
                    if _treatment_url_microsites and url.startswith(microsite_replace):
                        url = url.replace(microsite_replace, domain)
                    results.append({'url': url,
                                    'modified_date': None,
                                    'priority': PRIORITY_CHOICES['medium']})
    if with_contents:
        class_names = ('basesection',) + settings.SMAP_EXCLUDE_CLASS_NAME
        subclasses = BaseSection.get_subclasses()
        class_names += tuple([subclass.__name__.lower() for subclass in subclasses])
        contents = BaseContent.objects.published().exclude(class_name__in=class_names)
        for content in contents:
            content = content.get_real_instance()
            url = _treatment_url(domain, content.public_link())
            if not url:
                continue
            if _treatment_url_microsites and url.startswith(microsite_replace):
                url = url.replace(microsite_replace, domain)
            results.append({'url': url,
                            'modified_date': content.modification_date,
                            'priority': PRIORITY_CHOICES['low']})
    return render_to_string("seo/sitemap.xml", {'results': results})
Ejemplo n.º 10
0
 def get_section_prefixes(self):
     return (u'/%s/' % self.url_prefixes[0][0][get_url_default_lang()], )