Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 7c99d20a06
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 40 lines (32 sloc) 1.442 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
# -*- coding: utf-8 -*-
from django.contrib.sites.models import Site
from django.utils.translation import ugettext_lazy as _

from cms.models.pagemodel import Page
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from cmsplugin_htmlsitemap import models
import re


class HtmlSitemapPlugin(CMSPluginBase):
    """HTML Sitemap CMS plugin."""

    name = _('HTML Sitemap')
    model = models.HtmlSitemap
    render_template = 'cmsplugin_htmlsitemap/sitemap.html'

    def render(self, context, instance, placeholder):
        site = Site.objects.get_current()
        pages = Page.objects.published(site=site).order_by('tree_id', 'lft')
        pages = pages.filter(level__gte=instance.level_min, level__lte=instance.level_max)
        if not instance.in_navigation is None:
            pages = pages.filter(in_navigation=instance.in_navigation)
        if instance.match_created_by:
            pages = pages.filter(created_by=instance.match_created_by)
        if instance.match_title:
            pages = pages.filter(title_set__title__contains=instance.match_title)
        if instance.match_url:
            pat = re.compile(instance.match_url, re.IGNORECASE)
            pages = [ p for p in pages if pat.search(p.get_absolute_url()) ]
        context.update({
            'instance':instance,
            'pages':pages,
        })
        return context

plugin_pool.register_plugin(HtmlSitemapPlugin)

Something went wrong with that request. Please try again.