def POST(self): import zipfile import datetime inp = web.input(theme={}) theme_zip = inp.theme fileinfo = zipfile.ZipFile(theme_zip.file) config = yaml.load(fileinfo.read('config.yaml')) theme_name = config.get("name") theme = Theme.get_by_key_name(theme_name) if not theme: theme = Theme(key_name=theme_name) theme.name = config.get("name") theme.author = config.get("author") theme.homepage = config.get("homepage") theme.description = config.get("description") theme.sidebar = config.get("sidebar") screenshot = fileinfo.read('screenshot.png') theme.screenshot = screenshot theme.save() for i in fileinfo.infolist(): filename = i.filename if filename.endswith('/') or \ filename in ['config.yaml', 'screenshot.png']: continue file_size = i.file_size date_time = i.date_time date_time = datetime.datetime(*date_time) theme_file = ThemeFile.all().filter('theme_name =', theme_name).\ filter('filename =', filename).get() if not theme_file: theme_file = ThemeFile() theme_file.theme_name = theme_name theme_file.filename = filename theme_file.filecontent = fileinfo.read(filename) if filename.endswith('.html'): filetype = 'template' else: filetype = 'file' theme_file.filetype = filetype theme_file.modified = date_time theme_file.save() raise web.seeother('/admin/theme')
def POST(self): import os, datetime, yaml from blog import widgets as blog_widgets from blog.models import Widget from theme.models import Theme, ThemeFile from settings import VERSION, THEME_TEMPLATE_DIR widgets = Widget.all() for widget in widgets: widget.delete() widget_modules = blog_widgets.default_widgets for widget_name in widget_modules: widget = Widget(key_name=widget_name) widget.name = widget_name widget.package = 'blog.widgets.%s' % widget_name widget.save() inp = web.input() blog = Blog.get() blog.name = inp.name blog.description = inp.description blog.timezone = inp.timezone blog.theme_widget = '{"1":[{"name":"categories"},{"name":"hot_tags"},{"name":"recent_entries"},{"name":"recent_comments"},{"name":"links"}]}' blog.version = VERSION blog.update() default_theme = os.path.join(THEME_TEMPLATE_DIR, 'default') config = open(os.path.join(default_theme, 'config.yaml')).read() config = yaml.load(config) theme_name = config.get("name") theme = Theme.get_by_key_name(theme_name) if not theme: theme = Theme(key_name=theme_name) theme.name = config.get("name") theme.author = config.get("author") theme.homepage = config.get("homepage") theme.description = config.get("description") theme.sidebar = config.get("sidebar") screenshot = open(os.path.join(default_theme, 'screenshot.png')).read() theme.screenshot = screenshot theme.save() for root, dirs, files in os.walk(default_theme, True): path = root.replace(default_theme, '') if path.startswith('/'): path = path[1:] for filename in files: f = os.path.join(path, filename) if filename in ['config.yaml', 'screenshot.png']: continue theme_file = ThemeFile.all().filter('theme_name =', theme_name).\ filter('filename =', f).get() if not theme_file: theme_file = ThemeFile() theme_file.theme_name = theme_name theme_file.filename = f theme_file.filecontent = open(os.path.join(default_theme, f)).read() if f.endswith('.html'): filetype = 'template' else: filetype = 'file' theme_file.filetype = filetype theme_file.modified = datetime.datetime.now() theme_file.save() raise web.seeother('/admin')