def article_env_init(handler, handler_paras, handler_json):
    handler_json['article_id'] = handler_paras['article_id']
    usr = handler.current_user
    env = generator(handler_paras['env_id'], handler_paras['env_type'])
    handler.env = env
    father = generator(handler_paras['father_id'], 
                handler_paras['father_type'])
    ref_comment = None
    if handler_paras['article_type'] == 'comment':
        if father is None:
            return 18#Invalid father
        ref_comment = generator(handler_paras['ref_comment'], 
                            handler_paras['article_type'])
    handler.father = None
    handler.ref_comment = None
    if father is not None:
        handler.env = father.env
        handler.father = father
    elif not handler.env:
        return 14#Invalid Env Arguments
    if ref_comment is not None:
        handler.ref_comment = ref_comment
    if not Article.is_valid_id(handler_paras['article_id']):
        acls = cls_gen(handler_paras['article_type'])
        if not acls or not issubclass(acls, Article):
            return 11#Invalid Article Type
        if not issubclass(acls, Comment) and \
                not test_auth(handler.env.authority_verify(usr), A_WRITE):
            return 12#Permission Denied
        handler.article_obj = acls()
        if handler.article_obj is None:
            return 13#Article Create Failed
        handler.article_obj.set_propertys(env=handler.env, author=usr)
        usr.add_to_drafts(handler.article_obj)
        handler_json.as_new(handler.article_obj) 
        #new Article Created
    else:
        handler.article_obj = generator(handler_paras['article_id'],
                    handler_paras['article_type'])
        if not isinstance(handler.article_obj, Article) or \
                handler.article_obj is None:
            return 4#Article Not Exist
        if handler.article_obj.env_obj_info != env.obj_info:
            return 15#Invalid Env
        if not test_auth(handler.article_obj.authority_verify(usr, env),
                        A_WRITE):
            return 16#WRITE Permission Denied
    if ref_comment is not None:
        handler.article_obj.ref_comment = ref_comment
    if father is not None:
        if not handler.article_obj.father_id:
            handler.article_obj.father = handler.father
    return 0
Exemplo n.º 2
0
def article_env_init(handler, handler_paras, handler_json):
    handler_json['article_id'] = handler_paras['article_id']
    usr = handler.current_user
    env = generator(handler_paras['env_id'], handler_paras['env_type'])
    handler.env = env
    father = generator(handler_paras['father_id'],
                       handler_paras['father_type'])
    ref_comment = None
    if handler_paras['article_type'] == 'comment':
        if father is None:
            return 18  #Invalid father
        ref_comment = generator(handler_paras['ref_comment'],
                                handler_paras['article_type'])
    handler.father = None
    handler.ref_comment = None
    if father is not None:
        handler.env = father.env
        handler.father = father
    elif not handler.env:
        return 14  #Invalid Env Arguments
    if ref_comment is not None:
        handler.ref_comment = ref_comment
    if not Article.is_valid_id(handler_paras['article_id']):
        acls = cls_gen(handler_paras['article_type'])
        if not acls or not issubclass(acls, Article):
            return 11  #Invalid Article Type
        if not issubclass(acls, Comment) and \
                not test_auth(handler.env.authority_verify(usr), A_WRITE):
            return 12  #Permission Denied
        handler.article_obj = acls()
        if handler.article_obj is None:
            return 13  #Article Create Failed
        handler.article_obj.set_propertys(env=handler.env, author=usr)
        usr.add_to_drafts(handler.article_obj)
        handler_json.as_new(handler.article_obj)
        #new Article Created
    else:
        handler.article_obj = generator(handler_paras['article_id'],
                                        handler_paras['article_type'])
        if not isinstance(handler.article_obj, Article) or \
                handler.article_obj is None:
            return 4  #Article Not Exist
        if handler.article_obj.env_obj_info != env.obj_info:
            return 15  #Invalid Env
        if not test_auth(handler.article_obj.authority_verify(usr, env),
                         A_WRITE):
            return 16  #WRITE Permission Denied
    if ref_comment is not None:
        handler.article_obj.ref_comment = ref_comment
    if father is not None:
        if not handler.article_obj.father_id:
            handler.article_obj.father = handler.father
    return 0
Exemplo n.º 3
0
 def get(self):
     pageparas = ArticleWritePara(self)
     page = WritePage(self)
     usr = self.current_user
     page['article_type'] = pageparas['type']
     page['article_type_with_env'] = page['article_type']
     article_cls = cls_gen(pageparas['type'])
     if not article_cls or not issubclass(article_cls, Article):
         self.send_error(404, error_info=u'Invalid Article Type')
         #todo Earthson
         return
     env = None
     if pageparas['env_id'] or pageparas['env_type']:
         env = generator(pageparas['env_id'], pageparas['env_type'])
         if not env:
             self.send_error(404, error_info=u'Invalid Envirenment')
             return
         env_info = env.obj_info
         page['env'] = env.as_env
     if not pageparas['id']:
         if not env:
             env = usr
             env_info = env.obj_info
             page['env'] = env.as_env
         page['article_type_with_env'] = env.first_alias + \
                                 '-' + article_cls.first_alias
         page.page_init()
         page.render()
         return
     page['isedit'] = True
     toedit = generator(pageparas['id'], pageparas['type'])
     if toedit is None:
         self.send_error(404, error_info=u'Article Not Found')
         return
     page['article_type_with_env'] = toedit.article_type_with_env
     env = toedit.env
     page['env'] = env.as_env
     auth_ret = toedit.authority_verify(usr, env=env)
     if not test_auth(auth_ret, A_WRITE):
         self.send_error(404, error_info=u'Permission Denied')
         return
     page['article'] = toedit.obj_info_view_by('edit_info',
                                               usr=usr,
                                               env=env)
     page.page_init()
     page.render()
     return
 def get(self):
     pageparas = ArticleWritePara(self)
     page = WritePage(self)
     usr = self.current_user
     page['article_type'] = pageparas['type']
     page['article_type_with_env'] = page['article_type']
     article_cls = cls_gen(pageparas['type'])
     if not article_cls or not issubclass(article_cls, Article):
         self.send_error(404, error_info=u'Invalid Article Type') 
         #todo Earthson
         return
     env = None
     if pageparas['env_id'] or pageparas['env_type']:
         env = generator(pageparas['env_id'], pageparas['env_type'])
         if not env:
             self.send_error(404, error_info=u'Invalid Envirenment')
             return
         env_info = env.obj_info
         page['env'] = env.as_env
     if not pageparas['id']:
         if not env:
             env = usr
             env_info = env.obj_info
             page['env'] = env.as_env
         page['article_type_with_env'] = env.first_alias + \
                                 '-' + article_cls.first_alias
         page.page_init()
         page.render()
         return
     page['isedit'] = True
     toedit = generator(pageparas['id'], pageparas['type'])
     if toedit is None:
         self.send_error(404, error_info=u'Article Not Found')
         return
     page['article_type_with_env'] = toedit.article_type_with_env
     env = toedit.env
     page['env'] = env.as_env
     auth_ret = toedit.authority_verify(usr, env=env)
     if not test_auth(auth_ret, A_WRITE):
         self.send_error(404, error_info=u'Permission Denied')
         return
     page['article'] = toedit.obj_info_view_by('edit_info', usr=usr, env=env)
     page.page_init()
     page.render()
     return
 def post(self):
     handler_paras = ArticleSrcPara(self)
     handler_json = ArticleSrcJson(self)
     usr = self.current_user
     status = self.env_init(handler_paras, handler_json)
     handler_json['src_alias'] = handler_paras['src_alias']
     if status == 0 and handler_paras.error_code > 0:
         #data read error
         status = handler_paras.error_code
     if handler_paras['do'] in ['new'] and \
             handler_paras['src_type'] in ['img', 'image']:
         #do not return json if upload_img
         handler_json.is_json = False
     if status != 0:
         handler_json.by_status(status)
         handler_json.write()
         return #Error
     if handler_paras['do'] not in ['new', 'edit', 'remove']:
         handler_json.by_status(8)
         handler_json.write()
         return #Unsupported Operation
     scls = cls_gen(handler_paras['src_type'])
     if handler_paras['do'] == 'new':
         if scls is None:
             handler_json.by_status(5)
             handler_json.write()
             return #Unsupported Ref Type
         src_obj = scls()
         tmps = self.article_obj.add_ref(src_obj)
         if tmps is False:
             handler_json.by_status(19)
             handler_json.write()
             return #Add Ref Failed
         handler_json.as_new_src(src_obj)
         src_obj.set_by_info(handler_paras.load_doc())
         if handler_paras['src_type'] in ['img', 'image']:
             handler_json['img_url'] = src_obj.thumb_url
         handler_json.by_status(0)
         handler_json.write()
         return #0
     elif handler_paras['do'] == 'remove':
         self.article_obj.remove_ref(scls.first_alias, 
                         handler_paras['src_alias'])
         handler_json.by_status(0)
         handler_json.write()
         return #0
     elif handler_paras['do'] == 'edit':
         src_obj = self.article_obj.get_ref(scls.first_alias,
                             handler_paras['src_alias']) 
         if src_obj is None:
             handler_json.by_status(18)
             handler_json.write()
             return #Src Not Exist
         src_obj.set_by_info(handler_paras.load_doc())
         if handler_paras['src_type'] in ['img', 'image']:
             handler_json['img_url'] = src_obj.thumb_url
         self.article_obj.do_update()
         handler_json.by_status(0)
         handler_json.write()
         return #0
     handler_json.by_status(8)
     handler.write()
     return #Unexpected Operation
Exemplo n.º 6
0
 def post(self):
     handler_paras = ArticleSrcPara(self)
     handler_json = ArticleSrcJson(self)
     usr = self.current_user
     status = self.env_init(handler_paras, handler_json)
     handler_json['src_alias'] = handler_paras['src_alias']
     if status == 0 and handler_paras.error_code > 0:
         #data read error
         status = handler_paras.error_code
     if handler_paras['do'] in ['new'] and \
             handler_paras['src_type'] in ['img', 'image']:
         #do not return json if upload_img
         handler_json.is_json = False
     if status != 0:
         handler_json.by_status(status)
         handler_json.write()
         return  #Error
     if handler_paras['do'] not in ['new', 'edit', 'remove']:
         handler_json.by_status(8)
         handler_json.write()
         return  #Unsupported Operation
     scls = cls_gen(handler_paras['src_type'])
     if handler_paras['do'] == 'new':
         if scls is None:
             handler_json.by_status(5)
             handler_json.write()
             return  #Unsupported Ref Type
         src_obj = scls()
         tmps = self.article_obj.add_ref(src_obj)
         if tmps is False:
             handler_json.by_status(19)
             handler_json.write()
             return  #Add Ref Failed
         handler_json.as_new_src(src_obj)
         src_obj.set_by_info(handler_paras.load_doc())
         if handler_paras['src_type'] in ['img', 'image']:
             handler_json['img_url'] = src_obj.thumb_url
         handler_json.by_status(0)
         handler_json.write()
         return  #0
     elif handler_paras['do'] == 'remove':
         self.article_obj.remove_ref(scls.first_alias,
                                     handler_paras['src_alias'])
         handler_json.by_status(0)
         handler_json.write()
         return  #0
     elif handler_paras['do'] == 'edit':
         src_obj = self.article_obj.get_ref(scls.first_alias,
                                            handler_paras['src_alias'])
         if src_obj is None:
             handler_json.by_status(18)
             handler_json.write()
             return  #Src Not Exist
         src_obj.set_by_info(handler_paras.load_doc())
         if handler_paras['src_type'] in ['img', 'image']:
             handler_json['img_url'] = src_obj.thumb_url
         self.article_obj.do_update()
         handler_json.by_status(0)
         handler_json.write()
         return  #0
     handler_json.by_status(8)
     handler.write()
     return  #Unexpected Operation