Esempio n. 1
0
 def blogs_from_tag(self, tagname, vfrom=0, vlim=20):
     from article.blog import Blog
     if not tagname:
         return [], 0
     if tagname == 'default':
         toview = self.blogids
     else:
         tag_blogs = self.lib.tag_lib.sub_list(tagname)
         toview = tag_blogs.load_all()
         if toview is None:
             toview = []
         toview = sorted(toview, key=itemgetter(1), reverse=True)
     len_toview = len(toview)
     if vfrom >= len_toview:
         return [], len_toview
     if vfrom + vlim > len_toview:
         vlim = len_toview - vfrom
     if tagname == 'default':
         toview = Blog.by_ids(toview, auto_cache=False)
     else:
         toview = [tuple(each) for each in toview[vfrom:(vfrom + vlim)]]
         tmp = set(toview)
         toview = Blog.by_ids([each[0] for each in toview],
                              auto_cache=False)
         toview.sort()
         tmp2 = set((each._id, each.release_time) for each in toview)
         tag_blogs.pull(*tuple(tmp - tmp2))  #try remove blog not existed
     for each in toview:
         each.set_cache('author', self)
         each.set_cache('env', self)
     return toview, len(toview)
Esempio n. 2
0
 def blogs_from_tag(self, tagname, vfrom=0, vlim=20):
     from article.blog import Blog
     if not tagname:
         return [], 0
     if tagname == 'default':
         toview = self.blogids
     else:
         tag_blogs = self.lib.tag_lib.sub_list(tagname)
         toview = tag_blogs.load_all()
         if toview is None:
             toview = []
         toview = sorted(toview, key=itemgetter(1), reverse=True)
     len_toview = len(toview)
     if vfrom >= len_toview:
         return [], len_toview
     if vfrom + vlim > len_toview:
         vlim = len_toview - vfrom
     if tagname == 'default':
         toview = Blog.by_ids(toview, auto_cache=False)
     else:
         toview = [tuple(each) for each in toview[vfrom:(vfrom+vlim)]]
         tmp = set(toview)
         toview = Blog.by_ids([each[0] for each in toview], auto_cache=False)
         toview.sort()
         tmp2 = set((each._id, each.release_time) for each in toview)
         tag_blogs.pull(*tuple(tmp - tmp2)) #try remove blog not existed
     for each in toview:
         each.set_cache('author', self)
         each.set_cache('env', self)
     return toview, len(toview)
Esempio n. 3
0
 def get(self):
     handler_page = RSSRecentBlogPage(self)
     blogs = sorted(Blog.by_ids(recent_blogs.get_slice(-10)))
     handler_page['items'] = [each.rss_info for each in blogs]
     handler_page.init_page()
     handler_page.render()
     return  #0
Esempio n. 4
0
 def own_data(self):
     ans = list()
     ans += [each for each in list_generator( [(ek, ev[0]) 
                 for ek, ev in self.drafts_lib.items()]) 
             if each is not None]
     ans += Blog.by_ids(self.blog_list.load_all())
     return ans
Esempio n. 5
0
    def get(self):
        from global_info import recent_blogs
        from article.blog import Blog

        page = RegisterPage(self)
        page["blog_list"] = [each.obj_info_view_by() for each in Blog.by_ids(recent_blogs.get_slice(-20))]
        return page.render()
Esempio n. 6
0
 def get(self):
     from global_info import recent_blogs
     from article.blog import Blog
     page = RegisterPage(self)
     page['blog_list'] = [each.obj_info_view_by() 
                 for each in Blog.by_ids(recent_blogs.get_slice(-20))]
     return page.render()
Esempio n. 7
0
 def get(self):
     handler_page = RSSRecentBlogPage(self)
     blogs = sorted(Blog.by_ids(recent_blogs.get_slice(-10)))
     handler_page['items'] = [each.rss_info for each in blogs]
     handler_page.init_page()
     handler_page.render()
     return #0
Esempio n. 8
0
 def get(self):
     handler_page = AtomRecentBlogPage(self)
     blogs = sorted(Blog.by_ids(recent_blogs.get_slice(-10)))
     atominfos = [each.atom_info for each in blogs]
     handler_page.add_entries(*atominfos)
     handler_page.init_page()
     handler_page.render()
     return  #0
Esempio n. 9
0
 def get(self):
     handler_page = AtomRecentBlogPage(self)
     blogs = sorted(Blog.by_ids(recent_blogs.get_slice(-10)))
     atominfos = [each.atom_info for each in blogs]
     handler_page.add_entries(*atominfos)
     handler_page.init_page()
     handler_page.render()
     return #0
Esempio n. 10
0
 def own_data(self):
     ans = list()
     ans += [
         each
         for each in list_generator([(ek, ev[0])
                                     for ek, ev in self.drafts_lib.items()])
         if each is not None
     ]
     ans += Blog.by_ids(self.blog_list.load_all())
     return ans
Esempio n. 11
0
 def get(self):
     handler_page = AFFeedPage(self)
     usr = self.current_user
     try:
         blogs = sorted(Blog.by_ids(recent_blogs.get_slice(-10)))
     except:
         blogs = []
     handler_page["id_list"] = [str(each) + "##blog" for each in (recent_blogs.load_all()[100:-10][::-1]) if each]
     handler_page["feed_list"] = [each.obj_info_view_by("basic_info", usr=usr, env=None) for each in blogs]
     handler_page.render()
     return  # 0
Esempio n. 12
0
 def get(self):
     handler_page = AFFeedPage(self)
     usr = self.current_user
     try:
         blogs = sorted(Blog.by_ids(recent_blogs.get_slice(-10)))
     except:
         blogs = []
     handler_page['id_list'] = [
         str(each) + '##blog'
         for each in (recent_blogs.load_all()[100:-10][::-1]) if each
     ]
     handler_page['feed_list'] = [
         each.obj_info_view_by('basic_info', usr=usr, env=None)
         for each in blogs
     ]
     handler_page.render()
     return  #0
Esempio n. 13
0
 def blogs_info_view_by(self, usr=None, tagname=None, vfrom=0, vlim=20):
     from article.blog import Blog
     if tagname and tagname != 'default':
         toview, len_toview = self.blogs_from_tag(tagname, vfrom, vlim)
     else:
         toview = self.blogids
         len_toview = len(toview)
         if vfrom > len_toview:
             return [], len_toview
         if vfrom + vlim > len_toview:
             vlim = len_toview - vfrom
         toview = toview[vfrom:(vfrom+vlim)]
         tmp = set(toview)
         toview = Blog.by_ids(toview)
         toview.sort()
         tmp2 = set(each._id for each in toview)
         self.lib.blog_list.pull(*tuple(tmp - tmp2)) 
         #try remove item not exist
     return [each.obj_info_view_by('basic_info', usr, env=usr) 
                     for each in toview], len_toview
Esempio n. 14
0
 def blogs_info_view_by(self, usr=None, tagname=None, vfrom=0, vlim=20):
     from article.blog import Blog
     if tagname and tagname != 'default':
         toview, len_toview = self.blogs_from_tag(tagname, vfrom, vlim)
     else:
         toview = self.blogids
         len_toview = len(toview)
         if vfrom > len_toview:
             return [], len_toview
         if vfrom + vlim > len_toview:
             vlim = len_toview - vfrom
         toview = toview[vfrom:(vfrom + vlim)]
         tmp = set(toview)
         toview = Blog.by_ids(toview)
         toview.sort()
         tmp2 = set(each._id for each in toview)
         self.lib.blog_list.pull(*tuple(tmp - tmp2))
         #try remove item not exist
     return [
         each.obj_info_view_by('basic_info', usr, env=usr)
         for each in toview
     ], len_toview
Esempio n. 15
0
#!/usr/bin/env python

from user import User
from article.blog import Blog

user_all = [User(each) for each in User.datatype.find()]

for each in user_all:
    tag_lib = each.lib.tag_lib
    tmp = tag_lib.load_all()
    for tag in tmp.keys():
        if tag == u'alltags':
            continue
        if not tmp[tag]:
            continue
        tmp[tag] = [[e._id, e.release_time]
                for e in Blog.by_ids(
                    [each[0] if isinstance(each, list) else each 
                    for each in tmp[tag]])]
    tag_lib.set_all(tmp)
Esempio n. 16
0
#!/usr/bin/env python
from user import User
from article.blog import Blog

usrs = [User(data=each) for each in User.datatype.find()]
for each in usrs:
    blogs = Blog.by_ids(each.lib.blog_list.load_all())
    for eb in blogs:
        eb.env = each
        eb.author = eb.author
        each.reset_blog_tags(eb)
Esempio n. 17
0
#!/usr/bin/env python

from user import User
from article.blog import Blog

user_all = [User(each) for each in User.datatype.find()]

for each in user_all:
    tag_lib = each.lib.tag_lib
    tmp = tag_lib.load_all()
    for tag in tmp.keys():
        if tag == u'alltags':
            continue
        if not tmp[tag]:
            continue
        tmp[tag] = [[e._id, e.release_time] for e in Blog.by_ids(
            [each[0] if isinstance(each, list) else each
             for each in tmp[tag]])]
    tag_lib.set_all(tmp)
#!/usr/bin/env python
from article.blog import Blog
from user import User

bids = ['5020dbdb37251703ac000005', '502266ba3725170e83000002', '502267a83725170e82000002', '502267a83725170e85000002', '50226ddd3725170ef3000003', '50227fef3725170f90000008']

blogobjs = Blog.by_ids(bids)
user_af = User.find_one({'email':'*****@*****.**'})
for each in blogobjs:
    each.set_propertys(env=user_af, author=user_af)
    user_af.add_tags(each.tag)
    user_af.post_blog(each)