Skip to content
Permalink
Browse files

Added configurable plugin options for filtering listed pages.

  • Loading branch information...
gw0 committed Sep 14, 2011
1 parent 5caab5f commit 7c99d20a0693114a891180e0d706c085af05898b
@@ -1,2 +1,3 @@
include README.rst
recursive-include cmsplugin_htmlsitemap/templates *
recursive-include cmsplugin_htmlsitemap/migrations *.py
@@ -20,3 +20,13 @@ Configuration
=============

Add ``cmsplugin_htmlsitemap`` to the list of ``INSTALLED_APPS`` in your ``settings.py`` file.

After adding the CMS plugin you can filter listed pages by their:

* starting/minimal level
* deepest/maximal level
* is in navigation
* exact match on created by
* match title containing substring
* URL match with regular expression

@@ -1,24 +1,39 @@
# -*- coding: utf-8 -*-

from django.contrib.sites.models import Site
from django.utils.translation import ugettext as _
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')
context.update(
{'instance': instance,
'pages': pages
}
)
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)

@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
from django.db import models
from django.utils.translation import ugettext_lazy as _

from cms.models import CMSPlugin


class HtmlSitemap(CMSPlugin):
"""Model for HTML Sitemap CMS plugin."""

level_min = models.PositiveSmallIntegerField(_('starting level'), default=0)
level_max = models.PositiveSmallIntegerField(_('deepest level'), default=100)
in_navigation = models.NullBooleanField(_('is in navigation'), default=None)
match_created_by = models.CharField(_('exact match on created by'), blank=True,
max_length=70)
match_title = models.CharField(_('match title containing substring'), blank=True,
max_length=255)
match_url = models.CharField(_('URL match with regular expression'), blank=True,
max_length=100)

class Meta:
verbose_name = _('HTML Sitemap plugin')
verbose_name_plural = _('HTML Sitemap plugins')
ordering = ('level_min', 'level_max')

def __unicode__(self):
return u'HTML Sitemap {0}-{1}'.format(self.level_min, self.level_max)

@@ -0,0 +1,63 @@
# encoding: utf-8
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models

class Migration(SchemaMigration):

def forwards(self, orm):

# Adding model 'HtmlSitemap'
db.create_table('cmsplugin_htmlsitemap', (
('cmsplugin_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['cms.CMSPlugin'], unique=True, primary_key=True)),
('level_min', self.gf('django.db.models.fields.PositiveSmallIntegerField')(default=0)),
('level_max', self.gf('django.db.models.fields.PositiveSmallIntegerField')(default=100)),
('in_navigation', self.gf('django.db.models.fields.NullBooleanField')(default=None, null=True, blank=True)),
('match_created_by', self.gf('django.db.models.fields.CharField')(max_length=70, blank=True)),
('match_title', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
('match_url', self.gf('django.db.models.fields.CharField')(max_length=100, blank=True)),
))
db.send_create_signal('cmsplugin_htmlsitemap', ['HtmlSitemap'])


def backwards(self, orm):

# Deleting model 'HtmlSitemap'
db.delete_table('cmsplugin_htmlsitemap')


models = {
'cms.cmsplugin': {
'Meta': {'object_name': 'CMSPlugin'},
'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'language': ('django.db.models.fields.CharField', [], {'max_length': '15', 'db_index': 'True'}),
'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
'parent': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.CMSPlugin']", 'null': 'True', 'blank': 'True'}),
'placeholder': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']", 'null': 'True'}),
'plugin_type': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
'position': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})
},
'cms.placeholder': {
'Meta': {'object_name': 'Placeholder'},
'default_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'slot': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'})
},
'cmsplugin_htmlsitemap.htmlsitemap': {
'Meta': {'ordering': "('level_min', 'level_max')", 'object_name': 'HtmlSitemap', 'db_table': "'cmsplugin_htmlsitemap'", '_ormbases': ['cms.CMSPlugin']},
'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}),
'in_navigation': ('django.db.models.fields.NullBooleanField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}),
'level_max': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '100'}),
'level_min': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '0'}),
'match_created_by': ('django.db.models.fields.CharField', [], {'max_length': '70', 'blank': 'True'}),
'match_title': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
'match_url': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'})
}
}

complete_apps = ['cmsplugin_htmlsitemap']
No changes.
0 setup.py 100644 → 100755
No changes.

0 comments on commit 7c99d20

Please sign in to comment.
You can’t perform that action at this time.