Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #6 from growlf/master

Merged Theme-name acquisition improvement
  • Loading branch information...
commit 87bad0edfb34349533735b8eedb8278257613e64 2 parents c868da3 + d8a149c
@MegaMark16 authored
View
7 README.rst
@@ -2,7 +2,7 @@ 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
+Dependencies
============
- django (tested with 1.3)
@@ -15,7 +15,7 @@ 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).
+Add ``'cms_themes',`` to your installed apps and ``syncdb`` (or migrate, if you have south installed).
Your installed apps should look something like this:
::
@@ -30,7 +30,8 @@ Your installed apps should look something like this:
'cms_themes',
)
-Make sure that you have a setting in your settings file called PROJECT_DIR that points to the root of your project, i.e. PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
+You should have a setting in your settings file called PROJECT_DIR that points to the root of your project, i.e. ``PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))``
+If not, it will be assumed that your themes will live just beneath the ``MEDIA_ROOT``.
Usage
=============
View
18 cms_themes/__init__.py
@@ -5,17 +5,22 @@
def init_themes():
if not hasattr(settings, 'THEMES_DIR'):
- THEMES_DIR = os.path.join(settings.PROJECT_DIR, 'themes')
+ if hasattr(settings, 'PROJECT_DIR'):
+ THEMES_DIR = os.path.join(settings.PROJECT_DIR, 'themes')
+ elif hasattr(settings, 'PROJECT_HOME'):
+ THEMES_DIR = os.path.join(settings.PROJECT_HOME, 'themes')
+ else:
+ THEMES_DIR = os.path.join(settings.MEDIA_ROOT, 'themes')
if not os.path.exists(THEMES_DIR):
os.makedirs(THEMES_DIR)
settings.STATICFILES_DIRS = (
- ('themes', os.path.join(settings.PROJECT_DIR, "themes")),
+ ('themes', THEMES_DIR),
) + settings.STATICFILES_DIRS
setattr(settings, 'THEMES_DIR', THEMES_DIR)
if not hasattr(settings, 'DEFAULT_CMS_TEMPLATES'):
setattr(settings, 'DEFAULT_CMS_TEMPLATES', settings.CMS_TEMPLATES)
if settings.THEMES_DIR not in settings.TEMPLATE_DIRS:
- settings.TEMPLATE_DIRS = settings.TEMPLATE_DIRS + (settings.THEMES_DIR,)
+ settings.TEMPLATE_DIRS = list(settings.TEMPLATE_DIRS) + [settings.THEMES_DIR,]
if not hasattr(settings, 'DEFAULT_TEMPLATE_DIRS'):
setattr(settings, 'DEFAULT_TEMPLATE_DIRS', settings.TEMPLATE_DIRS)
if not hasattr(settings, 'DEFAULT_STATICFILES_DIRS'):
@@ -38,19 +43,18 @@ def set_themes():
return
theme_templates = []
- theme_static = []
for theme_dir in os.listdir(settings.THEMES_DIR):
if theme_dir in themes:
theme_full_path = os.path.join(settings.THEMES_DIR, theme_dir)
if os.path.isdir(theme_full_path) and 'templates' in os.listdir(theme_full_path):
template_path = os.path.join(theme_full_path, 'templates')
- setattr(settings, 'TEMPLATE_DIRS', (template_path,) + settings.DEFAULT_TEMPLATE_DIRS)
+ setattr(settings, 'TEMPLATE_DIRS', [template_path,] + settings.DEFAULT_TEMPLATE_DIRS)
for template in os.listdir(template_path):
template_display = '%s (%s)' % (template.replace('_', ' ').title().split('.')[0], theme_dir)
theme_templates.append((template, template_display))
- setattr(settings, 'CMS_TEMPLATES', tuple(theme_templates) + settings.DEFAULT_CMS_TEMPLATES)
- setattr(settings, 'STATICFILES_DIRS', (settings.THEMES_DIR,) + settings.DEFAULT_STATICFILES_DIRS)
+ setattr(settings, 'CMS_TEMPLATES', list(theme_templates) + list(settings.DEFAULT_CMS_TEMPLATES))
+ setattr(settings, 'STATICFILES_DIRS', [settings.THEMES_DIR] + list(settings.DEFAULT_STATICFILES_DIRS))
try:
from django.conf import settings
View
2  cms_themes/admin.py
@@ -5,7 +5,7 @@
from django.db import models
class ThemeAdmin(admin.ModelAdmin):
- list_display = ('id','name',)
+ list_display = ('id','name','theme_file',)
list_display_links = ('id','name',)
list_filter = ('name',)
filter_horizontal = ('sites',)
View
2  cms_themes/models.py
@@ -17,7 +17,7 @@ class Theme(models.Model):
def save(self, *args, **kwargs):
if not self.id:
f = tarfile.open(fileobj=self.theme_file, mode='r:gz')
- self.name = f.getnames()[-1]
+ self.name = os.path.commonprefix(f.getnames())
f.extractall(settings.THEMES_DIR)
super(Theme, self).save(*args, **kwargs)
Please sign in to comment.
Something went wrong with that request. Please try again.