Beispiel #1
0
def upload_file():
    is_login()
    if (request.args.get("page", '').strip()):
        page = int(request.args.get("page", '').strip())
    else:
        page = 1#如果没有指定就默认为第一页
        
    if request.method == 'POST':
        file = request.files['upfile']
        if allowed_file( file.filename ):
            tmp = str(random.randrange(0,9))#0-9是随机的目录
            filename = tmp+'/42ic.com-'+ str( int(time.time()) ) + "." + file.filename.rsplit( '.', 1 )[1]
            #存放原始文件
            file.save( os.path.join( app.config['UPFILE_PATH'], filename ) )
            filesize = os.path.getsize( app.config['UPFILE_PATH']+ filename)
            #如果是图片文件,就生成两组小图
            if file_is_img(file.filename):
                im = Image.open( app.config['UPFILE_PATH'] + "/" + filename ).convert("RGB")
                #大图也加一个水印
                im_artwork = im.copy()
                WriteText(im_artwork, 'www.42ic.com', os.path.join( app.config['UPFILE_PATH']+'artwork/', filename ))
                #生成2组小图并加水印
                i = Graphics(im, app.config['UPFILE_PATH'],filename);
                i.run_thumb_all([200,400],[540,1000]);
            a = Attachment( g.user.id, file.filename.rsplit( '.', 1 )[1],\
                 filesize, file.filename, filename)
            db.session.add( a )
            db.session.commit()
            flash(u"上传成功。", "success")
    file_list = Attachment.query.filter(Attachment.user_id==g.user.id).\
                order_by(Attachment.id.desc()).paginate(page, per_page=10)
    page_url = lambda page: '?page='+str(page)
    return render_template("upload.html",file_list=file_list,page_url=page_url)
Beispiel #2
0
def report_abuse(comment_id):
    is_login()
    comment = Comment.query.get_or_404(comment_id)
    form = CommentAbuseForm()
    if form.validate_on_submit():

        admins = current_app.config['ADMINS']

        if admins:

            body = render_template("emails/report_abuse.html",
                               comment=comment,
                               complaint=form.complaint.data)
            
            message = Message(subject="Report Abuse",
                              body=body,
                              sender=g.user.email,
                              recipients=admins)

            mail.send(message)
            
        flash(_("Your report has been sent to the admins"), "success")

        return redirect(comment.url)

    return render_template("comment/report_abuse.html",
                           comment=comment,
                           form=form)
Beispiel #3
0
def edit_group(slug):
    is_login()
    group = Group.query.urlname_get_info(slug)
    form = Group_EditForm(obj=group)
    #判断权限
    if group.leader_id != g.user.id:
        flash(u'对不起,您无权操作!', "error")
        return redirect(url_for("group.group_view",slug=slug))
    if form.validate_on_submit():
        form.populate_obj(group)
        try:
            file = request.files['group_icon']
        except:
            file = None        
        #获取图标文件
        if file:
            image_path = '/home/lyping/data/42ic/' + 'iapp/static/groupicon/image'
            icon_path = '/home/lyping/data/42ic/' + 'iapp/static/groupicon'
            ALLOWED_EXTENSIONS = set( ['bmp', 'png', 'jpg', 'jpeg', 'gif', 'BMP', 'PNG', 'JPG', 'JPEG', 'GIF'] )            
            #存储原文件
            filename = str( group.id ) + "-" + str( int(time.time()) ) + "." + file.filename.rsplit( '.', 1 )[1]
            file.save( os.path.join( image_path, filename ) )
            #产生缩略图
            import Image
            from iapp.utils.pic import picopen, pic_square
            iconname = str( group.id ) + "-"+ str( int(time.time()) ) + file.filename.rsplit( '.', 1 )[1]
            im = Image.open( image_path + "/" + filename )
            image2 = pic_square( im, 48 )
            image2.save( os.path.join( icon_path, filename ) )
            #存储图标名称
            group.group_icon_url = filename
        db.session.commit()
        flash(u'资料修改成功!', "success")
        return redirect(url_for("group.group_view",slug=slug))
    return render_template('group/edit_group.html', form = form,group=group)
Beispiel #4
0
def topic_reply(topic_id):
    is_login()
    topic = Group_Topic.query.get_or_404(topic_id)
    groupinfo = Group.query.id_get_info(topic.group_id)
    #检查是否有发言权限
    is_join = Group_User.query.is_join(groupinfo.id,g.user.id)
    if is_join is None:
        is_join = 0
    else:
        is_join = 1
    #如果还么有加入,是不能回复的
    if not is_join:
        flash(u'您还没有加入小组,无权发言!', "error")
        return redirect(url_for("group.group_view", slug=slug))
    
    form = Group_Topic_New_ReplyForm()
    if form.validate_on_submit():
        group_reply = Group_Reply()
        form.populate_obj(group_reply)
        group_reply.topic_id = topic_id
        db.session.add(group_reply)
        #话题回复次数更新
        group_topic = Group_Topic.query.get_or_404(topic_id)
        group_topic.num_comment = group_topic.num_comment + 1
        group_topic.date_last_response  = datetime.now()
        group_topic.sort  = int(time.time())#用于排序
        db.session.commit()
        flash(u'话题回复成功', "success")
        queue.push((502,g.user.id,topic_id,group_topic.title[0:30],group_reply.content[0:100]))
        queue.push((202,g.user.id,1))#回复主题增加1积分
        return redirect(url_for("group.topic_view", topic_id=topic_id))
    else:
        return redirect(url_for("group.topic_view", topic_id=topic_id))
Beispiel #5
0
def change_password():
    is_login()
    user = None
    if g.user:
        user = User.query.filter_by( id = g.user.id ).first()
    elif 'activation_key' in request.values:
        user = User.query.filter_by(
            activation_key=request.values['activation_key']).first()
    
    if user is None:
        abort(403)

    form = ChangePasswordForm(activation_key=user.activation_key)

    if form.validate_on_submit():

        user.password = form.password.data
        user.activation_key = None
        db.session.commit()
        #登出
        session.pop('user_id', None)

        flash(u"密码修改成功,请重新登录。", "success")
        #清除缓存
        cache.delete('session_login_uid_'+str(session['user_id']))         
        return redirect(url_for("account.login"))

    return render_template("account/change_password.html", form=form)
Beispiel #6
0
def user_icon():
    is_login()
    if request.method == 'POST':
        xyh = request.form['imgpos'].split('_')
        ed_icon = Users_icon.query.filter_by( uid = g.user.id ).first()
        ed_icon.x = x = int(xyh[0])
        ed_icon.y = y = int(xyh[1])
        ed_icon.h = h = int(xyh[2])
        db.session.commit()
        #处理图片并保存
        import Image
        im = Image.open( app.config['AVATAR_IMAGE_PATH'] + "/" + ed_icon.image_name )
        box = (x,y,x+h,y+h)
        #裁剪图片
        image = im.crop(box)
        #缩略图片
        image2 = pic_square( image, 48)
        del image
        tmp = str(random.randrange(0,9))
        filename = tmp+'/'+str( g.user.id ) + "-" + str( int(time.time()) ) + "." + ed_icon.image_name.rsplit( '.', 1 )[1]
        image2.save( os.path.join( app.config['AVATAR_PATH'], filename ) )
        #更新用户资料
        ed_user = User.query.filter_by( id = g.user.id ).first()
        ed_user.avatar = filename
        db.session.commit()
        flash(u"头像编辑成功。", "success")
        #清除缓存
        cache.delete('session_login_uid_'+str(session['user_id']))         
    d = {}
    ed_icon = Users_icon.query.filter_by( uid = g.user.id ).first()
    d['icon_image_url'] = "avatar/image/" + ed_icon.image_name
    d['icon_x'] = ed_icon.x
    d['icon_y'] = ed_icon.y
    d['icon_h'] = ed_icon.h
    return render_template( 'account/user_icon.html',**d)
Beispiel #7
0
def user_icon_up_file():
    is_login()
    file = request.files['picfile']
    if g.user and file and allowed_file( file.filename ):
        #user = session.query( Users_icon ).filter_by( uid = uid ).first()
        #0-9是随机的目录
        tmp = str(random.randrange(0,9))
        filename = tmp+'/'+str( g.user.id ) + "-" + str( int(time.time()) ) + "." + file.filename.rsplit( '.', 1 )[1]
        file.save( os.path.join( app.config['AVATAR_IMAGE_PATH'], filename ) )
        try:
            ed_icon = Users_icon.query.filter_by( uid = g.user.id ).first()
        except:
            ed_icon = Users_icon()
        ed_icon.image_name = filename
        import Image
        iconname = str( g.user.id ) + "-"+ str( int(time.time()) ) + file.filename.rsplit( '.', 1 )[1]
        im = Image.open( image_path + "/" + filename )
        image2 = pic_square( im, 48 )
        image2.save( os.path.join( app.config['AVATAR_PATH'], filename ) )
        ed_user = User.query.filter_by( id = g.user.id ).first()
        ed_user.avatar = filename
        db.session.commit()
        flash(u"图片上传成功,请编辑头像。", "success")
        #清除缓存
        cache.delete('session_login_uid_'+str(session['user_id']))         
    return redirect(url_for("account.user_icon") )
Beispiel #8
0
def make_the_right_answer(answer_id):
    is_login()
    #获取答案信息
    ed_answer = Answer.query.get_or_404(answer_id)
    question = Question.query.filter_by( id = ed_answer.question_id ).first()
    if question.author_id ==g.user.id or g.user.role>300:
        #检查是否已经有正确答案,
        if question.answer_id:
            flash(u'操作失败,一个问题只能有一个满意答案!', "error")
        else:
            #设置答案为满意答案
            this_answer = Answer.query.filter_by( id = answer_id ).first()
            #return str(this_answer)
            this_answer.answer_ok = 1
            #设置问题的满意答案ID
            question.answer_id = answer_id
            user = User.query.filter_by( id = ed_answer.author_id ).first()
            #答案作者威望+3
            user.prestige = user.prestige + 3
            #答案作者答案采纳数+1
            user.best_answer_number = user.best_answer_number + 1
            db.session.commit()
            queue.push((202,g.user.id,5))#找到正确增加5积分
            flash(u'恭喜您找到满意答案,问题状态已更新成功!', "success")
    else:
        flash(u'您没有权限操作!', "error")
    return redirect(url_for("question.view", question_id=ed_answer.question_id))
Beispiel #9
0
def send_message(user_id):
    is_login()
    user = User.query.get_or_404(user_id)
    user.permissions.send_message.test(403)

    form = MessageForm()

    if form.validate_on_submit():

        body = render_template("emails/send_message.html",
                               user=user,
                               subject=form.subject.data,
                               message=form.message.data)

        subject = _("your friend  %(name)s sent you a message", name=g.user.username)
        message = Message(subject=subject,
                          body=body,
                          recipients=[user.email])

        mail.send(message)

        flash(_("Your message has been sent to %(name)s", 
               name=user.username), "success")

        return redirect(url_for("user.posts", username=user.username))

    return render_template("user/send_message.html", user=user, form=form)
Beispiel #10
0
def group_trash(slug):
    is_login()
    groupinfo = Group.query.urlname_get_info(slug)
    #如果没有指定就默认为第一页
    action = request.args.get("action", '').strip()
    if action == 'restore':
        if groupinfo.leader_id == g.user.id or g.user.role >=300:
            id = int(request.args.get("id", '').strip())
            topic = Group_Topic.query.get_or_404(id)
            topic.deleteed = 0
            db.session.commit()
            flash(u'主题恢复成功', "success")
    if (request.args.get("page", '').strip()):
        page = int(request.args.get("page", '').strip())
    else:
        page = 1
    #判断是不是组长
    if groupinfo.leader_id == g.user.id:
        topic_list = Group_Topic.query.get_topic_trash_list(groupinfo.id).\
                 paginate(page, per_page=30)
    else:
        topic_list = Group_Topic.query.get_my_topic_trash_list(groupinfo.id,g.user.id).\
            paginate(page, per_page=30)
   
    page_url = lambda page: '?page='+str(page)

    return render_template( 'group/group_trash.html',groupinfo=groupinfo,\
         topic_list=topic_list, page_url=page_url)
Beispiel #11
0
def delete(post_id):
    is_login()
    post = Post.query.get_or_404(post_id)
    post.permissions.delete.test(403)
    
    Comment.query.filter_by(post=post).delete()

    db.session.delete(post)
    db.session.commit()

    if g.user.id != post.author_id:
        body = render_template("emails/post_deleted.html",
                               post=post)

        message = Message(subject="Your post has been deleted",
                          body=body,
                          recipients=[post.author.email])

        mail.send(message)

        flash(_("The post has been deleted"), "success")
    
    else:
        flash(_("Your post has been deleted"), "success")

    return jsonify(success=True,
                   redirect_url=url_for('frontend.index'))
Beispiel #12
0
def edit(post_id):
    is_login()
    post = Post.query.get_or_404(post_id)
    post.permissions.edit.test(403)
    
    form = PostForm(obj=post)
    if form.validate_on_submit():

        form.populate_obj(post)
        db.session.commit()

        if g.user.id != post.author_id:
            body = render_template("emails/post_edited.html",
                                   post=post)

            message = Message(subject="Your post has been edited",
                              body=body,
                              recipients=[post.author.email])

            mail.send(message)

            flash(_("The post has been updated"), "success")
        
        else:
            flash(_("Your post has been updated"), "success")
        return redirect(url_for("post.view", post_id=post_id))

    return render_template("post/edit_post.html", 
                           post=post, 
                           form=form)
Beispiel #13
0
def download_file(aid):
    is_login()
    a = Attachment.query.get_or_404(aid)
    #下载计数统计
    a.num_down = a.num_down + 1
    db.session.commit()
    #返回文件URL
    return redirect(app.config['UPFILE_URL']+a.file_new_name)
Beispiel #14
0
def new_group():
    is_login()
    form = Group_RequisitionForm()
    if form.validate_on_submit():
        group_requisition = Group_Requisition()
        form.populate_obj(group_requisition)
        db.session.add(group_requisition)
        db.session.commit()
        flash(u'申请提交成功,审核通过后会站内信息通知您', "success")
        return redirect(url_for("group.index"))
    return render_template('group/new_group.html', form = form)
Beispiel #15
0
def delete(comment_id):
    is_login()
    comment = Comment.query.get_or_404(comment_id)
    comment.permissions.delete.test(403)

    db.session.delete(comment)
    db.session.commit()

    signals.comment_deleted.send(comment.post)

    return jsonify(success=True,
                   comment_id=comment_id)
Beispiel #16
0
def namecard():
    is_login()
    form = EditNameCardForm(g.user)

    if form.validate_on_submit():
        userinfo = User.query.filter_by( id = g.user.id ).first()
        form.populate_obj(userinfo)
        db.session.commit()
        flash(u'资料已经更新', "success")
        #清除缓存
        cache.delete('session_login_uid_'+str(session['user_id']))         
        return redirect(url_for("account.namecard"))
    return render_template("account/edit_namecard.html", form=form)
Beispiel #17
0
def topic_delete(topic_id):
    is_login()
    topic = Group_Topic.query.get_or_404(topic_id)
    groupinfo = Group.query.id_get_info(topic.group_id)
    #只有作者本人或组长才能删除
    if topic.author_id == g.user.id or groupinfo.leader_id == g.user.id:
        topic.deleteed = 1
        db.session.commit()
        flash(u'删除话题成功', "success")
        return redirect(url_for("group.group_view", slug=groupinfo.url_name))
    else:
        flash(u'无权操作!', "error")
        return redirect(url_for("group.topic_view", topic_id=topic_id))
Beispiel #18
0
def ask(slug=u''):
    is_login()
    form = Question_AskForm()
    if form.validate_on_submit():
        question = Question()
        form.populate_obj(question)
        question.ip = request.remote_addr
        db.session.add(question)
        db.session.commit()
        flash(u'问题发布成功', "success")
        queue.push((301,g.user.id,question.id,question.title,question.description[0:100]))#发任务
        queue.push((202,g.user.id,2))#提问增加2积分
        return redirect(url_for("question.view", question_id=question.id))
    return render_template( 'question/ask.html', form=form, title=slug)
Beispiel #19
0
def add_comment(post_id, parent_id=None):
    is_login()
    post = Post.query.get_or_404(post_id)
    post.permissions.view.test(403)

    parent = Comment.query.get_or_404(parent_id) if parent_id else None
    
    form = CommentForm()

    if form.validate_on_submit():
        comment = Comment(post=post,
                          parent=parent,
                          author=g.user)
        
        form.populate_obj(comment)

        db.session.add(comment)
        db.session.commit()

        signals.comment_added.send(post)

        flash(_("Thanks for your comment"), "success")

        author = parent.author if parent else post.author

        if author.email_alerts and author.id != g.user.id:
            
            subject = _("Somebody replied to your comment") if parent else \
                      _("Somebody commented on your post")

            template = "emails/comment_replied.html" if parent else \
                       "emails/post_commented.html"

            body = render_template(template,
                                   author=author,
                                   post=post,
                                   parent=parent,
                                   comment=comment)

            mail.send_message(subject=subject,
                              body=body,
                              recipients=[post.author.email])


        return redirect(comment.url)
    
    return render_template("post/add_comment.html",
                           parent=parent,
                           post=post,
                           form=form)
Beispiel #20
0
def edit(question_id):
    is_login()
    ed_question = Question.query.get_or_404(question_id)
    #需要权限大于等于200或本人才能修改问题
    if not ((g.user.role >= 200) or (g.user.id == ed_question.author_id)) :
        flash(u'您没有权限编辑问题', "error")
        return redirect(url_for("question.view", question_id=question_id))
    form = Question_EditForm(obj=ed_question)
    if form.validate_on_submit():
        form.populate_obj(ed_question)
        db.session.commit()
        #cache.delete(url_for("question.view", question_id=question_id))
        flash(u'问题保存成功', "success")
        return redirect(url_for("question.view", question_id=question_id))
    return render_template( 'question/edit.html', form =form,question = ed_question)
Beispiel #21
0
def my_topics():
    is_login()
    #如果没有指定就默认为第一页
    if (request.args.get("page", '').strip()):
        page = int(request.args.get("page", '').strip())
    else:
        page = 1
    page_url = lambda page: '?page='+str(page)

    topic_list = Group_Topic.query.get_my_topics_list(g.user.id).\
        paginate(page, per_page=30)
    #我加入的小组(近9)
    my_join_group = Group_User.query.my_join_group(g.user.id)
    return render_template( 'group/my_topics.html',\
            topic_list=topic_list, page_url=page_url,my_join_group=my_join_group)
Beispiel #22
0
def group_join(slug):
    is_login()
    groupinfo = Group.query.urlname_get_info(slug)
    is_join = Group_User.query.is_join(groupinfo.id,g.user.id)
    if not is_join:
        group_user = Group_User(groupinfo.id,g.user.id)
        db.session.add(group_user)
        #小组成员人数+1
        groupinfo.num_members = groupinfo.num_members + 1
        db.session.commit()
        queue.push((503,g.user.id,groupinfo.id,groupinfo.url_name,groupinfo.name[0:30],groupinfo.description[0:100]))
        flash(u'成功加入小组', "success")
    else:
        flash(u'已经加入了这个小组', "error")
    return redirect(url_for("group.group_view", slug=groupinfo.url_name))
Beispiel #23
0
def edit_answer(answer_id):
    is_login()
    ed_answer = Answer.query.get_or_404(answer_id)
    ed_question = Question.query.get_or_404(ed_answer.question_id)
    #需要权限大于等于200或本人才能修改问题
    if not ((g.user.role >= 200) or (g.user.id == ed_answer.author_id)) :
        flash(u'您没有权限编辑这个答案', "error")
        return redirect(url_for("question.view", ed_answer.question_id))
    form = Answer_EditForm(obj=ed_answer)
    if form.validate_on_submit():
        form.populate_obj(ed_answer)
        db.session.commit()
        flash(u'这个答案保存成功', "success")
        queue.push((202,g.user.id,1))#编辑问题增加1积分
        return redirect(url_for("question.view", question_id=ed_answer.question_id))
    return render_template( 'question/edit_answer.html', form =form,question = ed_question,answer=ed_answer)
Beispiel #24
0
def topic_reply_delete(reply_id):
    is_login()
    reply = Group_Reply.query.get_or_404(reply_id)
    topic = Group_Topic.query.get_or_404(reply.topic_id)
    groupinfo = Group.query.id_get_info(topic.group_id)
    #只有作者本人或组长才能删除
    if topic.author_id == g.user.id or groupinfo.leader_id == g.user.id\
        or reply.author_id == g.user.id or g.user.role >=300:
        reply.deleteed = 1
        topic.num_comment = topic.num_comment - 1
        db.session.commit()
        flash(u'删除回复成功', "success")
        return redirect(url_for("group.topic_view", topic_id=reply.topic_id))
    else:
        flash(u'无权操作!', "error")
        return redirect(url_for("group.topic_view", topic_id=reply.topic_id))
Beispiel #25
0
def topic_edit(topic_id):
    is_login()
    topic = Group_Topic.query.get_or_404(topic_id)
    groupinfo = Group.query.id_get_info(topic.group_id)
    #只有小组管理员或作者有权限修改
    if groupinfo.leader_id == g.user.id or topic.author_id == g.user.id:
        pass
    else:
        flash(u'无权操作!', "error")
        return redirect(url_for("group.topic_view",topic_id=topic_id))
    form = Group_Edit_TopicForm(obj=topic)
    if form.validate_on_submit():
        form.populate_obj(topic)
        db.session.commit()
        flash(u'修改成功!', "success")
        return redirect(url_for("group.topic_view",topic_id=topic_id))
    return render_template('group/edit_topic.html', form = form,topic=topic)
Beispiel #26
0
def group_quit(slug):
    is_login()
    groupinfo = Group.query.urlname_get_info(slug)
    #组长不能退出本组
    if groupinfo.leader_id == g.user.id:
        flash(u'组长不能提前退出小组哦!', "error")
        return redirect(url_for("group.group_view", slug=groupinfo.url_name))
    is_join = Group_User.query.is_join(groupinfo.id,g.user.id)
    if is_join:
        Group_User.query.filter( Group_User.user_id == g.user.id ).\
            filter( Group_User.group_id == groupinfo.id ).delete()
        #小组成员人数-1
        groupinfo.num_members = groupinfo.num_members - 1
        db.session.commit()
        flash(u'成功退出小组', "success")
    else:
        flash(u'您还不是小组成员呢', "error")
    return redirect(url_for("group.group_view", slug=groupinfo.url_name))
Beispiel #27
0
def thankhim(answer_id):
    is_login()
    #获取答案信息
    ed_answer = Answer.query.get_or_404(answer_id)
    if ed_answer.author_id ==g.user.id:
        return jsonify(status =0,value = u'不能感谢自己')
    else:
        athink = Answer_Thank.query.filter(Answer_Thank.answer_id==answer_id).filter(Answer_Thank.user_id==g.user.id).first()
        if athink:
            return jsonify(status = 0,value = u'已经感谢过了')
        else:
            athink = Answer_Thank(g.user.id,answer_id)
            db.session.add(athink)
            user = User.query.filter_by( id = ed_answer.author_id ).first()
            #答案作者威望+1
            user.prestige = user.prestige + 1
            db.session.commit()
            return jsonify(status = 1,value = u'操作成功!')
Beispiel #28
0
def edit(comment_id):
    is_login()
    comment = Comment.query.get_or_404(comment_id)
    comment.permissions.edit.test(403)

    form = CommentForm(obj=comment)

    if form.validate_on_submit():
        
        form.populate_obj(comment)

        db.session.commit()

        flash(_("Your comment has been updated"), "success")

        return redirect(comment.url)
    
    return render_template("comment/edit_comment.html",
                           comment=comment,
                           form=form)
Beispiel #29
0
def new_answer(question_id):
    is_login()
    ed_question = Question.query.get_or_404(question_id)
    if request.method == 'POST' and request.form['answer']:
        if ed_question.author_id == g.user.id:
            flash(u'自己不能回答自己问题的哦,有问题可以追问或编辑!', "error")
        else:
            ed_question = Question.query.get_or_404(question_id)
            ed_answer = Answer()
            ed_answer.answer = request.form['answer']
            ed_answer.ip = request.remote_addr
            ed_answer.question_id = question_id
            db.session.add( ed_answer )
            ed_question.num_answer = ed_question.num_answer + 1
            db.session.commit()
            flash(u'您的答案已经提交成功!', "success")
            #消息队列
            queue.push((302,g.user.id,ed_question.id,ed_question.title,ed_answer.answer[0:100]))
            queue.push((202,g.user.id,3))#回答问题增加3积分
            #cache.delete(url_for("question.view", question_id=question_id))
    return redirect(url_for("question.view", question_id=question_id))
Beispiel #30
0
def new_topic(slug):
    is_login()
    groupinfo = Group.query.urlname_get_info(slug)
    is_join = Group_User.query.is_join(groupinfo.id,g.user.id)
    if is_join is None:
        flash(u'您还没有加入小组,无权发言!', "error")
        return redirect(url_for("group.group_view", slug=slug))
    else:
        form = Group_New_TopicForm()
        if form.validate_on_submit():
                group_topic = Group_Topic()
                form.populate_obj(group_topic)
                group_topic.group_id = groupinfo.id
                group_topic.ip = request.remote_addr
                db.session.add(group_topic)
                db.session.commit()
                flash(u'话题发布成功', "success")
                queue.push((501,g.user.id,group_topic.id,group_topic.title[0:30],group_topic.description[0:100]))
                queue.push((202,g.user.id,2))#新建主题增加2积分
                return redirect(url_for("group.topic_view", topic_id=group_topic.id))
        return render_template( 'group/new_topic.html',groupinfo=groupinfo,\
                form=form)