コード例 #1
0
ファイル: CourseAsk.py プロジェクト: lanway/shacus_app
    def post(self):
        u_id = self.get_argument('uid')
        u_authkey = self.get_argument('authkey')
        ufuncs = Ufuncs.Ufuncs()
        if ufuncs.judge_user_valid(u_id, u_authkey):
            type = self.get_argument('type')

            if type == '11002':  #请求教程的详细信息
                c_id = self.get_argument('cid')
                tags = []
                ret_content = {}
                try:
                    self.db.query(Course).filter(Course.Cid == c_id,
                                                 Course.Cvalid == 1).one()
                    try:
                        exist = self.db.query(Usercourse).filter(
                            Usercourse.UCcid == c_id,
                            Usercourse.UCuid == u_id).one()  #判断是否曾经看过此教程
                        if exist.UCseen == 0:
                            exist.UCseen = 1
                            self.db.commit()
                    except Exception, e:
                        entry = Usercourse(UCuid=u_id,
                                           UCcid=c_id,
                                           UCseen=1,
                                           UCfav=0)
                        self.db.merge(entry)
                        self.db.commit()

                    course = self.db.query(Course).filter(
                        Course.Cid == c_id).one()
                    entrys = self.db.query(CourseTagEntry).filter(
                        CourseTagEntry.CTEcid == c_id,
                        CourseTagEntry.CTEvalid == 1).all()  #查询教程的标签
                    for entry in entrys:
                        tag_info = self.db.query(CourseTag).filter(
                            CourseTag.CTid == entry.CTEtid).one()
                        tags.append(tag_info.CTname)
                    ret_content[
                        'course'] = Coursemodel.Coursemodel.Course_Model_Complete(
                            course, tags)  #将浏览人数加一
                    course.CwatchN += 1
                    course.Cscore += 1
                    self.db.commit()
                    try:
                        self.db.query(CourseLike).filter(
                            CourseLike.CLcid == c_id, CourseLike.CLuid == u_id,
                            CourseLike.CLvalid == 1).one()  #查询是否关注过该教程
                        ret_content['isliked'] = 1
                    except Exception, e:
                        ret_content['isliked'] = 0

                    self.retjson['code'] = '11021'
                    self.retjson['contents'] = ret_content
                except Exception, e:
                    self.retjson['code'] = '11022'
                    self.retjson['contents'] = '该教程无效'
コード例 #2
0
    def post(self):
        ret_contents = {}
        ret_course = []
        ret_tag = []
        u_id = self.get_argument('uid')
        u_authkey = self.get_argument('authkey')
        ufuncs = Ufuncs.Ufuncs()
        if ufuncs.judge_user_valid(u_id, u_authkey):
            type = self.get_argument('type')
            if type == '11001':  #查看教程首页
                try:
                    courses = self.db.query(Course).filter(
                        Course.Cvalid == 1).order_by(desc(
                            Course.Cscore)).limit(3).all()  #通过score查出前三推荐给用户
                except Exception, e:
                    print e
                for course in courses:
                    ret_course.append(
                        Coursemodel.Course_Model_Simply_Homepage(course))
                tags = self.db.query(CourseTag).all()
                for tag in tags:
                    ret_tag.append(Coursemodel.CourseTag_Model(tag))
                ret_contents['tag'] = ret_tag
                ret_contents['course'] = ret_course
                self.retjson['contents'] = ret_contents
                self.retjson['code'] = '11010'

            if type == '11101':  #教程首页点击more
                like = 0
                courses = self.db.query(Course).order_by(desc(
                    Course.Cscore)).all()
                for course in courses:
                    u_cid = course.Cid
                    course = self.db.query(Course).filter(
                        Course.Cid == u_cid).one()
                    try:
                        self.db.query(CourseLike).filter(
                            CourseLike.CLcid == u_cid,
                            CourseLike.CLuid == u_id,
                            CourseLike.CLvalid == 1).one()
                        like = 1
                    except Exception, e:
                        like = 0
                        print e
                    try:
                        u_ucourse = self.db.query(Usercourse).filter(
                            Usercourse.UCuid == u_id,
                            Usercourse.UCcid == u_cid).one()
                        ret_course.append(
                            Coursemodel.Course_Model_Simply(
                                course, like, int(u_ucourse.UCfav),
                                int(u_ucourse.UCseen)))
                    except Exception, e:
                        ret_course.append(
                            Coursemodel.Course_Model_Simply(
                                course, like, 0, 0))
コード例 #3
0
 def post(self):
     u_id = self.get_argument('uid')
     u_authkey = self.get_argument('authkey')
     ufuncs = Ufuncs.Ufuncs()
     if ufuncs.judge_user_valid(u_id, u_authkey):
         type = self.get_argument('type')
         c_id = self.get_argument('cid')
         c_exist = self.db.query(Course).filter(Course.Cid == c_id).one()
         if c_exist.Cvalid == 1:  #该教程仍然有效
             try:
                 exist = self.db.query(CourseLike).filter(
                     CourseLike.CLcid == c_id,
                     CourseLike.CLuid == u_id).one()
                 if exist.CLvalid == 1:
                     if type == '11003':  #点赞时已经点过了
                         self.retjson['code'] = '11031'
                         self.retjson['contents'] = '你已经对此活动点过赞了'
                     if type == '11004':  #取消赞时点过赞了
                         exist.CLvalid = 0
                         self.retjson['code'] = '11041'
                         self.retjson['contents'] = '取消赞成功'
                         self.db.query(Course).filter(Course.Cid == c_id). \
                             update({Course.ClikeN: Course.ClikeN - 1,Course.Cscore :Course.Cscore-5}, synchronize_session=False)
                         self.db.commit()
                 else:
                     if type == '11003':  #点赞时已经取消赞
                         exist.CLvalid = 1
                         self.retjson['code'] = '11032'
                         self.retjson['contents'] = '成功点赞'
                         self.db.query(Course).filter(Course.Cid == c_id). \
                             update({Course.ClikeN: Course.ClikeN + 1,Course.Cscore :Course.Cscore+5}, synchronize_session=False)
                         self.db.commit()
                     if type == '11004':  #取消时已取消赞
                         self.retjson['code'] = '11042'
                         self.retjson['contents'] = '你已经对此活动取消过赞了'
             except Exception, e:
                 print e
                 if type == '11003':  #点赞时从未点过
                     entry = CourseLike(CLcid=c_id, CLuid=u_id, CLvalid=1)
                     self.db.merge(entry)
                     self.retjson['code'] = '11032'
                     self.retjson['contents'] = '成功点赞'
                     self.db.query(Course).filter(Course.Cid == c_id). \
                         update({Course.ClikeN: Course.ClikeN + 1,Course.Cscore :Course.Cscore+5}, synchronize_session=False)
                     self.db.commit()
                 if type == '11004':  #取消赞时从未点赞过
                     self.retjson['code'] = '11043'
                     self.retjson['contents'] = '你从来没有赞过这个教程'
         else:
             self.retjson['code'] = '11033'
             self.retjson['contents'] = '该教程已经失效'
コード例 #4
0
                self.retjson['code'] = '10509'
                self.retjson['contents'] = '修改邮箱成功'
            except Exception, e:
                print e
                self.retjson['code'] = '10510'
                self.retjson['contents'] = '修改邮箱失败'

        #修改头像,第一次存储图片,返回token
        elif type == '10513':

            #todo:第一二次握手之间应该加一个验证码

            u_id = self.get_argument('uid')
            u_authkey = self.get_argument('authkey')
            image = self.get_argument('image')
            ufuncs = Ufuncs.Ufuncs()
            if ufuncs.judge_user_valid(u_id, u_authkey):
                retjson_body = {'image_token': ''}
                image_token_handler = AuthKeyHandler()
                m_image_json = json.loads(image)
                self.retjson['contents'] = image_token_handler.generateToken(
                    m_image_json)
                self.retjson['code'] = '10515'
            else:
                self.retjson['contents'] = '用户授权码不正确'
                self.retjson['code'] = '10514'
        elif type == '10516':
            u_id = self.get_argument('uid')
            u_authkey = self.get_argument('authkey')
            image = self.get_argument('image')
            ufuncs = Ufuncs.Ufuncs()
コード例 #5
0
    def post(self):
        u_id = self.get_argument('uid')
        u_authkey = self.get_argument('authkey')
        c_id = self.get_argument('cid')
        ufuncs = Ufuncs.Ufuncs()
        type = self.get_argument('type')
        if ufuncs.judge_user_valid(u_id, u_authkey):
            try:
                self.db.query(Course).filter(Course.Cid == c_id,
                                             Course.Cvalid == 1).one()
                try:
                    exist = self.db.query(Usercourse).filter(
                        Usercourse.UCuid == u_id,
                        Usercourse.UCcid == c_id).one()
                    if type == '11008':  #用户收藏教程
                        if exist.UCfav == 1:  #用户收藏过此教程
                            self.retjson['contents'] = '你已经收藏过次教程'
                            self.retjson['code'] = '11084'
                        else:  #用户没有收藏过此教程
                            exist.UCfav = 1
                            self.db.query(Course).filter(Course.Cid == c_id). \
                                update({Course.CfavN: Course.CfavN + 1,Course.Cscore :Course.Cscore+10}, synchronize_session=False)
                            try:
                                self.db.commit()
                                self.retjson['contents'] = '收藏教程成功'
                                self.retjson['code'] = '11083'
                            except Exception, e:
                                self.retjson['contents'] = '服务器出错'
                                self.retjson['code'] = '11082'
                    if type == '11009':  #用户取消收藏教程
                        if exist.UCfav == 1:  #用户取消收藏教程
                            exist.UCfav = 0
                            self.db.query(Course).filter(Course.Cid == c_id). \
                                update({Course.CfavN: Course.CfavN - 1,Course.Cscore :Course.Cscore-10}, synchronize_session=False)
                            try:
                                self.db.commit()
                                self.retjson['contents'] = '取消收藏教程成功'
                                self.retjson['code'] = '11092'
                            except Exception, e:
                                self.retjson['contents'] = '服务器出错'
                                self.retjson['code'] = '11082'
                        else:  #用户已经取消收藏此教程
                            self.retjson['contents'] = '你已经取消收藏过次教程'
                            self.retjson['code'] = '11093'

                except Exception, e:
                    if type == '11008':  #用户从来没有对此教程进行过任何的操作
                        usercourse = Usercourse(UCuid=u_id,
                                                UCcid=c_id,
                                                UCseen=0,
                                                UCfav=1)
                        self.db.merge(usercourse)
                        self.db.query(Course).filter(Course.Cid == c_id).\
                            update({Course.CfavN: Course.CfavN+1,Course.Cscore :Course.Cscore+10},synchronize_session=False)
                        try:
                            self.db.commit()
                            self.retjson['contents'] = '收藏教程成功'
                            self.retjson['code'] = '11083'
                        except Exception, e:
                            self.db.rollback()
                            self.retjson['contents'] = '服务器出错'
                            self.retjson['code'] = '11082'
                    if type == '11009':  #用户对该教程没有进行过任何的操作却要取消收藏
                        self.retjson['contents'] = '你没有收藏过次教程'
                        self.retjson['code'] = '11091'
コード例 #6
0
    def post(self):
        ret_contents = {}
        ret_activity = []
        ret_e_appointment = []
        ret_my_appointment = []
        ac = ACmodelHandler()
        ap = APmodelHandler()
        type = self.get_argument('type')
        u_id = self.get_argument('uid')
        auth_key = self.get_argument('authkey')
        ufuncs = Ufuncs.Ufuncs()
        if ufuncs.judge_user_valid(u_id, auth_key):
            if type == '10901':  # 查看我的已报名的约拍活动
                ret_activity = self.get_activity(u_id, 0)
                ret_contents['activity'] = ret_activity
                ret_e_appointment = self.get_e_appointment(u_id, 0)
                ret_contents['entryappointment'] = ret_e_appointment
                ret_my_appointment = self.get_my_appointment(u_id, 0)
                ret_contents['myappointment'] = ret_my_appointment
                self.retjson['code'] = '10392'
                self.retjson['contents'] = ret_contents

            elif type == '10902':  # 查看我的正在进行的约拍活动
                ret_activity = self.get_activity(u_id, 1)
                ret_contents['activity'] = ret_activity
                ret_e_appointment = self.get_e_appointment(u_id, 1)
                ret_contents['entryappointment'] = ret_e_appointment
                ret_my_appointment = self.get_my_appointment(u_id, 1)
                ret_contents['myappointment'] = ret_my_appointment
                self.retjson['code'] = '10393'
                self.retjson['contents'] = ret_contents

            elif type == '10903':  # 查看我的已经完成的但是没有评价约拍活动
                ret_activity = self.get_activity(u_id, 2)
                ret_contents['activity'] = ret_activity
                ret_e_appointment = self.get_e_appointment_not_evaluate(u_id)
                ret_contents['entryappointment'] = ret_e_appointment
                ret_my_appointment = self.get_my_appointment_not_evaluate(u_id)
                ret_contents['myappointment'] = ret_my_appointment
                self.retjson['code'] = '10394'
                self.retjson['contents'] = ret_contents

            elif type == '10909':  # 查看我的已经完成评价的约拍 这里没有活动了,因为活动没有状态码4

                ret_e_appointment = self.get_e_appointment_evaluate(u_id)
                ret_contents['entryappointment'] = ret_e_appointment
                ret_my_appointment = self.get_my_appointment_evaluate(u_id)
                ret_contents['myappointment'] = ret_my_appointment
                self.retjson['code'] = '10395'
                self.retjson['contents'] = ret_contents

            elif type == '10904':  # 选择约拍对象
                apid = self.get_argument('apid')
                chooseuid = self.get_argument('chooseduid')
                try:
                    registEntry = self.db.query(AppointEntry).\
                        filter(AppointEntry.AEregisterID == chooseuid, AppointEntry.AEapid == apid).one()  # 查找报名项
                    if registEntry:
                        if registEntry.AEvalid == 1:  # 用户未取消报名
                            if registEntry.AEchoosed:
                                self.retjson['contents'] = u'之前已选择过该用户!'
                            else:  # 用户报名中且未被选择,添加新的约拍项
                                registEntry.AEchoosed = 1  # 该用户被选择
                                try:
                                    appointment = self.db.query(Appointment.APid, Appointment.APsponsorid, Appointment.APtype,
                                                                Appointment.APstatus).\
                                        filter(Appointment.APid == registEntry.AEapid).one()
                                    if appointment.APsponsorid == int(
                                            u_id):  # 该操作用户是发起者
                                        mid = pid = 0
                                        if appointment.APtype == 1:  # 发起者是摄影师:
                                            mid = chooseuid
                                            pid = u_id
                                        elif appointment.APtype == 0:  # 发起者是模特:
                                            mid = u_id
                                            pid = chooseuid
                                        print 'before change'
                                        self.db.query(Appointment).filter(Appointment.APid == appointment.APid).\
                                        update({"APstatus": 1}, synchronize_session='evaluate') # 将该约拍项移到进行中
                                        print 'after change'
                                        newappinfo = AppointmentInfo(
                                            AImid=mid,
                                            AIpid=pid,
                                            AIappoid=apid)
                                        try:
                                            self.db.merge(newappinfo)
                                            self.db.commit()
                                            self.retjson['code'] = '10920'
                                            self.retjson[
                                                'contents'] = u"选择约拍对象成功"
                                        except Exception, e:
                                            print e
                                            self.retjson['code'] = '10925'
                                            self.retjson[
                                                'contents'] = u"数据库插入错误"
                                    else:
                                        self.retjson['code'] = '10921'
                                        self.retjson[
                                            'contents'] = u"该用户没有选择权限!"
                                except Exception, e:
                                    print e
                                    self.retjson['code'] = '10924'
                                    self.retjson['contents'] = u'该约拍不存在或已过期'