Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit a1940dee429a4f9b23c3c493dfbbdb85442d041e @MegaMark16 MegaMark16 committed Apr 13, 2011
@@ -0,0 +1,11 @@
+*.pyc
+*.vim
+*.swp
+*.py~
+*.html~
+*.txt~
+.DS_Store
+pip-log.txt
+build
+dist
+*.egg-info
@@ -0,0 +1,2 @@
+* Andrew Schoen <andrew.schoen@gmail.com>
+* Mark Ransom <megamark16@gmail.com>
10 LICENSE
@@ -0,0 +1,10 @@
+Copyright (c) 2011, Salva O'Renick
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+* Neither the name of the Salva O'Renick nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,3 @@
+include AUTHORS
+include LICENSE
+include README.rst
@@ -0,0 +1,36 @@
+django-cms-redirects
+=================
+A django app that lets you store simple redirects in a database and handles the redirecting for you. Integrated with Django CMS to allow you to link directly to a page object. Inherits from django.contrib.redirects, but overrides the middleware.
+
+Dependancies
+============
+
+- django
+- django-cms
+
+Getting Started
+=============
+
+To get started simply install using ``pip``:
+::
+ pip install django-cms-redirects
+
+Add ``cms_redirects`` to your installed apps and ``syncdb``. If you are using ``south`` you might want to ``syncdb --all`` and ``migrate --fake``
+
+Your installed apps should look something like this:
+::
+ INSTALLED_APPS = (
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.sites',
+ 'django.contrib.messages',
+ 'django.contrib.admin',
+ 'cms',
+ 'cms_redirects',
+ )
+
+Finally, add 'cms_redirects.middleware.RedirectFallbackMiddleware' to your MIDDLEWARE_CLASSES setting.
+
+
+
@@ -0,0 +1,2 @@
+VERSION = (1,0,0)
+__version__ = "1.0.0"
@@ -0,0 +1,10 @@
+from django.contrib import admin
+from cms_redirects.models import CMSRedirect
+
+class CMSRedirectAdmin(admin.ModelAdmin):
+ list_display = ('old_path', 'new_path', 'page')
+ list_filter = ('site',)
+ search_fields = ('old_path', 'new_path', 'page')
+ radio_fields = {'site': admin.VERTICAL}
+
+admin.site.register(CMSRedirect, CMSRedirectAdmin)
@@ -0,0 +1,29 @@
+from cms_redirects.models import CMSRedirect
+from django import http
+from django.conf import settings
+
+class RedirectFallbackMiddleware(object):
+ def process_response(self, request, response):
+ if response.status_code != 404:
+ return response # No need to check for a redirect for non-404 responses.
+ path = request.get_full_path()
+ try:
+ r = CMSRedirect.objects.get(site__id__exact=settings.SITE_ID, old_path=path)
+ except CMSRedirect.DoesNotExist:
+ r = None
+ if r is None and settings.APPEND_SLASH:
+ # Try removing the trailing slash.
+ try:
+ r = CMSRedirect.objects.get(site__id__exact=settings.SITE_ID,
+ old_path=path[:path.rfind('/')]+path[path.rfind('/')+1:])
+ except CMSRedirect.DoesNotExist:
+ pass
+ if r is not None:
+ if r.page:
+ return http.HttpResponsePermanentRedirect(r.page.get_absolute_url())
+ if r.new_path == '':
+ return http.HttpResponseGone()
+ return http.HttpResponsePermanentRedirect(r.new_path)
+
+ # No redirect was found. Return the response.
+ return response
@@ -0,0 +1,80 @@
+# 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 'CMSRedirect'
+ db.create_table('cms_redirects_cmsredirect', (
+ ('redirect_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['redirects.Redirect'], unique=True, primary_key=True)),
+ ('page_link', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['cms.Page'], null=True, blank=True)),
+ ))
+ db.send_create_signal('cms_redirects', ['CMSRedirect'])
+
+
+ def backwards(self, orm):
+
+ # Deleting model 'CMSRedirect'
+ db.delete_table('cms_redirects_cmsredirect')
+
+
+ models = {
+ 'cms.page': {
+ 'Meta': {'ordering': "('site', 'tree_id', 'lft')", 'object_name': 'Page'},
+ 'changed_by': ('django.db.models.fields.CharField', [], {'max_length': '70'}),
+ 'created_by': ('django.db.models.fields.CharField', [], {'max_length': '70'}),
+ 'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'in_navigation': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'db_index': 'True'}),
+ 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'limit_visibility_in_menu': ('django.db.models.fields.SmallIntegerField', [], {'default': 'None', 'null': 'True', 'db_index': 'True', 'blank': 'True'}),
+ 'login_required': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'moderator_state': ('django.db.models.fields.SmallIntegerField', [], {'default': '1', 'blank': 'True'}),
+ 'navigation_extenders': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '80', 'null': 'True', 'blank': 'True'}),
+ 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['cms.Page']"}),
+ 'placeholders': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['cms.Placeholder']", 'symmetrical': 'False'}),
+ 'publication_date': ('django.db.models.fields.DateTimeField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
+ 'publication_end_date': ('django.db.models.fields.DateTimeField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
+ 'published': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'publisher_is_draft': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'db_index': 'True'}),
+ 'publisher_public': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'publisher_draft'", 'unique': 'True', 'null': 'True', 'to': "orm['cms.Page']"}),
+ 'publisher_state': ('django.db.models.fields.SmallIntegerField', [], {'default': '0', 'db_index': 'True'}),
+ 'reverse_id': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '40', 'null': 'True', 'blank': 'True'}),
+ 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
+ 'soft_root': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}),
+ 'template': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ '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'})
+ },
+ 'cms_redirects.cmsredirect': {
+ 'Meta': {'ordering': "('old_path',)", 'object_name': 'CMSRedirect', '_ormbases': ['redirects.Redirect']},
+ 'page_link': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Page']", 'null': 'True', 'blank': 'True'}),
+ 'redirect_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['redirects.Redirect']", 'unique': 'True', 'primary_key': 'True'})
+ },
+ 'redirects.redirect': {
+ 'Meta': {'ordering': "('old_path',)", 'unique_together': "(('site', 'old_path'),)", 'object_name': 'Redirect', 'db_table': "'django_redirect'"},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'new_path': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'}),
+ 'old_path': ('django.db.models.fields.CharField', [], {'max_length': '200', 'db_index': 'True'}),
+ 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"})
+ },
+ 'sites.site': {
+ 'Meta': {'ordering': "('domain',)", 'object_name': 'Site', 'db_table': "'django_site'"},
+ 'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ }
+ }
+
+ complete_apps = ['cms_redirects']
@@ -0,0 +1,82 @@
+# 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):
+
+ # Deleting field 'CMSRedirect.page_link'
+ db.delete_column('cms_redirects_cmsredirect', 'page_link_id')
+
+ # Adding field 'CMSRedirect.page'
+ db.add_column('cms_redirects_cmsredirect', 'page', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['cms.Page'], null=True, blank=True), keep_default=False)
+
+
+ def backwards(self, orm):
+
+ # Adding field 'CMSRedirect.page_link'
+ db.add_column('cms_redirects_cmsredirect', 'page_link', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['cms.Page'], null=True, blank=True), keep_default=False)
+
+ # Deleting field 'CMSRedirect.page'
+ db.delete_column('cms_redirects_cmsredirect', 'page_id')
+
+
+ models = {
+ 'cms.page': {
+ 'Meta': {'ordering': "('site', 'tree_id', 'lft')", 'object_name': 'Page'},
+ 'changed_by': ('django.db.models.fields.CharField', [], {'max_length': '70'}),
+ 'created_by': ('django.db.models.fields.CharField', [], {'max_length': '70'}),
+ 'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'in_navigation': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'db_index': 'True'}),
+ 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'limit_visibility_in_menu': ('django.db.models.fields.SmallIntegerField', [], {'default': 'None', 'null': 'True', 'db_index': 'True', 'blank': 'True'}),
+ 'login_required': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'moderator_state': ('django.db.models.fields.SmallIntegerField', [], {'default': '1', 'blank': 'True'}),
+ 'navigation_extenders': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '80', 'null': 'True', 'blank': 'True'}),
+ 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['cms.Page']"}),
+ 'placeholders': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['cms.Placeholder']", 'symmetrical': 'False'}),
+ 'publication_date': ('django.db.models.fields.DateTimeField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
+ 'publication_end_date': ('django.db.models.fields.DateTimeField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
+ 'published': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'publisher_is_draft': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'db_index': 'True'}),
+ 'publisher_public': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'publisher_draft'", 'unique': 'True', 'null': 'True', 'to': "orm['cms.Page']"}),
+ 'publisher_state': ('django.db.models.fields.SmallIntegerField', [], {'default': '0', 'db_index': 'True'}),
+ 'reverse_id': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '40', 'null': 'True', 'blank': 'True'}),
+ 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
+ 'soft_root': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}),
+ 'template': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ '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'})
+ },
+ 'cms_redirects.cmsredirect': {
+ 'Meta': {'ordering': "('old_path',)", 'object_name': 'CMSRedirect', '_ormbases': ['redirects.Redirect']},
+ 'page': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Page']", 'null': 'True', 'blank': 'True'}),
+ 'redirect_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['redirects.Redirect']", 'unique': 'True', 'primary_key': 'True'})
+ },
+ 'redirects.redirect': {
+ 'Meta': {'ordering': "('old_path',)", 'unique_together': "(('site', 'old_path'),)", 'object_name': 'Redirect', 'db_table': "'django_redirect'"},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'new_path': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'}),
+ 'old_path': ('django.db.models.fields.CharField', [], {'max_length': '200', 'db_index': 'True'}),
+ 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"})
+ },
+ 'sites.site': {
+ 'Meta': {'ordering': "('domain',)", 'object_name': 'Site', 'db_table': "'django_site'"},
+ 'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ }
+ }
+
+ complete_apps = ['cms_redirects']
No changes.
@@ -0,0 +1,9 @@
+from django.contrib.redirects.models import Redirect
+from django.utils.translation import ugettext_lazy as _
+from cms.models.fields import PageField
+
+from cms.models import Page
+
+class CMSRedirect(Redirect):
+ page = PageField(verbose_name=_("page"), blank=True, null=True, help_text=_("A link to a page has priority over a text link."))
+
@@ -0,0 +1,39 @@
+from setuptools import setup, find_packages
+import os
+
+version = __import__('multimedia').__version__
+
+install_requires = [
+ 'setuptools',
+ 'django',
+ 'django-cms',
+]
+
+setup(
+ name = "django-cms-redirects",
+ version = version,
+ url = 'http://github.com/salvaorenick/django-cms-redirects',
+ license = 'BSD',
+ platforms=['OS Independent'],
+ description = "",
+ author = "Andrew Schoen",
+ author_email = 'andrew.schoen@gmail.com',
+ packages=find_packages(),
+ install_requires = install_requires,
+ include_package_data=True,
+ zip_safe=False,
+ classifiers = [
+ 'Development Status :: 5 - Production/Stable',
+ 'Framework :: Django',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: BSD License',
+ 'Operating System :: OS Independent',
+ 'Programming Language :: Python',
+ 'Topic :: Internet :: WWW/HTTP',
+ 'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
+ 'Topic :: Internet :: WWW/HTTP :: Site Management :: Link Checking',
+ ],
+ package_dir={
+ 'cms_redirects': 'cms_redirects',
+ },
+)

0 comments on commit a1940de

Please sign in to comment.