Changeset 50


Ignore:
Timestamp:
08/05/09 23:04:04 (3 years ago)
Author:
msaelices
Message:

Three things:

  • I forgot upload some files:
    • templates/themes/ directory, with two example dummy themes
    • apps/themes/checker.py
    • apps/base/templates/base.html
  • Refactor, putting updating theme info logic into model.
  • Improve checker function to make transaction aware.

Fixes #23.

Location:
trunk/merengueproj
Files:
9 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/merengueproj/apps/themes/__init__.py

    r42 r50  
    1818        for theme_dir in os.listdir(themes_root): 
    1919            yield theme_dir, safe_join(themes_root, theme_dir) 
     20 
     21 
     22def get_theme_path(directory_name=None): 
     23    for theme_dir, theme_path in get_theme_dirs(): 
     24        if directory_name == theme_dir: 
     25            return theme_path 
  • trunk/merengueproj/apps/themes/admin.py

    r42 r50  
    1 from base.admin import BaseAdmin 
     1from base.admin import BaseAdmin, set_field_read_only 
    22from themes.checker import check_themes 
    33from themes.models import Theme 
     
    55 
    66class ThemeAdmin(BaseAdmin): 
    7     readonly_fields = ('name', 'description', 'directory_name') 
    8     list_display = ('name', 'directory_name', 'enabled', 'active') 
     7    readonly_fields = ('name', 'description', 'directory_name', 'installed') 
     8    list_display = ('name', 'directory_name', 'installed', 'active') 
     9 
     10    def get_form(self, request, obj=None): 
     11        form = super(ThemeAdmin, self).get_form(request, obj) 
     12        if not obj.installed: 
     13            set_field_read_only(form.base_fields['active'], 'active', obj) 
     14        return form 
    915 
    1016    def changelist_view(self, request, extra_context=None): 
  • trunk/merengueproj/apps/themes/models.py

    r42 r50  
     1import os 
     2import ConfigParser 
     3 
    14from django.db import models 
    25from django.db.models import signals 
    36from django.utils.translation import ugettext_lazy as _ 
    47 
     8from themes import get_theme_path 
    59from themes.managers import ThemeManager 
    610 
     
    913    name = models.CharField(_('name'), max_length=100) 
    1014    description = models.TextField(_('description')) 
    11     enabled = models.BooleanField(default=False) 
     15    installed = models.BooleanField(default=False) 
    1216    active = models.BooleanField(default=False) 
    1317    directory_name = models.CharField(_('directory name'), max_length=100) 
     
    1721    def __unicode__(self): 
    1822        return self.name 
     23 
     24    def get_path(self): 
     25        """ get theme template path """ 
     26        return get_theme_path(self.directory_name) 
     27 
     28    def update_from_fs(self, commit=True): 
     29        """ update theme info from filesystem """ 
     30        theme_info_file = os.path.join(self.get_path(), 'theme.info') 
     31        if os.path.isfile(theme_info_file): 
     32            config = ConfigParser.ConfigParser() 
     33            config.read(theme_info_file) 
     34            theme_name = config.get(ConfigParser.DEFAULTSECT, 'name', self.directory_name) 
     35            theme_description = config.get(ConfigParser.DEFAULTSECT, 'description', '') 
     36        else: 
     37            theme_name = self.directory_name 
     38            theme_description = '' 
     39        self.name = theme_name 
     40        self.description = theme_description 
     41        if commit: 
     42            self.save() 
    1943 
    2044 
Note: See TracChangeset for help on using the changeset viewer.