Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #1 from gw0/master
Added configurable plugin options for filtering listed pages.
  • Loading branch information
Raphael Jasjukaitis committed Dec 25, 2011
2 parents 5caab5f + 6152187 commit 8c2365c
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 11 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
@@ -1,2 +1,3 @@
include README.rst
recursive-include cmsplugin_htmlsitemap/templates *
recursive-include cmsplugin_htmlsitemap/migrations *.py
29 changes: 26 additions & 3 deletions README.rst
Expand Up @@ -12,11 +12,34 @@ Requirements
Installation
============

Using pip to install the plugin::
Using PyPI you can simply type into a terminal:

pip install cmsplugin-htmlsitemap
pip install cmsplugin-htmlsitemap

or

easy_install cmsplugin-htmlsitemap

Configuration
=============

Add ``cmsplugin_htmlsitemap`` to the list of ``INSTALLED_APPS`` in your ``settings.py`` file.
Add ``cmsplugin_htmlsitemap`` to the list of ``INSTALLED_APPS`` in your
``settings.py`` file. Don't forget to syncdb your database or migrate if you're
using ``south``.

After adding the CMS plugin you can configure filtering of 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

Author
======

Copyright 2011 Raphael Jasjukaitis <webmaster@raphaa.de>
Credits to GW <gw.2011@tnode.com or http://gw.tnode.com/>

Released under the BSD license.
29 changes: 22 additions & 7 deletions cmsplugin_htmlsitemap/cms_plugins.py
@@ -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)

63 changes: 63 additions & 0 deletions cmsplugin_htmlsitemap/migrations/0001_initial.py
@@ -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']
Empty file.
28 changes: 28 additions & 0 deletions cmsplugin_htmlsitemap/models.py
@@ -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)

2 changes: 1 addition & 1 deletion setup.py 100644 → 100755
Expand Up @@ -4,7 +4,7 @@

setup(
name='cmsplugin-htmlsitemap',
version='0.1.0',
version='0.1.1',
description='HTML sitemap plugin for Django CMS',
long_description=open(os.path.join(os.path.dirname(__file__), 'README.rst')).read(),
author='Raphael Jasjukaitis',
Expand Down

0 comments on commit 8c2365c

Please sign in to comment.