def get_template_sources(self, template_name, template_dirs=None): """Return the absolute paths to "template_name", when appended to the selected theme directory in THEMES_DIR. Any paths that don't lie inside one of the template dirs are excluded from the result set, for security reasons. """ theme_templates = [] current_request = get_current_request() if current_request and current_request.mobile: theme_templates.append(os.path.join(get_theme_root(), 'mobile')) theme_templates.append(os.path.join(get_theme_root(), 'templates')) for template_path in theme_templates: try: if settings.USE_S3_THEME: yield os.path.join(template_path, template_name) else: yield safe_join(template_path, template_name) except UnicodeDecodeError: # The template dir name was a bytestring that wasn't valid UTF-8. raise except ValueError: # The joined path was located outside of this particular # template_dir (it might be inside another one, so this isn't # fatal). pass
def __init__(self, theme): self.orig_name = theme self.name = theme self.description = u'' self.tags = u'' self.screenshot = u'' self.screenshot_thumbnail = u'' self.author = u'' self.author_uri = u'' self.version = u'' self.create_dt = datetime.now() theme_root = get_theme_root(theme) # check if theme info file exists is_file = qstr_is_file(DEFAULT_THEME_INFO, ROOT_DIR=theme_root) if is_file: theme_file = file(os.path.join(theme_root, DEFAULT_THEME_INFO)) data = theme_file.readlines() theme_file.close() # set attributes according to data in info file for datum in data: datum = datum.replace('\n', '') label, value = datum.split('=') label = label.strip().replace(' ', '_').lower() value = value.strip() if label == 'create_dt': value = parse(value) if label in ('screenshot', 'screenshot_thumbnail'): value = os.path.join('/themes', theme, value) setattr(self, label, value)
def __init__(self, theme): self.orig_name = theme self.name = theme self.description = u'' self.tags = u'' self.screenshot = u'' self.screenshot_thumbnail = u'' self.author = u'' self.author_uri = u'' self.version = u'' self.create_dt = datetime.now() theme_root = get_theme_root(theme) # check if theme info file exists is_file = qstr_is_file(DEFAULT_THEME_INFO, ROOT_DIR=theme_root) if is_file: theme_file = file(os.path.join(theme_root, DEFAULT_THEME_INFO)) data = theme_file.readlines() theme_file.close() # set attributes according to data in info file for datum in data: datum = datum.replace('\n', '') if "=" in datum: label, value = datum.split('=', 1) label = label.strip().replace(' ', '_').lower() value = value.strip() if label == 'create_dt': value = parse(value) if label in ('screenshot', 'screenshot_thumbnail'): value = os.path.join('/themes', theme, value) setattr(self, label, value)
def get_template_sources(self, template_name, template_dirs=None): """Return the absolute paths to "template_name", when appended to the selected theme directory in THEMES_DIR. Any paths that don't lie inside one of the template dirs are excluded from the result set, for security reasons. """ theme_templates = [] current_request = get_current_request() if not settings.DEBUG: # this is needed when the theme is changed self.theme_root = get_theme_root() if current_request and current_request.mobile: theme_templates.append(os.path.join(self.theme_root, 'mobile')) theme_templates.append(os.path.join(self.theme_root, 'templates')) for template_path in theme_templates: try: if settings.USE_S3_THEME: yield os.path.join(template_path, template_name) else: yield safe_join(template_path, template_name) except UnicodeDecodeError: # The template dir name was a bytestring that wasn't valid UTF-8. raise except ValueError: # The joined path was located outside of this particular # template_dir (it might be inside another one, so this isn't # fatal). pass
def __init__(self, theme): self.orig_name = theme self.name = theme self.description = '' self.tags = '' self.screenshot = '' self.author = '' self.author_uri = '' self.version = '' theme_root = get_theme_root(theme) # check if theme info file exists is_file = qstr_is_file(DEFAULT_THEME_INFO, ROOT_DIR=theme_root) if is_file: theme_file = file(os.path.join(theme_root, DEFAULT_THEME_INFO)) data = theme_file.readlines() theme_file.close() # set attributes according to data in info file for datum in data: datum = datum.replace('\n', '') label, value = datum.split('=') label = label.strip().replace(' ', '_').lower() value = value.strip() if label == 'screenshot': value = '/themes/' + theme + '/' + value self.__setattr__(label, value)
def __init__(self, *args, **kwargs): """ Hold the theme_root in self.theme_root instead of calling get_theme_root() in get_template_sources(). This significantly reduces the number of queries for get_setting('module', 'theme_editor', 'theme'). (reduced # of queries from 3316 to 233 when testing on my local for an article view. - @jennyq) """ self.theme_root = get_theme_root() super(Loader, self).__init__(*args, **kwargs)
def render_to_theme(template_name, dictionary={}, context_instance=Context): """Loads the given template_name and renders it with the given dictionary as context. The template_name may be a string to load a single template using get_template, or it may be a tuple to use select_template to find one of the templates in the list. Returns a string. This shorcut prepends the template_name given with the selected theme's directory """ context_instance.update(dictionary) toggle = 'TOGGLE_TEMPLATE' in context_instance theme = context_instance['THEME'] theme_template = get_theme_template(template_name, theme=theme) context_instance["THEME_TEMPLATE"] = template_name context_instance["CUSTOM_TEMPLATE"] = False if toggle: t = get_default_template(template_name) else: if isinstance(template_name, (list, tuple)): try: t = select_template(theme_template) except TemplateDoesNotExist: t = get_default_template(template_name) context_instance["CUSTOM_TEMPLATE"] = False else: try: t, origin = get_template(theme_template) if origin and re.search("^%s.+" % get_theme_root(), origin.name): context_instance["CUSTOM_TEMPLATE"] = True if 'homepage.html' in template_name: context_instance["CUSTOM_TEMPLATE"] = False except TemplateDoesNotExist: t = get_default_template(template_name) context_instance["CUSTOM_TEMPLATE"] = False return strip_content_above_doctype(t.render(context_instance))
import codecs import urllib # django from django import forms from django.core.files import File from django.conf import settings from django.utils.translation import ugettext_lazy as _ from django.core.cache import cache # local from tendenci.core.theme.utils import get_theme_root, get_theme, theme_choices from tendenci.apps.theme_editor.utils import archive_file from tendenci.libs.boto_s3.utils import save_file_to_s3 THEME_ROOT = get_theme_root() FILE_EXTENTIONS = (".html", ".js", ".css", ".less", ".jpg", ".jpeg", ".png", ".ico", ".gif", ".txt", ".xml", ".kml") class FileForm(forms.Form): content = forms.CharField(label="Content", widget=forms.Textarea(attrs={"rows": 26, "cols": 73}), max_length=500000) rf_path = forms.CharField(widget=forms.HiddenInput()) def save(self, request, file_relative_path, ROOT_DIR=THEME_ROOT, ORIG_ROOT_DIR=THEME_ROOT): content = self.cleaned_data["content"] file_path = (os.path.join(ROOT_DIR, file_relative_path)).replace("\\", "/") if settings.USE_S3_THEME: file_path = (os.path.join(ORIG_ROOT_DIR, file_relative_path)).replace("\\", "/") # write the theme file locally in case it was wiped by a restart
import codecs import urllib # django from django import forms from django.core.files import File from django.conf import settings from django.utils.translation import ugettext_lazy as _ from django.core.cache import cache # local from tendenci.core.theme.utils import get_theme_root, get_theme, theme_choices from tendenci.apps.theme_editor.utils import archive_file from tendenci.libs.boto_s3.utils import save_file_to_s3 THEME_ROOT = get_theme_root() FILE_EXTENTIONS = ( '.html', '.js', '.css', '.less', '.jpg', '.jpeg', '.png', '.ico', '.gif', '.txt', '.xml', '.kml', )