Beispiel #1
0
 def get_suggestion_content(request):
     suggestid = request.get('suggestid', -1)
     suggestion = suggest_model.find_by_id(suggestid)
     if suggestion:
         return ERROR.success(suggestion.to_json(columns = ['content']))
     else:
         return ERROR.SUGGESTION_NOT_FOUND
Beispiel #2
0
 def query_class(request):
     classid = request.get('classid', -1)
     _class = class_model.find_by_id(classid)
     if _class:
         return ERROR.success(_class.to_json())
     else:
         return ERROR.ISSUE_NOT_FOUND
Beispiel #3
0
 def query_question(request):
     questionid = request.get('questionid', '')
     question = question_model.find_by_id(questionid)
     if question:
         return ERROR.success(question.to_json())
     else:
         return ERROR.QUESTION_NOT_FOUND
Beispiel #4
0
    def query_chatroom(request):
        userid = request.get('userid', -1)
        chatid = request.get('chatid', -1)

        chatroom = chatroom_model.find_by_id(chatid)
        if chatroom:
            chatroom_all_users = {}
            for user in chatroom.get_users():
                chatroom_all_users[user.id] = user.to_json(
                    columns=['id', 'username', 'head'])

            if userid in chatroom_all_users:
                # 更新访问时间
                chatroom_record_model.visit_chatroom(userid, chatid)

                msgs = {
                    'messages':
                    [message.to_json() for message in chatroom.messages]
                }
                for msg in msgs['messages']:
                    msg.update(chatroom_all_users.get(msg['send_userid'], {}))
                return ERROR.success(msgs)
            return ERROR.PERMISSION_DENIED
        else:
            return ERROR.CHAT_NOT_FOUND
Beispiel #5
0
 def query_issue(request):
     issueid = request.get('issueid', -1)
     issue = issue_model.find_by_id(issueid)
     if issue:
         return ERROR.success(issue.to_json())
     else:
         return ERROR.ISSUE_NOT_FOUND
Beispiel #6
0
 def get_issue_content(request):
     issueid = request.get('issueid', -1)
     issue = issue_model.find_by_id(issueid)
     if issue:
         return ERROR.success(issue.to_json(columns = ['files']))
     else:
         return ERROR.ISSUE_NOT_FOUND
Beispiel #7
0
 def search_question(request):
     keyword = request.get('keyword', '')
     questions = question_model.query.filter( or_(
                                 question_model.title.like('%' + keyword + '%'),
                                 question_model.content.like('%' + keyword + '%')
                                 )).all()
     return ERROR.success({'questions': [question.to_json() for question in questions]})
Beispiel #8
0
 def getinfo(userid):
     user = user_model.find_by_id(userid)
     return ERROR.success(
         user.to_json(columns=[
             'id', 'username', 'head', 'phone', 'email', 'realname',
             'teaching_address', 'major', 'introduction', 'wechat',
             'additional_server', 'level', 'create_time'
         ]))
Beispiel #9
0
 def query_user_issues(userid):
     user = user_model.find_by_id(userid)
     return ERROR.success({
         'issues': [
             issue.to_json(columns=['type', 'comment', 'status'])
             for issue in user.issues
         ]
     })
Beispiel #10
0
 def get_user_info(request):
     userid = request.get('userid', -1)
     user = user_model.find_by_id(userid)
     if user:
         return ERROR.success(user.to_json(columns = ['id', 'username', 'head', 'phone', 'email',
                                                      'realname', 'teaching_address', 'major', 'introduction',
                                                      'wechat', 'additional_server', 'level', 'create_time']))
     else:
         return ERROR.USER_NOT_FOUND
Beispiel #11
0
    def query_suggestion(request):
        userid = request.get('userid', -1)
        suggestid = request.get('suggestid', -1)

        suggestion = suggest_model.find_by_id(suggestid)
        if suggestion:
            if suggestion.userid == userid:
                return ERROR.success(suggestion.to_json())
            return ERROR.PERMISSION_DENIED
        return ERROR.SUGGESTION_NOT_FOUND
Beispiel #12
0
 def add_staff(request):
     name = request.get('name', '')
     email = request.get('email', '')
     if name and email:
         new_staff =  staff_model(name, email)
         db.session.add(new_staff)
         db.session.commit()
         return ERROR.success(new_staff.to_json())
     else:
         return ERROR.REQUEST_INVALID
Beispiel #13
0
 def create_question(request):
     title = request.get('title', '')
     content = request.get('content', '')
     if content:
         newquestion = question_model(title, content)
         db.session.add(newquestion)
         db.session.commit()
         return ERROR.success(newquestion.to_json())
     else:
         return ERROR.REQUEST_INVALID
Beispiel #14
0
    def create_suggest(request):
        userid = request.get('userid', -1)
        title = request.get('title', '')
        content = request.get('content', '')
        if title and content:
            newsuggest = suggest_model(userid, title, content)
            db.session.add(newsuggest)
            db.session.commit()

            user_model.send_mail_by_userid(userid, "建议收到通知",
                                           "学生会已收到您的建议,会尽快进行处理!")
            return ERROR.success(newsuggest.to_json())
        return ERROR.REQUEST_INVALID
Beispiel #15
0
    def create_issue(request):
        userid = request.get('userid', -1)
        type = request.get('type', '')
        files = request.get('files', '')
        if type and files:
            newissue = issue_model(userid, type, files)
            db.session.add(newissue)
            db.session.commit()

            user_model.send_mail_by_userid(userid, "认证进度通知",
                                           "管理员已收到您的认证信息请求,会尽快进行处理!")
            user_model.send_mail_to_admin('认证审核通知', '认证待审核!')
            return ERROR.success(newissue.to_json())
        return ERROR.REQUEST_INVALID
Beispiel #16
0
    def create_chatroom(request):
        userid = request.get('userid', -1)
        invited_userid = request.get('invited_userid', -1)

        user = user_model.find_by_id(userid)
        invited_user = user_model.find_by_id(invited_userid)
        if invited_user:
            new_chatroom = chatroom_model()
            db.session.add(new_chatroom)
            db.session.commit()
            chatroom_record_model.create_chatroom_record(
                userid, invited_userid, new_chatroom.id)

            return ERROR.success(new_chatroom.to_json())
        else:
            return ERROR.USER_NOT_FOUND
Beispiel #17
0
    def get_user_msgs(userid):
        user = user_model.find_by_id(userid)
        chats = {"chats": []}

        for chatroom_record in user.chatroom_records:
            last_visit_time = chatroom_record.last_visit_time
            chatroom = chatroom_record.chatroom
            room = {"chatroom": chatroom.to_json()}

            new_msg_num = chatroom.messages.filter(
                message_model.send_time > last_visit_time).count()
            room.update({"new_num": new_msg_num})

            for user in chatroom.get_users():
                if user.id != userid:
                    room.update({"name": user.username, "head": user.head})

            chats['chats'].append(room)
        return ERROR.success(chats)
Beispiel #18
0
    def create_class(request):
        userid = request.get('userid', -1)
        name = request.get('name', '')
        type = request.get('type', -1)
        rank = request.get('rank', -1)
        teaching_type = request.get('teaching_type', '')
        teaching_address = request.get('teaching_address', '')
        price = request.get('price', -1)
        discount = request.get('discount', -1)
        class_count = request.get('class_count', 16)
        content = request.get('content', '')
        files = request.get('files', [])
        introduction = request.get('introduction', '')

        if name:
            newclass = class_model(userid, name, type, rank, teaching_type, teaching_address, price, discount, class_count, content, files, introduction)
            db.session.add(newclass)
            db.session.commit()
            user_model.send_mail_by_userid(userid, '开设课程通知', '开设课程待审核!')
            user_model.send_mail_to_admin('开课审核通知', '新开课程 %s 待审核!' % name)

            return ERROR.success(newclass.to_json())
        return ERROR.REQUEST_INVALID
Beispiel #19
0
 def get_all_questions():
     return ERROR.success({'questions': [question.to_json() for question in question_model.query.all()]})
Beispiel #20
0
 def get_staffs():
     return ERROR.success({'staffs': [staff.to_json(columns=['id', 'name', 'email']) for staff in staff_model.query.all()]})
Beispiel #21
0
 def get_all_classes():
     return ERROR.success({'classes': [_class.to_json(columns=['id', 'userid', 'name', 'status']) for _class in class_model.query.all()]})
Beispiel #22
0
 def get_all_issues():
     return ERROR.success({'issues': [issue.to_json(columns=['id', 'userid', 'type', 'status']) for issue in issue_model.query.all()]})
Beispiel #23
0
 def get_all_suggestions():
     return ERROR.success({'suggestions': [suggest.to_json(columns=['id', 'title', 'status']) for suggest in suggest_model.query.all()]})
Beispiel #24
0
 def query_user_classes(userid):
     user = user_model.find_by_id(userid)
     return ERROR.success({'classes': [_class.to_json() for _class in user.classes]})
Beispiel #25
0
 def query_user_suggestions(userid):
     user = user_model.find_by_id(userid)
     return ERROR.success({
         'suggestions':
         [suggestion.to_json() for suggestion in user.suggestions]
     })