예제 #1
0
 def GET(self, page = 1):
     curpage = int(page)
     totalpost =  model.Posts.count()
     pagestr = page_navigation('', curpage, Setting.config['listnum'], totalpost)
     posts = model.Posts.get_all(None, Setting.config['listnum'], curpage)
     R.common_data()
     return R.render('index', posts = posts, pagestr = pagestr)
예제 #2
0
 def POST(self, page = 1):
     spost = web.input(s = '')
     skey = spost.s
     skey = skey.encode("utf-8")
     pagestr = ''
     posts = model.execSql("select * from " + tablename("Posts") + " where post_title like '%" + skey + "%'")
     R.common_data()
     return R.render('index', posts = posts, pagestr = pagestr)
예제 #3
0
 def GET(self, kname = "", page = 1):
     if kname:
         tagname = check_str(kname)
         curpage = int(page)
         totalpost =  model.Posts.count('tag', tagname)
         pagestr = page_navigation('/tag/' + kname, curpage, Setting.config['listnum'], totalpost)
         posts = model.Posts.get_by_tagname(tagname, Setting.config['listnum'], curpage)
         R.common_data()
         return R.render('index', posts = posts, pagestr = pagestr)
예제 #4
0
 def GET(self, kname = "", page = 1):
     if kname:
         category_shortname = check_str(kname)
         category = model.Category.get_by_short(category_shortname)
         if category.category_id:
             curpage = int(page)
             totalpost =  model.Posts.count('category', category.category_id)
             pagestr = page_navigation('/category/' + kname, curpage, Setting.config['listnum'], totalpost)
             posts = model.Posts.get_all(category.category_id, Setting.config['listnum'], curpage)
             R.common_data()
             return R.render('index', posts = posts, pagestr = pagestr)
         raise web.seeother('/')
예제 #5
0
 def GET(self, kname="", page=1):
     if kname:
         category_shortname = check_str(kname)
         category = model.Category.get_by_short(category_shortname)
         if category.category_id:
             curpage = int(page)
             totalpost = model.Posts.count('category', category.category_id)
             pagestr = page_navigation('/category/' + kname, curpage,
                                       Setting.config['listnum'], totalpost)
             posts = model.Posts.get_all(category.category_id,
                                         Setting.config['listnum'], curpage)
             R.common_data()
             return R.render('index', posts=posts, pagestr=pagestr)
         raise web.seeother('/')
예제 #6
0
 def POST(self):
     ninfo = web.input(newname = '', oldpwd = '', newpwd = '', repwd = '')
     if ninfo.oldpwd:
         userinfo = model.Kvdata.get(web.ctx.session.user)
         if userinfo:
             if userinfo['passwd'] == hash_md5(ninfo.oldpwd):
                 if ninfo.newname:
                     model.Kvdata.modify(web.ctx.session.user, ninfo.newname)
                     web.ctx.session.user = ninfo.newname
                     return R.render('user', user=web.ctx.session.user, msg = "用户名修改成功")
                 if ninfo.newpwd and ninfo.newpwd == ninfo.repwd:
                     model.Kvdata.set(web.ctx.session.user, {'passwd': hash_md5(ninfo.newpwd)})
                     return R.render('user', user=web.ctx.session.user, msg = "密码修改成功")
     raise web.seeother('/manage/user')
예제 #7
0
 def POST(self, pid=0):
     post = web.input(ptitle='',
                      ptstitle='',
                      pcategory=0,
                      pcontent='',
                      ptype=0,
                      ptags='',
                      pstatus=1,
                      pontop=0,
                      pcomment=1)
     tags = post['ptags']
     if tags:
         tags = tags.replace(" ", "")
         taglist = list(set(tags.split(",")))
         post['ptags'] = ','.join(taglist)
     if pid:
         model.Posts.modify(pid, post)
         model.Relations.remove(pid)
     else:
         pid = model.Posts.creat(post)
     if tags:
         otags = dict([[t.tag_name, t.tag_id]
                       for t in model.Tags.get_all()])
         for tag in taglist:
             if tag not in otags.keys() and len(tag) > 1:
                 tid = model.Tags.creat(tag)
                 model.Relations.creat(tid, pid)
             else:
                 model.Relations.creat(otags[tag], pid)
     return R.result('success', '/manage/postlist', '文章保存成功')
예제 #8
0
 def GET(self, frame):
     frames = ['index', 'top', 'menu']
     if frame in frames:
         return web.template.frender('template/manage/' + frame + '.html')()
     if frame == 'main':
         totalpost =  model.Posts.count()
         return R.render('main', totalpost = totalpost)
예제 #9
0
 def GET(self):
     home = os.getcwd()
     uploadDir = os.path.join(home, "static/uploads")
     if os.path.isdir(uploadDir):
         import time
         filedata = []
         for ifile in os.listdir(uploadDir):
             ifilepath = os.path.join(uploadDir, ifile)
             filetime = time.strftime(
                 '%Y-%m-%d %H:%M:%S',
                 time.localtime(os.stat(ifilepath).st_ctime))
             if os.path.isdir(ifilepath):
                 filedata.append({
                     'ftype': 'D',
                     'fname': ifile,
                     'fedittime': filetime
                 })
             else:
                 filedata.append({
                     'ftype': 'f',
                     'fname': ifile,
                     'fedittime': filetime
                 })
         print filedata
     return R.render('attachment', filedata=filedata)
예제 #10
0
 def GET(self, frame):
     frames = ['index', 'top', 'menu']
     if frame in frames:
         return web.template.frender('template/manage/' + frame + '.html')()
     if frame == 'main':
         totalpost = model.Posts.count()
         return R.render('main', totalpost=totalpost)
예제 #11
0
 def GET(self, kname):
     pname = check_str(kname)
     if is_int(pname):
         post = model.Posts.get_by_id(pname)
     else:
         post = model.Posts.get_by_title(pname)
     if post.post_id:
         model.Posts.viewcount(post.post_id)
         related_posts = model.Posts.get_related(post.post_category)
         related_comments = model.Comments.get_all(post.post_id)
         post_prev = model.Posts.get_next(post.post_id, 'down')
         post_next = model.Posts.get_next(post.post_id)
         R.common_data()
         R.addtplfunc('Md5', hash_md5)
         return R.render('post', post=post, related_posts=related_posts,
                         related_comments=related_comments,
                         post_prev=post_prev, post_next=post_next)
     raise web.seeother('/')
예제 #12
0
 def GET(self, pid = 0):
     if pid:
         epost = model.Posts.get_by_id(pid)
     else:
         epost = model.Posts.model()
         epost.post_title = "在这里键入标题"
     tags = model.Tags.get_all()
     categorys = model.Category.get_all()
     return R.render('post', epost=epost, categorys=categorys, tags=tags)
예제 #13
0
 def GET(self, pid=0):
     if pid:
         epost = model.Posts.get_by_id(pid)
     else:
         epost = model.Posts.model()
         epost.post_title = "在这里键入标题"
     tags = model.Tags.get_all()
     categorys = model.Category.get_all()
     return R.render('post', epost=epost, categorys=categorys, tags=tags)
예제 #14
0
 def POST(self):
     nsetting = web.input(webtitle='Garfielt Blog',
                          websubtitle='Welcome to Mysite!',
                          webdes='The Garfielt Blog',
                          webkeys='Garfielt, Blog, Python, web.py',
                          webcdn='',
                          timeadjust=0,
                          listnum=10)
     model.Kvdata.set('setting', nsetting)
     Setting.config = model.Kvdata.get("setting")
     return R.result('success', '/manage/setting', '设置修改成功')
예제 #15
0
 def POST(self):
     nsetting = web.input(webtitle = 'Garfielt Blog',
                          websubtitle = 'Welcome to Mysite!',
                          webdes = 'The Garfielt Blog',
                          webkeys = 'Garfielt, Blog, Python, web.py',
                          webcdn = '',
                          timeadjust = 0,
                          listnum = 10)
     model.Kvdata.set('setting', nsetting)
     Setting.config = model.Kvdata.get("setting")
     return R.result('success', '/manage/setting', '设置修改成功')
예제 #16
0
 def POST(self):
     ninfo = web.input(newname='', oldpwd='', newpwd='', repwd='')
     if ninfo.oldpwd:
         userinfo = model.Kvdata.get(web.ctx.session.user)
         if userinfo:
             if userinfo['passwd'] == hash_md5(ninfo.oldpwd):
                 if ninfo.newname:
                     model.Kvdata.modify(web.ctx.session.user,
                                         ninfo.newname)
                     web.ctx.session.user = ninfo.newname
                     return R.render('user',
                                     user=web.ctx.session.user,
                                     msg="用户名修改成功")
                 if ninfo.newpwd and ninfo.newpwd == ninfo.repwd:
                     model.Kvdata.set(web.ctx.session.user,
                                      {'passwd': hash_md5(ninfo.newpwd)})
                     return R.render('user',
                                     user=web.ctx.session.user,
                                     msg="密码修改成功")
     raise web.seeother('/manage/user')
예제 #17
0
 def GET(self):
     esetting = dict_to_object(model.Kvdata.get("setting"))
     home = os.getcwd()
     templateDir = os.path.join(home, "template")
     if os.path.isdir(templateDir):
         themes = []
         for ifile in os.listdir(templateDir):
             if ifile != 'manage':
                 ifilepath = os.path.join(templateDir, ifile)
                 if os.path.isdir(ifilepath):
                     themes.append(ifile)
     return R.render('setting', esetting=esetting, themes=themes)
예제 #18
0
 def GET(self, kname):
     pname = check_str(kname)
     if is_int(pname):
         post = model.Posts.get_by_id(pname)
     else:
         post = model.Posts.get_by_title(pname)
     if post.post_id:
         model.Posts.viewcount(post.post_id)
         related_posts = model.Posts.get_related(post.post_category)
         related_comments = model.Comments.get_all(post.post_id)
         post_prev = model.Posts.get_next(post.post_id, 'down')
         post_next = model.Posts.get_next(post.post_id)
         R.common_data()
         R.addtplfunc('Md5', hash_md5)
         return R.render('post',
                         post=post,
                         related_posts=related_posts,
                         related_comments=related_comments,
                         post_prev=post_prev,
                         post_next=post_next)
     raise web.seeother('/')
예제 #19
0
 def GET(self):
     esetting = dict_to_object(model.Kvdata.get("setting"))
     home = os.getcwd()
     templateDir = os.path.join(home, "template")
     if os.path.isdir(templateDir):
         themes = []
         for ifile in os.listdir(templateDir):
             if ifile != 'manage':
                 ifilepath = os.path.join(templateDir, ifile)
                 if os.path.isdir(ifilepath):
                     themes.append(ifile)
     return R.render('setting', esetting=esetting, themes=themes)
예제 #20
0
 def GET(self, action ='view', page = 1):
     if action == 'delete':
         model.Posts.delete(pid)
     cats = model.Category.get_all()
     curpage = int(page)
     totalpost =  model.Posts.count()
     pagestr = page_navigation('/manage/post', curpage, 15, totalpost)
     categorys = {}
     for c in cats:
         categorys[c.category_id] = c.category_name
     posts = model.Posts.get_all(None, 15, curpage)
     return R.render('postlist', posts=posts, categorys=categorys,
                     totalpost=totalpost, pagestr=pagestr)
예제 #21
0
 def GET(self):
     home = os.getcwd()
     uploadDir = os.path.join(home, "static/uploads")
     if os.path.isdir(uploadDir):
         import time
         filedata = []
         for ifile in os.listdir(uploadDir):
             ifilepath = os.path.join(uploadDir, ifile)
             filetime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(os.stat(ifilepath).st_ctime))
             if os.path.isdir(ifilepath):
                 filedata.append({'ftype':'D', 'fname':ifile, 'fedittime':filetime})
             else:
                 filedata.append({'ftype':'f', 'fname':ifile, 'fedittime':filetime})
         print filedata
     return R.render('attachment', filedata = filedata)
예제 #22
0
 def GET(self, action='view', page=1):
     if action == 'delete':
         #            model.Posts.delete(pid)
         model.Posts.remove(page)
     cats = model.Category.get_all()
     curpage = int(page)
     totalpost = model.Posts.count()
     pagestr = page_navigation('/manage/post', curpage, 15, totalpost)
     categorys = {}
     for c in cats:
         categorys[c.category_id] = c.category_name
     posts = model.Posts.get_all(None, 15, curpage)
     return R.render('postlist',
                     posts=posts,
                     categorys=categorys,
                     totalpost=totalpost,
                     pagestr=pagestr)
예제 #23
0
 def POST(self, pid = 0):
     post = web.input(ptitle = '', ptstitle = '', pcategory = 0,
                      pcontent = '', ptype = 0, ptags = '', pstatus = 1,
                      pontop = 0, pcomment = 1)
     tags = post['ptags']
     if tags:
         tags = tags.replace(" ", "")
         taglist = list(set(tags.split(",")))
         post['ptags'] = ','.join(taglist)
     if pid:
         model.Posts.modify(pid, post)
         model.Relations.remove(pid)
     else:
         pid = model.Posts.creat(post)
     if tags:
         otags = dict([[t.tag_name, t.tag_id] for t in model.Tags.get_all()])
         for tag in taglist:
             if tag not in otags.keys() and len(tag)>1:
                 tid = model.Tags.creat(tag)
                 model.Relations.creat(tid, pid)
             else:
                 model.Relations.creat(otags[tag], pid)
     return R.result('success', '/manage/postlist', '文章保存成功')
예제 #24
0
 def GET(self, action='view', cid=0):
     if action == 'delete':
         model.Comments.remove(cid)
     comments = model.Comments.get_all()
     return R.render('comment', comments=comments)
예제 #25
0
 def GET(self):
     return R.render('user', user=web.ctx.session.user, msg='')
예제 #26
0
 def GET(self, action='view', lid=0):
     if action == 'delete':
         model.Links.remove(lid)
     elink = model.Links.get_by_id(lid)
     links = model.Links.get_all()
     return R.render('links', elink=elink, links=links)
예제 #27
0
 def GET(self):
     return R.render('login')
예제 #28
0
 def GET(self):
     return R.render('user', user=web.ctx.session.user, msg='')
예제 #29
0
 def GET(self, tid = 0):
     tags = model.Tags.get_all()
     etag = model.Tags.get_by_id(tid)
     return R.render('tags', etag=etag, tags=tags)
예제 #30
0
 def GET(self):
     return R.render('login')
예제 #31
0
 def GET(self, action = 'view', cid = 0):
     if action == 'delete':
         model.Comments.remove(cid)
     comments = model.Comments.get_all()
     return R.render('comment', comments=comments)
예제 #32
0
 def GET(self, action = ''):
     return R.render('data')
예제 #33
0
 def GET(self, action=''):
     return R.render('data')
예제 #34
0
 def GET(self, action = 'view', lid = 0):
     if action == 'delete':
         model.Links.remove(lid)
     elink = model.Links.get_by_id(lid)
     links = model.Links.get_all()
     return R.render('links', elink=elink, links=links)
예제 #35
0
 def GET(self, tid=0):
     tags = model.Tags.get_all()
     etag = model.Tags.get_by_id(tid)
     return R.render('tags', etag=etag, tags=tags)
예제 #36
0
 def GET(self, action = 'view', cid = 0):
     ecategory = model.Category.get_by_id(cid)
     if action == 'delete':
         model.Category.delete(cid)
     categorys = model.Category.get_all()
     return R.render('category', ecategory = ecategory, categorys = categorys)
예제 #37
0
 def GET(self, action='view', cid=0):
     ecategory = model.Category.get_by_id(cid)
     if action == 'delete':
         model.Category.delete(cid)
     categorys = model.Category.get_all()
     return R.render('category', ecategory=ecategory, categorys=categorys)