def index(request): page=request.GET.get('page',1) page = int(page) entrys = Entry.objects.get_posts() categories=Category.objects.all() comments=Comment.objects.in_public().exclude(email=Blog.get().email)[:8] return render_response(request,'wap/index.html',locals())
def GET(self): from util.feedgenerator import Atom1Feed blog = Blog.get() blog_home = web.ctx.home feed = Atom1Feed( title=blog.name, link=blog_home, description=blog.description, ) posts = Post.all().filter('hidden =', False).order('-date').fetch(10) for post in posts: if post.category: category = (post.category.name,) else: category = () if post.tags: category = category + tuple(post.tags) feed.add_item(title=post.title, link=blog_home + post.getUrl(), description=post.content, pubdate=post.date, categories=category ) web.header('Content-Type', 'application/atom+xml') return feed.writeString('utf-8')
def GET(self): """系统设置表单""" import pytz common_timezones = pytz.common_timezones blog = Blog.get() return render('admin/setting.html',blog=blog,timezones=common_timezones)
def POST(self): """保存模板装饰布局""" data = web.data() blog = Blog.get() blog.theme_widget = data blog.update() return json.dumps({'status': 'ok'})
def single(request,id=None): id=int(id) page=request.GET.get('page',1) page=int(page) entry=Entry.objects.get(id=id) comments=entry.comments.in_public().exclude(email=Blog.get().email) comments = paginator(comments,10,page) return render_response(request,'wap/single.html',{'entry':entry,'comments':comments})
def recentComments(request,page=1): page=request.GET.get('page',1) page = int(page) allcomment=Comment.objects.exclude(email=Blog.get().email).filter(is_public=True).order_by('-date') comments = paginator(allcomment,10,page) t = loadTempalte('recentcomments.html') html = t.render(Context({'comments': comments})) json = simplejson.dumps((True,html)) return HttpResponse(json)
def index(request): post_count=Entry.objects.all().filter(entrytype='post').count() comment_count=Comment.objects.in_public().count() spam_count=Comment.objects.in_moderation().count() page_count=Entry.objects.all().filter(entrytype='page').count() category_count=Category.objects.count() tag_count=Tag.objects.count() comments=Comment.objects.all().exclude(email=Blog.get().email).filter(is_public=True).order_by('-date')[:10] return render_response(request,"admin/index.html",locals())
def POST(self): inp = web.input() blog = Blog.get() blog.post_pagesize = int(inp.post_pagesize) blog.comment_pagesize = int(inp.comment_pagesize) blog.comment_sort = inp.comment_sort blog.ping_sites = inp.ping_sites blog.update() raise web.seeother('/admin/setting/habit')
def POST(self): """保存博客信息""" inp = web.input() blog = Blog.get() blog.name = inp.name blog.description = inp.description blog.timezone = inp.timezone blog.custom_header = inp.custom_header blog.update() raise web.seeother('/admin/setting')
def on_comment_was_submit(sender,comment,*args,**kwargs): blog=Blog.get() domain="http://%s"%(Site.objects.get_current().domain) if comment.parent_id != '0': old_c=comment.parent emailtitle=u'您在 '+blog.title+u' 上的评论有了新的回复' if old_c.mail_notify: sendmail('email/reply_comment.txt',{'old':old_c,"comment":comment, 'blog':blog,'domain':domain}, emailtitle,old_c.email) else: comments_notify=OptionSet.get('comments_notify',1) if int(comments_notify) == 1 and comment.is_public==True: emailtitle=u'文章'+comment.object.title+u'有了新的评论' sendmail('email/new_comment.txt',{'comment':comment,'domain':domain},emailtitle,blog.email)
def get_reader_wall(context,number=10): comments=cache.get_cache('sidebar:readerwall') if not comments: admin_email=Blog.get().email sql="select count(email) as count,author,email,weburl from comments_comment where is_public=1 and email !='%s' group by email order by count desc limit %d"%(admin_email,number) cursor = connection.cursor() cursor.execute(sql) rows=cursor.fetchall() comments=[] for row in rows: count=row[0] author=row[1] email=row[2] weburl=row[3] comment={'author':author,'weburl':weburl,'count':str(count),'email':email} comments.append(comment) cache.set_cache('sidebar:readerwall',comments,30) return {'comments':comments}
def __init__(self): self.blog = Blog.get()
def GET(self): blog = Blog.get() return render('admin/setting_habit.html',blog=blog)
def side(request): blog=Blog.get() site=Site.objects.get_current() return locals()
def blogger_getUsersBlogs(appkey, username, password): _checkUser(username,password) blog=Blog.get() url='http://%s'%(Site.objects.get_current().domain) return [{'url' : url, 'blogid' : '1','isAdmin':True, 'blogName' : blog.title,'xmlrpc':url+"/rpc"}]
def get_recent_comment(context,number=10): comments=Comment.objects.in_public().exclude(email=Blog.get().email) return {'comments':comments[:number]}
def GET(self): blog = Blog.get() return render('admin/setting_permalink.html', blog=blog)
def GET(self): import pytz common_timezones = pytz.common_timezones blog = Blog.get() return render('admin/install.html',blog=blog,timezones=common_timezones)
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')