Beispiel #1
0
 def has_action(self, request, content):
     user = request.user
     if user.is_anonymous():
         return False
     if not self.match_type(content):
         return False
     if user.is_superuser:
         return True
     class_names = ['basesection']
     subclasses = BaseSection.get_subclasses()
     class_names += [subclass.__name__.lower() for subclass in subclasses]
     return user.contents_owned.filter(class_name__in=class_names).exists()
Beispiel #2
0
 def has_action(self, request, content):
     user = request.user
     if user.is_anonymous():
         return False
     if not self.match_type(content):
         return False
     if user.is_superuser:
         return True
     class_names = ['basesection']
     subclasses = BaseSection.get_subclasses()
     class_names += [subclass.__name__.lower() for subclass in subclasses]
     return user.contents_owned.filter(class_name__in=class_names).exists()
Beispiel #3
0
def contents_stats(context, user=None, expanded=1):
    basecontents = get_contents(user, expanded)
    contents = []
    sections = []
    section_classes = [BaseSection] + BaseSection.get_subclasses()
    section_class_names = [section_class._meta.module_name for section_class in section_classes]
    message = None
    if isinstance(basecontents, list):
        for content, visit in basecontents:
            if content.class_name in section_class_names:
                sections.append((content, visit))
            else:
                contents.append((content, visit))
    elif isinstance(basecontents, dict) and basecontents["result"] == "error":
        message = basecontents.get("message", basecontents["result"])
    return {"contents": contents, "sections": sections, "message": message, "request": context.get("request")}
Beispiel #4
0
def contents_stats(context, user=None, expanded=1):
    basecontents = get_contents(user, expanded)
    contents = []
    sections = []
    section_classes = [BaseSection] + BaseSection.get_subclasses()
    section_class_names = [
        section_class._meta.module_name for section_class in section_classes
    ]
    message = None
    if isinstance(basecontents, list):
        for content, visit in basecontents:
            if content.class_name in section_class_names:
                sections.append((content, visit))
            else:
                contents.append((content, visit))
    elif isinstance(basecontents, dict) and basecontents['result'] == 'error':
        message = basecontents.get('message', basecontents['result'])
    return {
        'contents': contents,
        'sections': sections,
        'message': message,
        'request': context.get('request')
    }
Beispiel #5
0
 def __init__(self, user, content, data=None, *args, **kwargs):
     super(HotLinkForm, self).__init__(data, *args, **kwargs)
     self.content = content
     self.only_menu = True
     if user.is_superuser:
         choices = BaseSection.objects.all()
     else:
         class_names = ['basesection']
         subclasses = BaseSection.get_subclasses()
         class_names += [subclass.__name__.lower() for subclass in subclasses]
         choices = user.contents_owned.filter(class_name__in=class_names)
     if choices.count() == 1:
         self.fields['section'] = forms.ModelChoiceField(initial=choices[0],
                                                          queryset=choices,
                                                          label='',
                                                          widget=forms.HiddenInput)
     else:
         self.fields['section'] = forms.ModelChoiceField(queryset=choices,
                                                          label=_('Section'),
                                                          required=True,
                                                          help_text=_('Choose a section where save the menu'))
     name_lang = transmeta.get_real_fieldname('name', settings.LANGUAGE_CODE)
     self.fields['slug'].required = False
     if not data:
         self.fields['slug'].label = ''
         self.fields['slug'].widget = forms.HiddenInput()
     self.fields[name_lang].label = _('Name')
     self.fields[name_lang].initial = getattr(content, name_lang, unicode(content))
     try:
         get_plugin('standingout')
         self.fields['where_link'] = forms.ChoiceField(label=_('How do you want link?'),
                                                       choices=(('m', _('menu'),),
                                                                ('s', _('standing out'),)))
         self.fields['visible_by_roles'].help_text = _('The roles that will see this menu. Only if you select the choice link like menu')
         self.only_menu = False
     except ImportError:
         pass
Beispiel #6
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})
Beispiel #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})