def post(self):
     from pages.postjson import CatalogManagerAddJson
     handler_para = CatalogManagerAddPara(self)
     handler_json = CatalogManagerAddJson(self)
     usr = self.current_user
     book = Catalog.by_id(handler_para['id'])
     if book is None:
         handler_json.by_status(1)
         handler_json.write()
         return #book not exist
     tomodify = User.by_id(handler_para['uid'])
     if tomodify is None:
         handler_json.by_status(2)
         handler_json.write()
         return #user to add not exist
     tmp_auth = book.authority_verify(usr=usr)
     if test_auth(tmp_auth, A_OWNER) is False:
         handler_json.by_status(4)
         handler_json.write()
         return #permission denied
     add_stat = book.add_manager(tomodify)
     if add_stat is False:
         handler_json.by_status(3)
         handler_json.write()
         return #managers full
     handler_json['new_manager'] = tomodify.json_info_view_by(usr=usr)
     handler_json.by_status(0)
     handler_json.write()
     return #0
 def post(self):
     handler_para = CatalogSectionNewPara(self)
     handler_json = CatalogSectionNewJson(self)
     usr = self.current_user
     book = Catalog.by_id(handler_para['book_id'])
     if book is None:
         handler_json.by_status(3)
         handler_json.write()
         return #book not exist
     auth_tmp = book.authority_verify(usr=usr, env=book)
     if test_auth(auth_tmp, A_WRITE) is False:
         handler_json.by_status(5)
         handler_json.write()
         return #permission denied
     if not handler_para['section']:
         handler_json.by_status(1)
         handler_json.write()
         return #section is empty
     if not handler_para['title']:
         handler_json.by_status(2)
         handler_json.write()
         return #title is empty
     handler_json['node_id'] = book.add_node(handler_para['title'], 
                                             handler_para['section'])
     handler_json.by_status(0)
     handler_json.write()
     return #0
 def post(self):
     handler_para = UnSpecArticleFromBookPara(self)
     handler_json = UnSpecArticleFromBookJson(self)
     usr = self.current_user
     book = Catalog.by_id(handler_para['book_id'])
     relation_obj = Relation.by_id(handler_para['relation_id'])
     if book is None:
         handler_json.by_status(2)
         handler_json.write()
         return  #book not exist
     if relation_obj is None:
         handler_json.by_status(1)
         handler_json.write()
         return  #relation not exist
     auth_tmp = book.authority_verify(usr, env=book)
     if test_auth(auth_tmp, A_WRITE) is False:
         handler_json.by_status(4)
         handler_json.write()
         return  #permission denied
     status = book.unspec_article_to(handler_para['node_id'], relation_obj)
     if status is False:
         handler_json.by_status(3)
         handler_json.write()
         return  #set failed, node_id may not exist
     handler_json.by_status(0)
     handler_json.write()
     return  #0
 def post(self):
     from pages.postjson import CatalogManagerAddJson
     handler_para = CatalogManagerAddPara(self)
     handler_json = CatalogManagerAddJson(self)
     usr = self.current_user
     book = Catalog.by_id(handler_para['id'])
     if book is None:
         handler_json.by_status(1)
         handler_json.write()
         return  #book not exist
     tomodify = User.by_id(handler_para['uid'])
     if tomodify is None:
         handler_json.by_status(2)
         handler_json.write()
         return  #user to add not exist
     tmp_auth = book.authority_verify(usr=usr)
     if test_auth(tmp_auth, A_OWNER) is False:
         handler_json.by_status(4)
         handler_json.write()
         return  #permission denied
     add_stat = book.add_manager(tomodify)
     if add_stat is False:
         handler_json.by_status(3)
         handler_json.write()
         return  #managers full
     handler_json['new_manager'] = tomodify.json_info_view_by(usr=usr)
     handler_json.by_status(0)
     handler_json.write()
     return  #0
 def post(self):
     handler_para = RecArticleToBookPara(self)
     handler_json = RecArticleToBookJson(self)
     usr = self.current_user
     book = Catalog.by_id(handler_para['book_id'])
     if book is None:
         handler_json.by_status(2)
         handler_json.write()
         return  #book not exist
     article_obj = generator(handler_para['article_id'],
                             handler_para['article_type'])
     if article_obj is None:
         handler_json.by_status(1)
         handler_json.write()
         return  #article not exist
     rr = article_obj.add_to_catalog(book, handler_para['node_id'])
     if rr is None:
         handler_json.by_status(3)
         handler_json.write()
         return  #section not exist
     handler_json['book_title'] = book.name
     handler_json['chapter_title'] = book.get_node_dict(
         handler_para['node_id'])['title']
     handler_json['article_title'] = article_obj.name
     handler_json['relation_id'] = rr.uid
     handler_json.by_status(0)
     handler_json.write()
     return  #0
 def post(self):
     handler_para = CatalogSectionNewPara(self)
     handler_json = CatalogSectionNewJson(self)
     usr = self.current_user
     book = Catalog.by_id(handler_para['book_id'])
     if book is None:
         handler_json.by_status(3)
         handler_json.write()
         return  #book not exist
     auth_tmp = book.authority_verify(usr=usr, env=book)
     if test_auth(auth_tmp, A_WRITE) is False:
         handler_json.by_status(5)
         handler_json.write()
         return  #permission denied
     if not handler_para['section']:
         handler_json.by_status(1)
         handler_json.write()
         return  #section is empty
     if not handler_para['title']:
         handler_json.by_status(2)
         handler_json.write()
         return  #title is empty
     handler_json['node_id'] = book.add_node(handler_para['title'],
                                             handler_para['section'])
     handler_json.by_status(0)
     handler_json.write()
     return  #0
 def post(self):
     handler_para = UnSpecArticleFromBookPara(self)
     handler_json = UnSpecArticleFromBookJson(self)
     usr = self.current_user
     book = Catalog.by_id(handler_para['book_id'])
     relation_obj = Relation.by_id(handler_para['relation_id'])
     if book is None:
         handler_json.by_status(2)
         handler_json.write()
         return #book not exist
     if relation_obj is None:
         handler_json.by_status(1)
         handler_json.write()
         return #relation not exist
     auth_tmp = book.authority_verify(usr, env=book)
     if test_auth(auth_tmp, A_WRITE) is False:
         handler_json.by_status(4)
         handler_json.write()
         return #permission denied
     status = book.unspec_article_to(handler_para['node_id'], relation_obj)
     if status is False:
         handler_json.by_status(3)
         handler_json.write()
         return #set failed, node_id may not exist
     handler_json.by_status(0)
     handler_json.write()
     return #0
 def post(self):
     handler_para = RecArticleToBookPara(self)
     handler_json = RecArticleToBookJson(self)
     usr = self.current_user
     book = Catalog.by_id(handler_para['book_id'])
     if book is None:
         handler_json.by_status(2)
         handler_json.write()
         return #book not exist
     article_obj = generator(handler_para['article_id'], 
                             handler_para['article_type'])
     if article_obj is None:
         handler_json.by_status(1)
         handler_json.write()
         return #article not exist
     rr = article_obj.add_to_catalog(book, handler_para['node_id'])
     if rr is None:
         handler_json.by_status(3)
         handler_json.write()
         return #section not exist
     handler_json['book_title'] = book.name
     handler_json['chapter_title'] = book.get_node_dict(
                 handler_para['node_id'])['title']
     handler_json['article_title'] = article_obj.name
     handler_json['relation_id'] = rr.uid
     handler_json.by_status(0)
     handler_json.write()
     return #0
Ejemplo n.º 9
0
 def create_catalog(self, name, keywords=''):
     from article.catalog import Catalog
     newobj = Catalog(attrs={
         'name': name,
         'keywords': keywords,
         'owner': self
     })
     self.lib.managed_catalog_lib[newobj.uid] = ['admin', datetime.now()]
     return newobj
Ejemplo n.º 10
0
def bookedit_init(handler, bid, page):
    book = Catalog.by_id(bid)
    if book is None:
        return 1  #book not exist
    usr = handler.current_user
    auth_tmp = book.authority_verify(usr=usr, env=book)
    if test_auth(auth_tmp, A_WRITE) is False:
        return 2  #permission denied
    handler.book = book
    return 0
Ejemplo n.º 11
0
 def get(self):
     handler_page = AFBookPage(self)
     usr = self.current_user
     try:
         books = sorted(Catalog.by_ids(recent_books.get_slice(-20)),
                        reverse=False)
     except:
         books = []
     handler_page['book_list'] = [
         each.obj_info_view_by('overview_info', usr=usr, env=None)
         for each in books
     ]
     handler_page.render()
     return  #0
Ejemplo n.º 12
0
 def get(self, bid):
     from article.catalog import Catalog
     handler_page = BookCatalogPage(self)
     usr = self.current_user
     handler_page['bid'] = bid
     catalog_obj = Catalog.by_id(bid)
     if catalog_obj is None:
         self.send_error(404)
         return
     handler_page['book'] = catalog_obj.obj_info_view_by('basic_info', 
                                 usr=usr)
     handler_page.page_init()
     book_name = handler_page['book']['name']
     handler_page['title'] = book_name + u' - 子曰知识谱'
     handler_page['meta_keywords'] = handler_page['book']['keywords']
     handler_page['description'] = u'知识谱' + book_name + u'目录'
     handler_page.render()
     return
 def post(self):
     from pages.postjson import CatalogInfoModifyJson
     handler_para = CatalogInfoModifyPara(self)
     handler_json = CatalogInfoModifyJson(self)
     usr = self.current_user
     book = Catalog.by_id(handler_para['id'])
     if book is None:
         handler_json.by_status(1)
         handler_json.write()
         return  #book not exist
     tmp_auth = book.authority_verify(usr)
     if test_auth(tmp_auth, A_WRITE) is False:
         handler_json.by_status(2)
         handler_json.write()
         return  #permission denied
     book.set_by_info(handler_para)
     handler_json.by_status(0)
     handler_json.write()
     return  #0
 def post(self):
     from pages.postjson import CatalogInfoModifyJson
     handler_para = CatalogInfoModifyPara(self)
     handler_json = CatalogInfoModifyJson(self)
     usr = self.current_user
     book = Catalog.by_id(handler_para['id'])
     if book is None:
         handler_json.by_status(1)
         handler_json.write()
         return #book not exist
     tmp_auth = book.authority_verify(usr)
     if test_auth(tmp_auth, A_WRITE) is False:
         handler_json.by_status(2)
         handler_json.write()
         return #permission denied
     book.set_by_info(handler_para)
     handler_json.by_status(0)
     handler_json.write()
     return #0
 def post(self):
     from pages.postjson import CatalogManagerDelJson
     handler_para = CatalogManagerDelPara(self)
     handler_json = CatalogManagerDelJson(self)
     usr = self.current_user
     book = Catalog.by_id(handler_para['id'])
     if book is None:
         handler_json.by_status(1)
         handler_json.write()
         return #book not exist
     tmp_auth = book.authority_verify(usr=usr)
     if test_auth(tmp_auth, A_OWNER) is False:
         handler_json.by_status(2)
         handler_json.write()
         return #permission denied
     tomodify = User.by_id(handler_para['uid'])
     book.del_manager(tomodify)
     handler_json.by_status(0)
     handler_json.write()
     return #0
 def post(self):
     from pages.postjson import CatalogManagerDelJson
     handler_para = CatalogManagerDelPara(self)
     handler_json = CatalogManagerDelJson(self)
     usr = self.current_user
     book = Catalog.by_id(handler_para['id'])
     if book is None:
         handler_json.by_status(1)
         handler_json.write()
         return  #book not exist
     tmp_auth = book.authority_verify(usr=usr)
     if test_auth(tmp_auth, A_OWNER) is False:
         handler_json.by_status(2)
         handler_json.write()
         return  #permission denied
     tomodify = User.by_id(handler_para['uid'])
     book.del_manager(tomodify)
     handler_json.by_status(0)
     handler_json.write()
     return  #0
 def post(self):
     handler_para = CatalogSectionDelPara(self)
     handler_json = CatalogSectionDelJson(self)
     usr = self.current_user
     book = Catalog.by_id(handler_para['book_id'])
     if book is None:
         handler_json.by_status(1)
         handler_json.write()
         return  #book not exist
     auth_tmp = book.authority_verify(usr=usr, env=book)
     if test_auth(auth_tmp, A_DEL) is False:
         handler_json.by_status(5)
         handler_json.write()
         return  #permission dined
     if not handler_para['node_id'] or \
             book.remove_node(handler_para['node_id']) is False:
         handler_json.by_status(2)
         handler_json.write()
         return  #node not exist
     handler_json.by_status(0)
     handler_json.write()
     return  #0
 def post(self):
     handler_para = DelArticleFromBookPara(self)
     handler_json = DelArticleFromBookJson(self)
     usr = self.current_user
     book = Catalog.by_id(handler_para['book_id'])
     article_obj = generator(handler_para['article_id'],
                             handler_para['article_type'])
     if article_obj is None:
         handler_json.by_status(1)
         handler_json.write()
         return  #article not exist
     auth_tmp = article_obj.authority_verify(usr, env=book)
     if book is not None:
         auth_tmp |= book.authority_verify(usr, env=book)
     if test_auth(auth_tmp, A_WRITE) is False:
         handler_json.by_status(2)
         handler_json.write()
         return  #permission denied
     rr = article_obj.remove_from_catalog(book, handler_para['node_id'])
     handler_json.by_status(0)
     handler_json.write()
     return  #0
 def post(self):
     handler_para = CatalogSectionDelPara(self)
     handler_json = CatalogSectionDelJson(self)
     usr = self.current_user
     book = Catalog.by_id(handler_para['book_id'])
     if book is None:
         handler_json.by_status(1)
         handler_json.write()
         return #book not exist
     auth_tmp = book.authority_verify(usr=usr, env=book)
     if test_auth(auth_tmp, A_DEL) is False:
         handler_json.by_status(5)
         handler_json.write()
         return #permission dined
     if not handler_para['node_id'] or \
             book.remove_node(handler_para['node_id']) is False:
         handler_json.by_status(2)
         handler_json.write()
         return #node not exist
     handler_json.by_status(0)
     handler_json.write()
     return #0
 def post(self):
     handler_para = DelArticleFromBookPara(self)
     handler_json = DelArticleFromBookJson(self)
     usr = self.current_user
     book = Catalog.by_id(handler_para['book_id'])
     article_obj = generator(handler_para['article_id'], 
                             handler_para['article_type'])
     if article_obj is None:
         handler_json.by_status(1)
         handler_json.write()
         return #article not exist
     auth_tmp = article_obj.authority_verify(usr, env=book)
     if book is not None:
         auth_tmp |= book.authority_verify(usr, env=book)
     if test_auth(auth_tmp, A_WRITE) is False:
         handler_json.by_status(2)
         handler_json.write()
         return #permission denied
     rr = article_obj.remove_from_catalog(book, handler_para['node_id'])
     handler_json.by_status(0)
     handler_json.write()
     return #0
Ejemplo n.º 21
0
    def get(self, bid, cnum):
        from article.catalog import Catalog
        handler_page = BookChapterPage(self)
        usr = self.current_user
        catalog_obj = Catalog.by_id(bid)
        if catalog_obj is None:
            self.send_error(404)
            return
        chapter_info = catalog_obj.get_node_info_view_by(cnum, usr, catalog_obj)
        if chapter_info is None:
            self.send_error(404)
            return
        handler_page['current_chapter'] = chapter_info
        handler_page['book'] = catalog_obj.obj_info_view_by('basic_info', 
                                    usr, catalog_obj)
        cids = [each['cid'] for each in handler_page['book']['chapter_list']]
        cid = chapter_info['cid']
        pre, nxt = None, None
        for i in xrange(len(cids)): #get position of current
            if cid == cids[i]:
                pre = i - 1 if i > 0 else None
                nxt = i + 1 if i + 1 < len(cids) else None
                break
        handler_page['previous_chapter'] = None if pre is None else \
                handler_page['book']['chapter_list'][pre] 
        handler_page['next_chapter'] = None if nxt is None else \
                handler_page['book']['chapter_list'][nxt]
        handler_page['bid'] = bid
        handler_page.page_init()

        book_name = handler_page['book']['name']
        chapter_num = handler_page['current_chapter']['chapter_num']
        chapter_name = handler_page['current_chapter']['title']
        handler_page['title'] = chapter_num + u' -  ' +chapter_name + u' - ' + book_name
        handler_page['meta_keywords'] = handler_page['book']['keywords']
        handler_page['description'] = book_name + u',' + chapter_name
        handler_page.render()
        return
Ejemplo n.º 22
0
#!/usr/bin/env python

from global_info import *
from article.blog import Blog
from article.catalog import Catalog
from user import User

recent_blogs.set_all([None for i in range(500)])
blog_all = sorted([Blog(each) for each in Blog.datatype.find()], reverse=True)
for each in blog_all:
    if each.is_posted is False:
        continue
    recent_blogs.push(each._id)
    recent_blogs.pop_head()

recent_books.set_all([None for i in range(500)])
book_all = sorted([Catalog(each) for each in Catalog.datatype.find()],
                  reverse=True)
for each in book_all:
    recent_books.push(each._id)
    recent_books.pop_head()

recent_users.set_all([None for i in range(500)])
user_all = sorted([User(each) for each in User.datatype.find()], reverse=True)
for each in user_all:
    recent_users.push(each._id)
    recent_users.pop_head()

unreg_users.set_all([None for i in range(5000)])
recent_feedbacks.set_all([None for i in range(500)])
Ejemplo n.º 23
0
 def getter(self):
     from article.catalog import Catalog
     cids = self.lib.managed_catalog_lib.keys()
     return sorted(Catalog.by_ids(cids), reverse=True)
Ejemplo n.º 24
0
 def getter(self):
     from article.catalog import Catalog
     cids = self.lib.managed_catalog_lib.keys()
     return sorted(Catalog.by_ids(cids), reverse=True)
Ejemplo n.º 25
0
#!/usr/bin/env python

from article.catalog import Catalog

all_catalogs = [Catalog(each) for each in Catalog.datatype.find()]
for each in all_catalogs:
    each.about.set_propertys(env=each, author_id=each.owner_id)

from user import User
user_all = [User(each) for each in User.datatype.find()]
for each in user_all:
    each.about.set_propertys(env=each, author_id=each._id)
Ejemplo n.º 26
0
#!/usr/bin/env python

from article.catalog import Catalog

catalog_all = [Catalog(each) for each in Catalog.datatype.find()]

for each in catalog_all:
    if not each.keywords:
        each.keywords = [each.name]
    each.remove_count = each.node_count - len(each.lib.node_lib)
    each.complete_count = 0
    for ek, ev in each.lib.node_info_lib.load_all().items():
        each.get_node_dict(ek)['article_count'] = len(ev['articles'])
        each.get_node_dict(ek)['subcatalog_count'] = len(ev['catalogs'])
        each.get_node_dict(ek)['spec_count'] = len(ev['main'])
        if len(ev['main']) != 0:
            each.complete_count += 1
Ejemplo n.º 27
0
#!/usr/bin/env python

from article.catalog import Catalog

catalogall = [Catalog(data=each) for each in Catalog.datatype.find()]

for each in catalogall:
    each.managers = list()