示例#1
0
 def __init__(self, artical_id, name, email, website, content, comment_id=0, status=True, id=0):
     self.fields = {}
     self.id = int(id)
     self.fields.update(
         artical_id=int(artical_id),
         name=smart_str(name),
         email=smart_str(email),
         website=smart_str(website),
         content=smart_str(content),
         comment_id=int(comment_id),
         instime=datetime.datetime.now(),
         status=status,
     )
     if id != 0:
         self.fields.update(id=self.id)
示例#2
0
 def __init__(
     self, link_addr, link_name, friend_name, description="", insdate=datetime.datetime.today(), status=True, id=0
 ):
     self.fields = {}
     self.id = int(id)
     self.fields.update(
         link_addr=link_addr,
         link_name=smart_str(link_name),
         friend_name=smart_str(friend_name),
         description=smart_str(description),
         insdate=insdate,
         status=status,
     )
     if self.id != 0:
         self.fields.update(id=self.id)
示例#3
0
文件: views.py 项目: CJljfn/miniblog
    def GET(self, id=0):
        args = web.input(page='1')
        id = int(id)
        articals = None
        artical_handler = self.col_handler('artical')
        category_handler = self.col_handler('category')
        category = category_handler.find_one({'id':id})
        tip = "分类:%s" % smart_str(category['name'])
        per_page = 7
        if not args.page.isdigit() or id==1:
            return web.notfound()
        page = int(args.page) 
        conditions = {'status':True, 'id':{'$ne':1}}
        if id > 1:
            conditions.update(category_id=id)
        total = artical_handler.find(conditions).count()
        paginator = Paginator(total, page, per_page=per_page)
        articals = artical_handler.find(conditions).sort('uptime', \
pymongo.DESCENDING).limit(per_page).skip((page-1)*per_page)
        
        pre_articals, pre_links, pre_comments, pre_categories = get_left_objs()
        
        return self.render.index(pre_articals=pre_articals, 
                                 pre_links=pre_links,
                                 pre_comments=pre_comments,
                                 pre_categories=pre_categories,
                                 articals=articals,
                                 paginator=paginator, 
                                 tip=tip)
示例#4
0
 def __init__(self, title, tags, content, category_id, author, times=0, status=True, id=0):
     self.fields = {}
     self.id = int(id)
     self.fields.update(
         title=smart_str(title),
         tags=smart_str(tags),
         content=smart_str(content),
         category_id=int(category_id),
         author=smart_str(author),
         times=times,
         update=datetime.date.today().isoformat(),
         uptime=datetime.datetime.now(),
         instime=datetime.datetime.now(),
         insdate=datetime.date.today().isoformat(),
         status=status,
     )
     if self.id != 0:
         self.fields.update(id=self.id)
示例#5
0
文件: views.py 项目: CJljfn/miniblog
    def POST(self, id=1):
        pre_articals, pre_links, pre_comments, pre_categories = get_left_objs()
        id = int(id)
        comment_children = []
        
        artical_handler = get_col_handler('artical')
        artical = artical_handler.find_one({'id':id})
        comment_handler = get_col_handler('comment')
        comments = comment_handler.find({'artical_id':id})
        if comments.count():
            for comment in comments:
                children = get_comments_in_comment(comment['id'])
                comment_children.append([comment, children])        
        form = commentf()
        if not form.validates():
            return self.render.artical_detail(pre_articals=pre_articals,
                                              pre_links=pre_links, 
                                              pre_comments=pre_comments,
                                              pre_categories=pre_categories,
                                              artical=artical,
                                              form=form, 
                                              comments=comment_children)
        check = web.input().get('remember_me', 'false')
        artical_id = web.input().get('artical_id', 1)
        name = web.input().get('name', '')
        email = web.input().get('email', '')
        website = web.input().get('website', '')
        content = web.input().get('content', '')
        comment_id = web.input().get('comment_id', 0)
        
        params = dict(name=urllib.quote(smart_str(name)), email=email, website=website)
        cookie_value = pickle.dumps(params)
        if check == 'false':
            pass
        else:
            web.setcookie(COOKIE_NAME, cookie_value, expires=2592000)
        comment = Comment(artical_id,
                          name,
                          email,
                          website,
                          content,
                          comment_id)
        comment.save()
        # TODO:Package this part
        comment_obj = comment_handler.find_one({'id':int(comment_id)})
        if int(comment_id) != 0:
#            comment_obj = comment_handler.find_one({'id':int(comment_id)})
            send_email(comment_obj.get('email', ''), u'来自%s的回复' % name, \
u'%s\n详情请看:http://www.cj53.com/click/%s' % (content, artical_id))
        send_email('*****@*****.**', u'有留言', \
u'%s\n详情请看:http://www.cj53.com/click/%s' % (content, artical_id))        
        if id == 1:
            raise web.seeother("/board")
        return web.seeother("/artical/%s" % id)
示例#6
0
文件: views.py 项目: CJljfn/miniblog
    def GET(self):
        tag = web.input(tag='').get('tag', '')
        tag = smart_str(urllib.unquote(tag))
        artical_handler = self.col_handler('artical')
        tip = "标签:%s" % tag
        if not tag:
            return web.notfound()
        articals = artical_handler.find({'tags':{'$regex':tag}, 'status':True})\
.sort('uptime', pymongo.DESCENDING)
        pre_articals, pre_links, pre_comments, pre_categories = get_left_objs()
        return self.render.index_tags(pre_articals=pre_articals, 
                                 pre_links=pre_links,
                                 pre_comments=pre_comments,
                                 pre_categories=pre_categories,
                                 articals=articals,
                                 tip=tip)        
示例#7
0
 def __init__(self, name, id=0):
     self.name = smart_str(name)
     self.id = int(id)
     self.fields = {"name": self.name}
     if self.id != 0:
         self.fields.update(id=self.id)
示例#8
0
def url_quote(value):
    return smart_unicode(urllib.quote(smart_str(value)))
示例#9
0
def windows_mode(content):
    content = smart_str(content, "gbk")
    return content.replace("\n", "\r\n")
示例#10
0
def url_quote(value):
    return smart_unicode(urllib.quote(smart_str(value)))
示例#11
0
 def delete(self, key):
     self._cache.delete(smart_str(key))
示例#12
0
 def incr(self, key, delta=1):
     self._cache.incr(smart_str(key), delta)
示例#13
0
 def set(self, key, value, timeout=0):
     self._cache.set(smart_str(key), value, self._get_memcache_timeout(timeout))
示例#14
0
 def get(self, key, default=None):
     val = self._cache.get(smart_str(key))
     if val is None:
         return default
     return val