Beispiel #1
0
 def post(self):
     print("UserBind post")
     self.check_input('openid', 'student_id', 'password')
     user = User.get_by_openid(self.input['openid'])
     self.validate_user()
     user.student_id = self.input['student_id']
     user.save()
Beispiel #2
0
 def get(self):
     self.check_input('openid')
     try:
         studentId = User.get_by_openid(self.input['openid']).student_id
     except:
         studentId = ''
     return studentId
Beispiel #3
0
 def setUp(self):
     # if you visit in wechat, will do the following things
     user_len = len(test_user_openid)
     for i in range(user_len):
         User(open_id=test_user_openid[i],
              student_id=test_student_id[i]).save()
     self.c = Client()
     published_activity.save()
     published_activity2.save()
     self.get_key_text = [
         XML_TEXT_BASE % (test_user_openid[i], '抢票 key')
         for i in range(user_len)
     ]
     self.get_key_text2 = [
         XML_TEXT_BASE % (test_user_openid[i], '抢票 key2')
         for i in range(user_len)
     ]
     self.refund_key_text = [
         XML_TEXT_BASE % (test_user_openid[i], '退票 key')
         for i in range(user_len)
     ]
     self.show_key_text = [
         XML_TEXT_BASE % (test_user_openid[i], '取票 key')
         for i in range(user_len)
     ]
 def get(self):
     self.check_input('openid', 'ticket')
     user = User.get_by_openid(self.input['openid'])
     student_id = user.student_id
     detail = Ticket.get_a_ticket(student_id, self.input['ticket'])
     detail['currentTime'] = int(datetime.datetime.now().timestamp())
     return detail
Beispiel #5
0
 def setUp(self):
     for i in range(6):
         u = User(open_id=str(i), student_id=str(i))
         u.save()
     a = Activity(name=str(1),
                  key='11',
                  description='aaa',
                  start_time=timezone.now(),
                  end_time=timezone.now(),
                  place='ss',
                  book_end=timezone.now(),
                  book_start=timezone.now(),
                  total_tickets='123',
                  status=Activity.STATUS_PUBLISHED,
                  pic_url='sss',
                  remain_tickets='1')
     a.save()
Beispiel #6
0
 def validate_user(self):
     user = User.get_by_openid(self.input['openid'])
     stuId = self.input['student_id']
     try:
         User.objects.get(student_id=self.input['student_id'])
     except:
         user.student_id = stuId
         user.save()
     else:
         raise ValidateError("Existed student_id")
Beispiel #7
0
    def get(self):
        self.check_input('openid', 'ticket')
        user = User.get_by_openid(self.input['openid'])
        ticket = Ticket.objects.get(unique_id=self.input['ticket'])
        act = Activity.objects.get(id=ticket.activity_id)
        return {
            'activityName': act.name,
            'place': act.place,
            'activityKey': act.key,
            'uniqueId': ticket.unique_id,
            'startTime': act.start_time.timestamp(),
            'endTime': act.end_time.timestamp(),
            'currentTime': datetime.datetime.now().timestamp(),
            'status': ticket.status
        }


###########################################################################
Beispiel #8
0
    def handle(self):
        confirm = WechatConfirmation.get_or_create()
        if self.user.student_id == '':
            return self.reply_text('请先进行绑定')
        try:
            user = User.get_by_openid(self.user.open_id)
        except:
            raise LogicError('no such open_id')

        hw_num = 0
        info_num = 0

        url = 'http://se.zhuangty.com:8000/curriculum/'
        params = {user.student_id}

        response = requests.post('http://se.zhuangty.com:8000/learnhelper/' +
                                 user.student_id + '/courses')

        if response.status_code == 200:
            res = json.loads(response.content.decode())
            for course in res['courses']:
                info_num += course['unreadnotice']
                hw_num += course['unsubmittedoperations']
        else:
            raise LogicError('Response Error')

        message_model = MessageModel()

        timenow = stamp_to_localstr_minute(current_stamp())
        model = message_model.create_remind_model(self.user.open_id, hw_num,
                                                  info_num, timenow)

        model_url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token='
        model_url += confirm.get_access_token()
        res = requests.post(model_url, data=json.dumps(model))

        return self.reply_text('欢迎使用提醒功能')
Beispiel #9
0
 def get(self):
     self.check_input('openid')
     return User.get_by_openid(self.input['openid']).student_id
Beispiel #10
0
def createUser(openID, studentID):
    user = User(open_id=openID, student_id=studentID)
    user.save()
    return user
Beispiel #11
0
 def post(self):
     self.check_input('openid', 'student_id', 'password')
     user = User.get_by_openid(self.input['openid'])
     self.validate_user()
     user.student_id = self.input['student_id']
     user.save()
Beispiel #12
0
 def get(self):
     self.check_input('openid')
     return User.get_by_openid(self.input['openid']).student_id