Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 4f7ee266d8edb91e2617df00a5656010d4ec0ee4 Mark Ransom committed Oct 22, 2011
@@ -0,0 +1,14 @@
+*.pyc
+*.vim
+*.swp
+*.py~
+*.html~
+*.txt~
+.DS_Store
+pip-log.txt
+build
+dist
+*.egg-info
+*.db
+*.tar.gz
+demo/themes/*
@@ -0,0 +1 @@
+* Mark Ransom <megamark16@gmail.com>
10 LICENSE
@@ -0,0 +1,10 @@
+Copyright (c) 2011, Mark Ransom
+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,42 @@
+django-cms-themes
+=================
+A django app that lets you load theme packs that are bundled templates, and select which theme a site should use.
+
+Dependancies
+============
+
+- django
+- django-cms
+
+Getting Started
+=============
+
+To get started simply install using ``pip``:
+::
+ pip install django-cms-themes
+
+Add ``cms_themes`` to your installed apps and ``syncdb`` (or migrate, if you have south installed).
+
+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_themes',
+ )
+
+
+Create a ``themes`` folder under the root of your webapp, and then create a symlink to that themes folder under your MEDIA_ROOT, as that is how most of the themes will assume the media is setup.
+
+Usage
+=============
+
+All usage is done through the admin.
+
+Simply create a new Theme record and upload a theme tarball (tar.gz) file from djangocmsthemes.com. All templates from themes uploaded should now show up in your Templates drop down on a django cms page.
+
@@ -0,0 +1,42 @@
+VERSION = (1,0,0)
+__version__ = "1.0.0"
+import random
+import os
+
+from django.conf import settings
+from django.contrib.sites.models import Site
+
+PROJECT_DIR = settings.PROJECT_DIR
+CMS_TEMPLATES = getattr(settings, 'CMS_TEMPLATES', ())
+
+if hasattr(settings, 'THEMES_DIR'):
+ THEMES_DIR = settings.THEMES_DIR
+else:
+ THEMES_DIR = os.path.join(PROJECT_DIR, 'themes')
+ setattr(settings, 'THEMES_DIR', THEMES_DIR)
+
+class cms_templates_iterable(object):
+ def __iter__(self):
+ return iter(self.get_themes())
+ def __len__(self):
+ return len(self.get_themes())
+ def __getitem__(self, index):
+ return self.get_themes()[index]
+
+ def get_themes(self):
+ try:
+ site = Site.objects.get(id=settings.SITE_ID)
+ themes = [theme[0] for theme in site.theme_set.values_list('name')]
+ except:
+ themes = []
+ theme_templates = []
+
+ for theme_dir in os.listdir(THEMES_DIR):
+ if theme_dir in themes or not len(themes):
+ theme_full_path = os.path.join(THEMES_DIR, theme_dir)
+ if 'templates' in os.listdir(theme_full_path):
+ template_path = os.path.join(theme_full_path, 'templates')
+ for template in os.listdir(template_path):
+ theme_templates.append((os.path.join(theme_dir, 'templates', template), '%s (%s)' % (template, theme_dir)))
+ return theme_templates
+setattr(settings, 'CMS_TEMPLATES', cms_templates_iterable())
@@ -0,0 +1,12 @@
+from django.contrib import admin, messages
+from models import Theme
+from django.conf import settings
+
+class ThemeAdmin(admin.ModelAdmin):
+ list_display = ('id','name',)
+ list_display_links = ('id','name',)
+ list_filter = ('name',)
+ filter_horizontal = ('sites',)
+
+admin.site.register(Theme, ThemeAdmin)
+
@@ -0,0 +1,51 @@
+# 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 'Theme'
+ db.create_table('cms_themes_theme', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('name', self.gf('django.db.models.fields.CharField')(max_length=255)),
+ ))
+ db.send_create_signal('cms_themes', ['Theme'])
+
+ # Adding M2M table for field sites on 'Theme'
+ db.create_table('cms_themes_theme_sites', (
+ ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+ ('theme', models.ForeignKey(orm['cms_themes.theme'], null=False)),
+ ('site', models.ForeignKey(orm['sites.site'], null=False))
+ ))
+ db.create_unique('cms_themes_theme_sites', ['theme_id', 'site_id'])
+
+
+ def backwards(self, orm):
+
+ # Deleting model 'Theme'
+ db.delete_table('cms_themes_theme')
+
+ # Removing M2M table for field sites on 'Theme'
+ db.delete_table('cms_themes_theme_sites')
+
+
+ models = {
+ 'cms_themes.theme': {
+ 'Meta': {'object_name': 'Theme'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'sites': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['sites.Site']", 'symmetrical': 'False'})
+ },
+ '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_themes']
@@ -0,0 +1,37 @@
+# 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 field 'Theme.theme_file'
+ db.add_column('cms_themes_theme', 'theme_file', self.gf('django.db.models.fields.files.FileField')(default=None, max_length=100), keep_default=False)
+
+
+ def backwards(self, orm):
+
+ # Deleting field 'Theme.theme_file'
+ db.delete_column('cms_themes_theme', 'theme_file')
+
+
+ models = {
+ 'cms_themes.theme': {
+ 'Meta': {'object_name': 'Theme'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'sites': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['sites.Site']", 'null': 'True', 'blank': 'True'}),
+ 'theme_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100'})
+ },
+ '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_themes']
No changes.
@@ -0,0 +1,25 @@
+from django.conf import settings
+from django.db import models
+from django.contrib.sites.models import Site
+from django.db.models.signals import post_save, pre_save
+import tarfile
+import StringIO
+
+class Theme(models.Model):
+ sites = models.ManyToManyField(Site, null=True, blank=True)
+ name = models.CharField(max_length=255)
+ theme_file = models.FileField(upload_to='themes_archives', null=True)
+
+ class Meta:
+ verbose_name = "Theme"
+ verbose_name_plural = "Themes"
+
+def extract_theme(sender, **kwargs):
+ instance = kwargs['instance']
+ if not instance.id:
+ print dir(instance.theme_file)
+ f = tarfile.open(fileobj=instance.theme_file, mode='r:gz')
+ f.extractall(settings.THEMES_DIR)
+
+pre_save.connect(extract_theme, sender=Theme)
+
No changes.
@@ -0,0 +1,11 @@
+#!/usr/bin/env python
+from django.core.management import execute_manager
+try:
+ import settings # Assumed to be in the same directory.
+except ImportError:
+ import sys
+ sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
+ sys.exit(1)
+
+if __name__ == "__main__":
+ execute_manager(settings)
@@ -0,0 +1,4 @@
+django==1.2.5
+django-cms==2.1.3
+django-appmedia
+south
Oops, something went wrong.

0 comments on commit 4f7ee26

Please sign in to comment.