Permalink
Browse files

Now the theme name is determined by the root folder of the theme in t…

…he archive
  • Loading branch information...
Mark Ransom
Mark Ransom committed Oct 23, 2011
1 parent bc8c8ae commit 500320646e370d3198fe076949c543d093982a38
Showing with 10 additions and 4 deletions.
  1. +4 −2 cms_themes/__init__.py
  2. +1 −1 cms_themes/admin.py
  3. +5 −1 cms_themes/models.py
View
@@ -17,7 +17,9 @@
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,)
+
def set_themes():
try:
site = Site.objects.get(id=settings.SITE_ID)
@@ -32,7 +34,7 @@ def set_themes():
if 'templates' in os.listdir(theme_full_path):
template_path = os.path.join(theme_full_path, 'templates')
for template in os.listdir(template_path):
- template_path = os.path.join('themes', theme_dir, 'templates', template)
+ template_path = os.path.join(theme_dir, 'templates', template)
theme_templates.append((template_path, '%s (%s)' % (template, theme_dir)))
setattr(settings, 'CMS_TEMPLATES', tuple(theme_templates) + settings.DEFAULT_CMS_TEMPLATES)
View
@@ -7,6 +7,6 @@ class ThemeAdmin(admin.ModelAdmin):
list_display_links = ('id','name',)
list_filter = ('name',)
filter_horizontal = ('sites',)
-
+ readonly_fields = ('name',)
admin.site.register(Theme, ThemeAdmin)
View
@@ -11,17 +11,21 @@
class Theme(models.Model):
sites = models.ManyToManyField(Site, null=True, blank=True)
- name = models.CharField(max_length=255)
+ name = models.CharField(max_length=255, blank=True)
theme_file = models.FileField(upload_to='themes_archives', null=True)
class Meta:
verbose_name = "Theme"
verbose_name_plural = "Themes"
+ def __unicode__(self):
+ return self.name
+
def extract_theme(sender, **kwargs):
instance = kwargs['instance']
if not instance.id:
f = tarfile.open(fileobj=instance.theme_file, mode='r:gz')
+ instance.name = f.getnames()[-1]
f.extractall(settings.THEMES_DIR)
set_themes()

0 comments on commit 5003206

Please sign in to comment.