示例#1
0
文件: AF_User.py 项目: deju/afw_old
    def post(self):
        user = self.current_user
        do = is_value(self.get_argument("do", "add"))
        tag = is_value(self.get_argument("tag", None))
        tag_page = is_value(self.get_argument("page", 'tag'))
        group_id = is_value(self.get_argument("group_id", '-1'))
        result = {'kind': -1, 'info': ''}
        if tag is None or len(tag) > 45:
            result['info'] = '分类字数需在15字以内!'
            self.write(json_encode(result))
            return
        if tag == "alltags" or tag == "default":
            result['info'] = '不能操作默认分类!'
            self.write(json_encode(result))
            return
        if tag_page != 'group-tag':
            target = user
        else:
            try:
                #print 'group_id', group_id
                group = BasicGroup(_id=group_id)
                if group.get_member_type(user) != 'Manager':
                    result['info'] = '您无权进行设置!'
                    self.write(json_encode(result))
                    return
            except Exception, e:
                logging.error(traceback.format_exc())
                logging.error('Url Error %s' % self.request.uri)

                result['info'] = '小组不存在!'
                self.write(json_encode(result))
                return
            else:
示例#2
0
文件: AF_User.py 项目: deju/afw_old
 def post(self):
     user = self.current_user
     do = is_value( self.get_argument("do", "add") )
     tag = is_value(self.get_argument("tag", None) )
     tag_page = is_value(self.get_argument("page", 'tag'))
     group_id = is_value( self.get_argument("group_id", '-1'))
     result = {'kind': -1, 'info': ''} 
     if tag is None or len(tag) > 45:
         result['info'] = '分类字数需在15字以内!'
         self.write( json_encode(result) )
         return
     if tag == "alltags" or tag == "default":
         result['info'] = '不能操作默认分类!'
         self.write( json_encode(result) )
         return
     if tag_page != 'group-tag':
         target = user
     else:
         try:
             #print 'group_id', group_id
             group = BasicGroup(_id=group_id)
             if group.get_member_type(user) != 'Manager':
                 result['info'] = '您无权进行设置!'
                 self.write(json_encode(result))
                 return
         except Exception, e:
             logging.error(traceback.format_exc())
             logging.error('Url Error %s' % self.request.uri)
             
             result['info'] = '小组不存在!'
             self.write(json_encode(result))
             return
         else:
示例#3
0
def fun_update_group_article(user=None, group_id='-1', article_id = '-1', article_type='blog', title='', summary='', body='',
                     permission='public', keys=[], classes=[], father_id='-1', father_type='blog', do="post"):

    try:
        group = BasicGroup(_id=group_id)
        limit = group.authority_verify(user)
        #print 'User limit ', limit
    except Exception, e:
        logging.error(traceback.format_exc())
        logging.error('Group not exist %s' % group_id)
        return [1, '小组不存在!']
示例#4
0
def fun_group_create(user, group_name='', group_detail='', group_class=''):
    if AFWConfig.afewords_group_open is not True:
        return [1, '创建小组暂时未开放!']
    if group_name == '' or group_detail == '':
        return [1, '小组信息不完整!']
    
    new_group = BasicGroup()
    new_group.set_propertys(**{'name': group_name, 'alias': group_name})
    new_group.about.body = group_detail
    new_group.avatar.thumb_name = '/static/img/afewords-group.jpg'
    user.follow_group(new_group)
    new_group.set_manager(user)

    return [0, str(new_group._id)]
示例#5
0
文件: AF_Group.py 项目: deju/afw_old
 def get(self):
     user = self.current_user
     AFUser = SuperUser(user)
     group_id = is_value( self.get_argument("id", 1) )
     AFGroup = None
     try:
         group = BasicGroup(_id=group_id)
         #print 'author ,', group.authority_verify(user)
         #print 'member, ', group.member_lib.load_all()
         if group.get_member_type(user) != 'Manager':
             AFGroup = None
         else:
             AFGroup = AFWBasicGroup(group)
     except Exception, e:
         error_info = { 'my_exc_info': traceback.format_exc(), 'des':'未找到该小组!',
             'reason': ['该小组不存在!', '或者该小组已经被删除!']}
         return self.send_error(404, **error_info)
示例#6
0
def fun_get_feed_by_id(user=None, obj_id=0, page_cap=20):
    # find by the post id

    #feed_id_list = [] #BlogPool().load_all()
    AFW_Group = BasicGroup(_id=AFWConfig.afewords_group_id)
    feed_id_list = AFW_Group.recommended_list.load_all()
    feed_id_list.reverse()
    #feed_id_list = [str(kk) for kk in feed_id_list]

    #print feed_id_list
    if obj_id == '0' or obj_id == 0:
        index = -1
    else:
        index = index_at_list(feed_id_list, convert_id(obj_id))
    if index is None:
        return [1, '操作出错!']

    load_list_id = feed_id_list[index + 1:index + page_cap + 1]
    if len(load_list_id) < page_cap:
        is_all = 'yes'
    else:
        is_all = 'no'
    #print 'index', index
    #print 'load list', load_list_id
    if load_list_id == []:
        last_id = 0
    else:
        last_id = load_list_id[len(load_list_id) - 1]
    tmp_blog_con = Blog.get_instances('_id', load_list_id)

    tmp_blog_list = []
    for one_blog in tmp_blog_con:
        try:
            tmp_user = User(_id=one_blog.author_id)
        except Exception, e:
            log_error('User is not exist, User ID: ' + one_blog.author_id)
            continue
        else:
            tmp_avatar = tmp_user.avatar
            tmp_blog_list.append({
                'blog_id':
                str(one_blog._id),
                'title':
                one_blog.name,
                'author_id':
                str(tmp_user._id),
                'view_body':
                strip_tags(one_blog.view_body) +
                '<a target="_blank" class="blog_detail" href="/blog/' +
                str(one_blog._id) + '">...</a>',
                'summary':
                one_blog.abstract,
                'author_avatar':
                tmp_avatar.thumb_name,
                'author_name':
                tmp_user.name
            })
示例#7
0
def fun_update_group_article(user=None,
                             group_id='-1',
                             article_id='-1',
                             article_type='blog',
                             title='',
                             summary='',
                             body='',
                             permission='public',
                             keys=[],
                             classes=[],
                             father_id='-1',
                             father_type='blog',
                             do="post"):

    try:
        group = BasicGroup(_id=group_id)
        limit = group.authority_verify(user)
        #print 'User limit ', limit
    except Exception, e:
        logging.error(traceback.format_exc())
        logging.error('Group not exist %s' % group_id)
        return [1, '小组不存在!']
示例#8
0
def fun_invite_friend(user, email=''):
    ''' invite friend by email list, the list is splitby \nor \r\n '''
    email_list = email.split(';')
    #print email_list
    AFW_Group = BasicGroup(_id=AFWConfig.afewords_group_id)
    send_ok_list = []
    true_email = 0
    for one_email in email_list:
        if is_email(one_email):
            true_email = true_email + 1
            if user.domain == 'afewords.com':
                one_email = one_email.lower()
                mail_ok, mail_info = send_mail_invite(one_email, name=user.name, user_id=str(user._id))
                if mail_ok == 0:
                    #print 'one email ', one_email
                    tmp_email = one_email.replace(r'.', r'#')
                    AFW_Group.invitation_lib[tmp_email] = datetime.now()
                    user.invitations = user.invitations + 1
                    send_ok_list.append(one_email)
            else:
                if user.invitations < 5:     
                    # send the email
                    one_email = one_email.lower()
                    mail_ok, mail_info = send_mail_invite(one_email, name=user.name, user_id=str(user._id))
                    if mail_ok == 0:
                        #print 'one email ', one_email
                        tmp_email = one_email.replace(r'.', r'#')
                        AFW_Group.invitation_lib[tmp_email] = datetime.now()
                        #AFW_Group.invitation_lib['*****@*****.**'] = datetime.now()
                        user.invitations = user.invitations + 1
                        send_ok_list.append(one_email)
                else:
                    if len(send_ok_list) > 0:
                        return [1, '邀请数目操作限制!'+ ";".join(send_ok_list) + '的邀请已经发送!']
                    else:
                        return [1, "邀请数目操作限制!"]
    if true_email > len(send_ok_list):
        return [1, "操作出错!" + ";".join(send_ok_list) + '的邀请已经发送!']
    return [0, '邮件已经发送至' + ";".join(send_ok_list)]
示例#9
0
文件: AF_Group.py 项目: deju/afw_old
 def get(self, group_id):
     user = self.current_user
     if user is None:
         AFUser = None
     else:
         AFUser = SuperUser(user)
     AFGroup = None
     member_type = None
     try:
         group = BasicGroup(_id=group_id)
         AFGroup = AFWBasicGroup(group)
         title = group.name + ' - 小组'
         topic_list, topic_count, topic_page = fun_get_topic_list(group=group, page=1, page_cap=20)
         notice_list, notice_count, notice_page = fun_get_notice_list(group=group, page=1, page_cap=5)
         if user is not None:
             member_type = group.get_member_type(user)
     except Exception:
         error_info = { 'my_exc_info': traceback.format_exc(), 'des':'未找到该小组!',
             'reason': ['该小组不存在!', '或者该小组已经被删除!']}
         return self.send_error(404, **error_info)
     return self.render("group.html", title=title, user=AFUser, group=AFGroup, group_base_type="home",
         topic_list=topic_list, notice_list=notice_list, member_type=member_type)
示例#10
0
def fun_group_user_group(user):
    
    group_list_dict = user.follow_group_lib.load_all()
    group_list = group_list_dict.keys()
    group_topic_list = []
    
    group_instance_list = BasicGroup.get_instances('_id', group_list)
    for item in group_instance_list:
        tmp_topic_list, total_num, page = fun_get_topic_list(item, 1, 5)
            
        group_topic_list.append({'group_name': item.name, 'group_avatar': item.avatar.thumb_name, 
            'group_id': str(item._id), 'group_topic': tmp_topic_list })
    
    return group_topic_list
示例#11
0
文件: AF_Group.py 项目: deju/afw_old
 def get(self, group_id, article_id):
     user = self.current_user
     if user is None:
         AFUser = None
     else:
         AFUser = SuperUser(user)
     req_url = self.request.uri
     url_path = urlparse.urlparse(req_url)
     url_list = url_path.path.split('/')
     AFGroup = None
     if len(url_list) < 5 or url_list[3] not in ['topic', 'feedback', 'doc', 'notice']:
         raise Exception
     try:
         group = BasicGroup(_id=group_id)
         AFGroup = AFWBasicGroup(group)
     except Exception:
         error_info = { 'my_exc_info': traceback.format_exc(), 'des':'未找到该小组!',
             'reason': ['该小组不存在!', '或者该小组已经被删除!']}
         return self.send_error(404, **error_info)
     member_type = None
     script = []
     if url_list[3] == "topic":
         try:
             AF_Object = Topic(_id=article_id)
             if AF_Object.group_id != group._id and  AF_Object.is_posted is not True:
                 raise Exception
             if user is not None:
                 member_type = group.get_member_type(user)
         except Exception, e:
             error_info = { 'my_exc_info': traceback.format_exc(), 'des':'未找到该话题!',
                 'reason': ['该话题不存在!', '或者该话题已经被删除!']}
             return self.send_error(404, **error_info)
         else:
             title = AF_Object.name + ' - '+ group.name + '小组话题'
             script = fun_load_code_js(AF_Object.view_body)
             return self.render('group-lib-one-base.html', user=AFUser, group=AFGroup, title=title,
                     group_base_type='topic', article=AF_Object, member_type=member_type, script=script)
示例#12
0
文件: AF_Group.py 项目: deju/afw_old
 def get(self, article_id):
     user = self.current_user
     AFUser = SuperUser(user)
     article_type = is_value(self.get_argument("type", 'topic'))
     if article_type not in ['topic', 'doc', 'notice', 'feedback']:
         return self.redirect("/")
         
     if article_type == 'topic':
         try:
             AF_Object = Topic(_id=article_id)
             group = BasicGroup(_id=AF_Object.group_id)
             if group.get_member_type(user) is None or str(AF_Object.author_id) != str(user._id):
                 AFGroup = None
             else:
                 AFGroup = AFWBasicGroup(group)
                 AFObject = SuperArticle(AF_Object)
                 # get the want data
         except (ItemNotFoundError, InvalidIDError, DBIndexError, BaseDBError), e:
             logging.error(e.msg)
             logging.error('Url Error %s' % self.request.uri)
         except Exception, e:
             AFGroup = None
             logging.error(traceback.format_exc())
             logging.error('Url Error %s' % self.request.uri)
示例#13
0
def fun_group_lib(user=None, page=1, page_cap=10):
    group_instance = BasicGroup.get_instances()
    
    group_lib = []
    #print type(group_instance)
    #print 'page ', page
    min_index, max_index = get_index_list_by_page(group_instance, page=page, page_cap=page_cap)
    #print 'all ', len(group_instance)
    #print 'min,max', min_index, max_index
    for item in group_instance[min_index: max_index]:
        try:
            group_lib.append({'group_id': str(item._id), 'group_name': item.name, 'group_detail': item.about.view_body,
                'group_member_count': len(item.member_lib), 'group_avatar': item.avatar.thumb_name })
        except Exception, e:
            item.remove()
            continue
示例#14
0
def fun_update_blog(user=None,
                    blog=None,
                    title='',
                    summary='',
                    body='',
                    keys=[],
                    permission='public',
                    classes=[],
                    do='post'):
    if type(keys) != list:
        keys = keys_to_list(keys)
    AF_Object = blog
    temp_tag = AF_Object.tag
    remove_tag_list = list(set(temp_tag) - set(classes))
    add_tag_list = list(set(classes) - set(temp_tag))

    blog.set_propertys(
        **{
            'name': title,
            'abstract': summary,
            'body': body,
            "keywords": keys,
            'privilege': permission
        })

    if not AF_Object.is_posted:
        # not post
        for iii in remove_tag_list:
            if iii != 'default':
                AF_Object.remove_from_tag(iii)
        for iii in add_tag_list:
            AF_Object.add_to_tag(iii)
        if do == "post":
            user.post_blog(AF_Object)
            AFW_Group = BasicGroup(_id=AFWConfig.afewords_group_id)
            AFW_Group.recommended_list.push(AF_Object._id)
        return [0, str(AF_Object._id)]
    else:
        # have post the blog
        for iii in remove_tag_list:
            if iii != 'default':
                user.remove_from_tag(AF_Object, iii)
        for iii in add_tag_list:
            user.add_to_tag(AF_Object, iii)

        return [0, str(AF_Object._id)]
示例#15
0
def fun_group_user_group(user):

    group_list_dict = user.follow_group_lib.load_all()
    group_list = group_list_dict.keys()
    group_topic_list = []

    group_instance_list = BasicGroup.get_instances('_id', group_list)
    for item in group_instance_list:
        tmp_topic_list, total_num, page = fun_get_topic_list(item, 1, 5)

        group_topic_list.append({
            'group_name': item.name,
            'group_avatar': item.avatar.thumb_name,
            'group_id': str(item._id),
            'group_topic': tmp_topic_list
        })

    return group_topic_list
示例#16
0
def fun_group_create(user, group_name='', group_detail='', group_class=''):
    if AFWConfig.afewords_group_open is not True:
        return [1, '创建小组暂时未开放!']
    if group_name == '' or group_detail == '':
        return [1, '小组信息不完整!']

    new_group = BasicGroup()
    new_group.set_propertys(**{'name': group_name, 'alias': group_name})
    new_group.about.body = group_detail
    new_group.avatar.thumb_name = '/static/img/afewords-group.jpg'
    user.follow_group(new_group)
    new_group.set_manager(user)

    return [0, str(new_group._id)]
示例#17
0
def fun_group_lib(user=None, page=1, page_cap=10):
    group_instance = BasicGroup.get_instances()

    group_lib = []
    #print type(group_instance)
    #print 'page ', page
    min_index, max_index = get_index_list_by_page(group_instance,
                                                  page=page,
                                                  page_cap=page_cap)
    #print 'all ', len(group_instance)
    #print 'min,max', min_index, max_index
    for item in group_instance[min_index:max_index]:
        try:
            group_lib.append({
                'group_id': str(item._id),
                'group_name': item.name,
                'group_detail': item.about.view_body,
                'group_member_count': len(item.member_lib),
                'group_avatar': item.avatar.thumb_name
            })
        except Exception, e:
            item.remove()
            continue
示例#18
0
文件: AF_User.py 项目: deju/afw_old
         result['info'] = '该用户不存在!'
         self.write(json_encode(result))
         return
     else:
         if do == "follow":
             user.follow_user(follower)
             result['kind'] = 0
         elif do == "unfollow":
             user.unfollow_user(follower)
             result['kind'] = 0
         self.write(json_encode(result))
         return
 else:
     # for group follow
     try:
         group = BasicGroup(_id=follow_id)
     except Exception, e:
         logging.error(traceback.format_exc())
         logging.error('Url Error %s' % self.request.uri)
         result['info'] = '无此小组!'
         self.write(json_encode(result))
         return
     else:
         if do == "follow":
             user.follow_group(group)
             result['kind'] = 0
         else:
             if group.get_member_type(user) == 'Manager':
                 result['info'] = '管理员无法退出!'
             else:
                 if str(group._id) != AFWConfig.afewords_group_id:
示例#19
0
文件: AF_User.py 项目: deju/afw_old
class UploadImageHandler(BaseHandler):
    ''' all image upload request entrance 
        picture_type = [avatar || article || ...]
        target_type = [blog || comment || avatar || group ]
        target_id = [id || null ]
        article_type == "comment":  need 2 more arguments --- father, name
        article_type == "blog": need 1 more arguments --- name
        article_type == "avatar": need 0 more arguments
        article_type == "group": need 0 more arguments 
        
        Base path:
            in article: http://picture.afewords.com/static/picture/normal/xxx.xxx
                        http://picture.afewords.com/static/picture/small/xxx.xxx
                        subdomain picture1 for test only
            avatar:     http://picture.afewords.com/static/avatar/small/xxx.xxx
                        http://picture.afewords.com/static/avatar/normal/xxx.xxx
            group logo:
                        http://picture.afewords.com/static/logo/small/xxx.xxx
                        http://picture.afewords.com/static/logo/normal/xxx.xxx
    '''
    @authfilter
    def post(self):
        user = self.current_user
        picture_base_domain = "http://" + AFWConfig.afewords_image_domain + ".afewords.com"
        image_path = {
            'avatar': {
                'normal': "/static/avatar/normal/",
                'small': "/static/avatar/small/"
            },
            'logo': {
                'normal': '/static/logo/normal/',
                'small': "/static/logo/small/"
            },
            'article': {
                'normal': "/static/picture/normal/",
                'small': "/static/picture/small/"
            }
        }

        result = {'kind': -1, 'info': ''}
        #print 'request:', self.request
        picture_type = is_value(self.get_argument("picture_type", 'article'))
        if self.request.files == {} or 'picture' not in self.request.files:
            self.write('<script>alert("请选择图片!")</script>')
            return
        # get the file and named send_file
        # send_file { 'body' , 'filename', 'content_type'}
        send_file = self.request.files['picture'][0]
        #print send_file['content_type']
        image_type_list = [
            'image/gif', 'image/jpeg', 'image/pjpeg', 'image/bmp', 'image/png',
            'image/x-png'
        ]
        if send_file['content_type'] not in image_type_list:
            self.write(
                '<script>alert("仅支持jpg,jpeg,bmp,gif,png格式的图片!")</script>')
            return
        #print len(send_file['body'])
        if len(send_file['body']) > 4 * 1024 * 1024:
            restr = '<script>parent.image_upload_handler("' + picture_type + '", 1,"请选择4M以内的图片!")</script>'
            self.write(restr)
            return
        tmp_file = tempfile.NamedTemporaryFile(delete=True)
        #print dir(tmp_file), type(tmp_file)
        tmp_file.write(send_file['body'])
        tmp_file.seek(0)
        #print tmp_file.name, tmp_file.mode, tmp_file.encoding
        image_one = ''
        try:
            image_one = Image.open(tmp_file.name)
        except IOError, error:
            logging.error(error)
            logging.error('+' * 30 + '\n')
            logging.error(self.request.headers)
            tmp_file.close()
            restr = '<script>parent.image_upload_handler("' + picture_type + '", 1,"图片不合法!")</script>'
            self.write(restr)
            return
        #print image_one.size
        #print image_one.format
        if image_one.size[0] < 150 or image_one.size[1] < 150 or \
                image_one.size[0] > 2000 or image_one.size[1] > 2000:
            tmp_file.close()
            restr = '<script>parent.image_upload_handler("' + picture_type + '", 1,"图片长宽在150px~2000px之间!")</script>'
            self.write(restr)
            return
        image_format = send_file['filename'].split('.').pop().lower()
        store_name = "afw_" + random_string(10).lower() + str(int(
            time.time())) + '.' + image_format.lower()
        #print 'format', image_format
        #print 'store name ', store_name
        if picture_type in ['article', 'avatar', 'logo']:
            full_name_normal = AFWConfig.afewords_image_path + image_path[
                picture_type]['normal'] + store_name
            full_name_small = AFWConfig.afewords_image_path + image_path[
                picture_type]['small'] + store_name
            domain_name_normal = picture_base_domain + image_path[
                picture_type]['normal'] + store_name
            domain_name_small = picture_base_domain + image_path[picture_type][
                'small'] + store_name
        else:
            self.write('<script>alert("不支持当前上传!")</script>')
            return
        #image_one.save('./1.jpg')
        #if self.request.files['picture'] and
        #if self.request.files['picture'][0]
        #print '+'*30, self.request.files

        if picture_type == "article":
            # this is for article , [blog, comment, about ]
            #print 'picture_type', picture_type
            title = is_value(self.get_argument("title", None))
            article_id = is_value(self.get_argument("article_id", None))
            article_type = is_value(self.get_argument("article_type", None))
            father_id = is_value(self.get_argument("father_id", None))
            group_id = is_value(self.get_argument("group_id", None))
            if title is None or article_id is None or article_type is None:
                result['info'] = '标题不能为空!'
                restr = '<script>parent.picture_upload_handler(1,"' + result[
                    'info'] + '",0,0,-1,0)</script>'

                self.write(restr)
                return
            image_one.thumbnail((750, 1000), resample=1)
            image_one.save(str(full_name_normal))
            image_one.thumbnail((130, 120), resample=1)
            image_one.save(str(full_name_small))
            result['kind'], result['info'] = fun_new_article_pic(
                user,
                article_id=article_id,
                group_id=group_id,
                article_type=article_type,
                title=title,
                url=domain_name_normal,
                thumb=domain_name_small,
                father_id=father_id)
            if result['kind'] == 1:
                restr = '<script>parent.picture_upload_handler(1,"' + result[
                    'info'] + '",0,0,-1,0)</script>'
                self.write(restr)
                return
            # right
            res = result['info']
            #print res['article'], type(res['article'])
            article_id = res['article']
            restr = []
            restr.append('<script>parent.picture_upload_handler(')
            restr.append(str(result['kind']) + ',"')
            restr.append(domain_name_small + '",')
            restr.append(str(res['alias']) + ',"')
            restr.append(title + '",' + str(res['isnew']) + ',"')
            restr.append(res['article'])
            restr.append('")</script>')
            '''
            restr = ('<script>parent.picture_upload_handler(' 
                        + str(result['kind']) + ',"' 
                        + domain_name_small + '",' 
                        + str(res['alias']) +',"' 
                        + title +'",' + res['isnew']+
                        + ',"' + res['article'] +'")</script>')'''
            self.write(''.join(restr))
            return

        elif picture_type == "avatar":
            # this is for user to set avatar
            image_one.thumbnail((750, 1000), resample=1)
            image_one.save(str(full_name_normal))
            result['kind'], result['info'] = fun_save_thumb(store_name)
            if result['kind'] == 1:
                restr = '<script>parent.image_upload_handler("avatar", 1,"请选择图片")</script>'
                self.write(restr)
                return
            # set to user
            #print domain_name_small
            user_avatar = user.avatar
            user_avatar.set_propertys(**{
                'file_name': domain_name_normal,
                'thumb_name': domain_name_small
            })
            restr = '<script>parent.image_upload_handler("avatar", 0,"' + domain_name_normal + '")</script>'
            self.write(restr)
            return

        elif picture_type == "logo":
            # this is for group to set logo
            group_id = is_value(self.get_argument("group_id", 1))
            try:
                tmp_group = BasicGroup(_id=group_id)
                if tmp_group.get_member_type(user) != 'Manager':
                    restr = '<script>parent.image_upload_handler("logo", 1,"您无权设置!")</script>'
                    self.write(restr)
                    return
            except Exception, e:
                logging.error(e)
                logging.error('Group not exist, ' + group_id)
                restr = '<script>parent.image_upload_handler("logo", 1,"参数出错!")</script>'
                self.write(restr)
                return

            image_one.thumbnail((750, 1000), resample=1)
            image_one.save(str(full_name_normal))
            result['kind'], result['info'] = fun_save_thumb(
                store_name,
                normal_path=AFWConfig.afewords_image_path +
                "/static/logo/normal/",
                small_path=AFWConfig.afewords_image_path +
                "/static/logo/small/")
            if result['kind'] == 1:
                restr = '<script>parent.image_upload_handler("logo", 1,"请选择Logo")</script>'
                self.write(restr)
                return

            group_avatar = tmp_group.avatar
            group_avatar.set_propertys(**{
                'file_name': domain_name_normal,
                'thumb_name': domain_name_small
            })
            restr = '<script>parent.image_upload_handler("logo", 0,"' + domain_name_normal + '", "' + group_id + '")</script>'
            self.write(restr)
            return
示例#20
0
文件: AF_Group.py 项目: deju/afw_old
                else:
                    AFGroup = AFWBasicGroup(group)
                    AFObject = SuperArticle(AF_Object)
                    # get the want data
            except (ItemNotFoundError, InvalidIDError, DBIndexError, BaseDBError), e:
                logging.error(e.msg)
                logging.error('Url Error %s' % self.request.uri)
            except Exception, e:
                AFGroup = None
                logging.error(traceback.format_exc())
                logging.error('Url Error %s' % self.request.uri)

        elif article_type == 'doc':
            try:
                AF_Object = Blog(_id=article_id)
                group = BasicGroup(_id=AF_Object.group_id)
                if group.get_member_type(user) != 'Manager' or str(AF_Object.author_id) != str(user._id):
                    AFGroup = None
                else:
                    AFGroup = AFWBasicGroup(group)
                    AFObject = SuperArticle(AF_Object)
                    AFObject.tag_all = AF_Object.tag
            except (ItemNOtFoundError, InvalidIDError, DBIndexError, BaseDBError), e:
                logging.error(e.msg)
                logging.error('Url Error %s' % self.request.uri)
            except Exception, e:
                logging.error(traceback.format_exc())
                logging.error('Url Error %s' % self.request.uri)
                AFGroup = None
        elif article_type == 'notice':
            try:
示例#21
0
文件: AF_User.py 项目: deju/afw_old
class CropImageHandler(BaseHandler):
    @authfilter
    def post(self):
        result = {'kind': 1, 'info': ''}
        user = self.current_user
        crop_type = is_value(self.get_argument("crop_type", 'avatar'))
        if crop_type not in ['avatar', 'logo', 'article']:
            result['info'] = '不支持当前操作!'
            self.write(json_encode(result))
            return
        pos_x = is_value(self.get_argument("pos-x", None))
        pos_y = is_value(self.get_argument("pos-y", None))
        pos_w = is_value(self.get_argument("pos-w", None))
        pos_time = is_value(self.get_argument("pos-time", 1))
        #print '(x, y, w, pos_time):', pos_x, pos_y, pos_w , pos_time
        try:
            pos_x = int(pos_x)
            pos_y = int(pos_y)
            pos_w = int(pos_w)
            pos_time = float(pos_time)
        except Exception, e:
            result['info'] = '您设置的参数出错,请您确认您的参数!'
            self.write(json_encode(result))
            return
        if pos_w < 150:
            result['info'] = '您设置的参数出错,请您确认您的参数!'
            self.write(json_encode(result))
            return

        if crop_type == "avatar":
            # set user avatar
            user_avatar = (user.avatar).file_name
            #print 'path: ', user_avatar
            if user_avatar == '' or user_avatar is None:
                result['info'] = '您的头像未设置,请您先上传并设置头像!'
                self.write(json_encode(result))
                return
            image_name = urlparse.urlparse(user_avatar).path.split('/').pop()
            result['kind'], result['info'] = fun_save_thumb(image_name,
                                                            pos_x=pos_x,
                                                            pos_y=pos_y,
                                                            pos_w=pos_w,
                                                            pos_time=pos_time)
            self.write(json_encode(result))
            return
        elif crop_type == 'logo':
            # crop group logo
            group_id = is_value(self.get_argument("group_id", 1))
            try:
                tmp_group = BasicGroup(_id=group_id)
                if tmp_group.get_member_type(user) != 'Manager':
                    result['info'] = '您无权进行设置!'
                    self.write(result)
                    return
            except Exception, e:
                result['info'] = '参数错误!'
                self.write(result)
                return
            group_avatar = tmp_group.avatar.file_name
            if group_avatar == '' or group_avatar is None:
                result['info'] = '请您先上传小组的Logo'
                self.write(result)
                return
            image_name = urlparse.urlparse(group_avatar).path.split('/').pop()
            result['kind'], result['info'] = fun_save_thumb(
                image_name,
                pos_x=pos_x,
                pos_y=pos_y,
                pos_w=pos_w,
                pos_time=pos_time,
                normal_path=AFWConfig.afewords_image_path +
                "/static/logo/normal/",
                small_path=AFWConfig.afewords_image_path +
                "/static/logo/small/")
            self.write(json_encode(result))
            return
示例#22
0
文件: AF_User.py 项目: deju/afw_old
         result['info'] = '该用户不存在!'
         self.write(json_encode(result))
         return
     else:
         if do == "follow":
             user.follow_user(follower)
             result['kind'] = 0
         elif do == "unfollow":
             user.unfollow_user(follower)
             result['kind'] = 0
         self.write(json_encode(result))
         return
 else:
     # for group follow
     try:
         group = BasicGroup(_id=follow_id)
     except Exception, e:
         logging.error(traceback.format_exc())
         logging.error('Url Error %s' % self.request.uri)
         result['info'] = '无此小组!'
         self.write(json_encode(result))
         return
     else:
         if do == "follow":
             user.follow_group(group)
             result['kind'] = 0
         else:
             if group.get_member_type(user) == 'Manager':
                 result['info'] = '管理员无法退出!'
             else:
                 if str(group._id) != AFWConfig.afewords_group_id:
示例#23
0
     except Exception, e:
         logging.error(traceback.format_exc())
         logging.error('%s not exist, id %s' % (article_type, article_id))
         AF_Object = Blog()
         AF_Object.author = user
         AF_Object.env = user
         article_id = str(AF_Object._id)
         isnew = True       
         (user.drafts_lib).add_obj(AF_Object)     
 elif article_type == "comment":
     return [1, '完善中']
 elif article_type in Group_Article:
     # for group
     isnew = False
     try:
         group = BasicGroup(_id=group_id)
         limit = group.authority_verify(user)
     except Exception, e:
         logging.error(traceback.format_exc())
         logging.error('Group not exist, id %s' % group_id)
         return [1, '参数错误,小组不存在!']
     
     class_map = { 'group-info': About, 'group-doc': Blog, 'group-feedback': Feedback, 
         'group-notice': Bulletin, 'group-topic': Topic}
         
     user_role = group.get_member_type(user)
     if user_role is None:
         return [1, '您不是该小组成员!']
     if article_type in ['group-info', 'group-doc', 'group-notice']:
         if user_role != 'Manager':
             return [1, '您不是管理员,无权操作!']
示例#24
0
        except Exception, e:
            logging.error(traceback.format_exc())
            logging.error('%s not exist, id %s' % (article_type, article_id))
            AF_Object = Blog()
            AF_Object.author = user
            AF_Object.env = user
            article_id = str(AF_Object._id)
            isnew = True
            (user.drafts_lib).add_obj(AF_Object)
    elif article_type == "comment":
        return [1, '完善中']
    elif article_type in Group_Article:
        # for group
        isnew = False
        try:
            group = BasicGroup(_id=group_id)
            limit = group.authority_verify(user)
        except Exception, e:
            logging.error(traceback.format_exc())
            logging.error('Group not exist, id %s' % group_id)
            return [1, '参数错误,小组不存在!']

        class_map = {
            'group-info': About,
            'group-doc': Blog,
            'group-feedback': Feedback,
            'group-notice': Bulletin,
            'group-topic': Topic
        }

        user_role = group.get_member_type(user)
示例#25
0
def fun_update_comment(user, group_id='-1', article_id = 0, article_type='blog', title='', summary='', body='',
                     permission='public', keys=[], classes=[], father_id='-1', father_type='blog', do="post", ref_comments=''):
    # update comment, all comments 
    group = None
    if father_type == 'blog':
        try:
            AF_Object = Blog(_id=father_id)
        except Exception, e:
            return [1, '文章不存在!']
    else:
        # for group 
        if father_type == 'group-notice':
            try:
                AF_Object = Bulletin(_id=father_id)
                group = BasicGroup(_id=AF_Object.group_id)
                if group.get_member_type(user) is None:
                    return [1, '您不是该小组成员']
            except Exception, e:
                logging.error(traceback.format_exc())
                logging.error('%s not exist, id %s' %(father_type, father_id))
                return [1, '该公告不存在!']
        elif father_type == "group-doc":
            try:
                AF_Object = Blog(_id=father_id)
                group = BasicGroup(_id=AF_Object.group_id)
                if group.get_member_type(user) is None:
                    return [1, '您不是该小组成员']
            except Exception, e:
                logging.error(traceback.format_exc())
                logging.error('%s not exist, id %s' %(father_type, father_id))
示例#26
0
                    father_type='blog',
                    do="post",
                    ref_comments=''):
 # update comment, all comments
 group = None
 if father_type == 'blog':
     try:
         AF_Object = Blog(_id=father_id)
     except Exception, e:
         return [1, '文章不存在!']
 else:
     # for group
     if father_type == 'group-notice':
         try:
             AF_Object = Bulletin(_id=father_id)
             group = BasicGroup(_id=AF_Object.group_id)
             if group.get_member_type(user) is None:
                 return [1, '您不是该小组成员']
         except Exception, e:
             logging.error(traceback.format_exc())
             logging.error('%s not exist, id %s' % (father_type, father_id))
             return [1, '该公告不存在!']
     elif father_type == "group-doc":
         try:
             AF_Object = Blog(_id=father_id)
             group = BasicGroup(_id=AF_Object.group_id)
             if group.get_member_type(user) is None:
                 return [1, '您不是该小组成员']
         except Exception, e:
             logging.error(traceback.format_exc())
             logging.error('%s not exist, id %s' % (father_type, father_id))