def create_from_fs(path): """ update theme info from filesystem """ theme_info_file = os.path.join(path, 'theme.info') directory_name = os.path.basename(path) ref = Theme.get(directory_name=directory_name) if ref: return False if os.path.isfile(theme_info_file): config = ConfigParser.ConfigParser() config.read(theme_info_file) theme_name = config.get(ConfigParser.DEFAULTSECT, 'name', directory_name) theme_description = config.get(ConfigParser.DEFAULTSECT, 'description') else: theme_name = directory_name theme_description = '' params = {'name': theme_name, 'description': theme_description, 'installed': True, 'active': False, 'directory_name': directory_name} theme_ref = Theme(**params) return theme_ref.put()
def __init__(self, *args, **kwargs): logging.info(">> AdminSiteForm") super(AdminSiteForm, self).__init__(*args, **kwargs) self.fields['site_name'].initial = ConfigData.get_configdata('SITE_NAME') self.fields['meta_description'].initial = ConfigData.get_configdata('SITE_DESCRIPTION') self.fields['meta_keywords'].initial = ConfigData.get_configdata('SITE_KEYWORDS') self.fields['theme'].widget = forms.Select(choices=Theme.get_choices()) self.fields['theme'].initial = Theme.get_active().uuid
def check_themes(): """ check themes found in file system and compare with registered one in database """ # first disable all themes for theme in Theme.all(): theme.installed = False theme.put() # now look for all themes in filesystem and enable them for theme_dir, theme_path in get_theme_dirs(): #theme, created = Theme.objects.get_or_create(directory_name=theme_dir) create_from_fs(theme_path) active_theme = Theme.get_active() if not active_theme: ref = Theme.get(directory_name=settings.DEFAULT_THEME) ref.active = True ref.put()
def get_global_vars(): params = getattr(settings, 'GLOBALS') params.update({'SITE_NAME':ConfigData.get_configdata('SITE_NAME'), 'SITE_DESCRIPTION':ConfigData.get_configdata('SITE_DESCRIPTION'), 'SITE_KEYWORDS':ConfigData.get_configdata('SITE_KEYWORDS'), 'MEDIA_URL':settings.MEDIA_URL, 'DOMAIN':settings.DOMAIN, 'THEME_MEDIA_URL':settings.THEME_URL + Theme.get_active().directory_name + '/'}) return params
def get_template_sources(template_name, template_dirs=None): from common.models import Theme active_theme = Theme.get_active() if not active_theme: check_themes() for themes_dir in get_theme_root_dirs(template_dirs): active_theme_dir = safe_join(themes_dir, active_theme.directory_name) try: yield safe_join(active_theme_dir, template_name) except UnicodeDecodeError: raise except ValueError: pass
def save(self): ConfigData.set_configdata('SITE_NAME', self.cleaned_data['site_name']) ConfigData.set_configdata('SITE_DESCRIPTION', self.cleaned_data['meta_description']) ConfigData.set_configdata('SITE_KEYWORDS', self.cleaned_data['meta_keywords']) Theme.check_for_duplicated_active_themes(self.cleaned_data['theme']) return True
def _flag_as_admin(context): admin_theme_url = settings.THEME_URL + Theme.get_admin().directory_name + '/' context.update({"admin":True, "THEME_MEDIA_URL":admin_theme_url})