def themeupload(self): theme_static = get_theme_folder('static') file = request.get_json()['file'] ext = os.path.splitext(file)[-1] if ext in ['.css', '.js']: upload_text_file(theme_static, file) else: upload_binary_file(theme_static, file) return 'Theme file uploaded'
def upload_template(template): root = get_theme_folder('templates/includes') abs_path = os.path.join(root, template) basename = os.path.basename(abs_path) with open(abs_path) as f: content = f.read() ctx = { 'entities': Entity.query.order_by('position').all(), 'main_menu': MenuItem.query.filter_by(parent=None).order_by('position').all() or Page.query.order_by('position').all(), '_theme': Setting.query.filter_by(name=u'theme').first().value } content = render_template_string(content, **ctx) content = re.sub(theme_pattern, models.convert_external, content) path = os.path.splitext(basename)[0] return upload_wiki_text(content, path, prefix='Template:')