示例#1
0
 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')
示例#2
0
 def GET(self, name):
     theme = Theme.get_by_key_name(name)
     theme_files = ThemeFile.all().filter('theme_name =', name)
     for theme_file in theme_files:
         theme_file.delete()
     theme.delete()
     
     raise web.seeother('/admin/theme')
def list(request):

    context = {}
    user = request.user

    title = request.GET.get('title', '')
    theme = Theme.objects.filter(user=user.id)
    if title:
        theme = Theme.filter(title__contains=title)

    context['theme'] = theme
    return render(request, 'manager/lists.html', context)
示例#4
0
 def GET(self):
     widgets = Widget.all()
     theme = blog.theme
     
     processor = Processor()
     theme = Theme.get_by_key_name(theme)
     sidebar_num = theme.sidebar
     
     # return theme_widget.get('1')
     return render('admin/widget.html',
                   widgets=widgets,
                   sidebar_num=sidebar_num,
                   processor=processor
                  )
示例#5
0
 def GET(self, name):
     import binascii
     
     theme = Theme.get_by_key_name(name)
     screenshot = str(theme.screenshot)
     
     etag = str(binascii.crc32(screenshot))
     
     match = web.ctx.env.get('HTTP_IF_NONE_MATCH')
     if match and match == etag:
         raise web.notmodified()
     
     web.header('ETag', etag)
     web.header('Content-Type', 'image/png')
     return screenshot
def addtheme(request):

    context = {}
    now = datetime.datetime.now()
    user = request.user
    if request.method == 'POST':
        form = ThemeForm(request.POST)
        if form.is_valid():
            formData = form.cleaned_data
            title = formData.get('title')
            desc = formData.get('desc')
            content = formData.get('content')
            now = datetime.datetime.now()
            th = Theme()
            th.title = title
            th.desc = desc
            th.content = content
            th.add_date = now
            th.user = user.id
            th.save()
            return HttpResponseRedirect('/success/')
    else:
        context['form'] = ThemeForm()
    return render(request, 'manager/manage.html', context)
示例#7
0
 def GET(self):
     use_theme = blog.theme
     themes = Theme.all()
     
     return render('admin/theme.html',themes=themes,use_theme=use_theme)
示例#8
0
 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')