Beispiel #1
0
 def post(self):
     if self.request.user.is_authenticated():
         self.check_input('name', 'key', 'place', 'description', 'picUrl',
                          'startTime', 'endTime', 'bookStart', 'bookEnd',
                          'totalTickets', 'status')
         check = Activity.objects.filter(
             name=self.input['name'],
             start_time=self.input['startTime']).first()
         if check is not None:
             raise LogicError('already have this activity')
         if len(self.input['picUrl']) > 256:
             raise LogicError(
                 'picUrl is too long, please upload local picture')
         act = Activity(name=self.input['name'],
                        key=self.input['key'],
                        place=self.input['place'],
                        description=self.input['description'],
                        pic_url=self.input['picUrl'],
                        start_time=self.input['startTime'],
                        end_time=self.input['endTime'],
                        book_start=self.input['bookStart'],
                        book_end=self.input['bookEnd'],
                        total_tickets=self.input['totalTickets'],
                        status=self.input['status'],
                        remain_tickets=self.input['totalTickets'])
         act.save()
         return act.id
     else:
         raise LoginError('')
Beispiel #2
0
 def test_acti_del_succ(self):
     s = Activity(name='11111',
                  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')
     s.save()
     name_test = s.name
     models.User.objects.create_user(username='******',
                                     email="*****@*****.**",
                                     password='******')
     c.login(username='******', password='******')
     resp = c.post('/api/a/activity/delete', {'id': s.id})
     mess = json.loads(str(resp.content, encoding="utf-8"))
     self.assertEqual(mess['code'], 0)
     self.assertEqual(mess['msg'], '')
     t = Activity.objects.filter(name=name_test)
     self.assertEqual(t[0].status, Activity.STATUS_DELETED)
Beispiel #3
0
 def post(self):
     """
     input:  self.input['name'] -------- 活动名称
             self.input['key'] -------- 活动代称
             self.input['place'] -------- 活动地点
             self.input['description'] -------- 活动描述
             self.input['picUrl'] -------- 活动配图url
             self.input['startTime'] -------- 活动开始时间
             self.input['endTime'] -------- 活动结束时间
             self.input['bookStart'] -------- 抢票开始时间
             self.input['bookEnd'] -------- 抢票结束时间
             self.input['totalTickets'] -------- 总票数
             self.input['status'] -------- 暂存或发布
             添加新活动
             需要登录
     """
     self.check_input('name', 'key', 'place', 'description', 'picUrl', 'startTime', 'endTime', 'bookStart',\
                      'bookEnd', 'totalTickets', 'status')
     if not self.request.user.is_authenticated():
         raise ValidateError("admin-user not login!")
     else:
         new_activity = Activity(name=self.input['name'], key=self.input['key'],place=self.input['place'],\
                                 description=self.input['description'], pic_url=self.input['picUrl'].replace(settings.MEDIA_SAVE_ROOT, settings.MEDIA_ROOT),\
                                 start_time=self.input['startTime'], end_time=self.input['endTime'],\
                                 book_start=self.input['bookStart'], book_end=self.input['bookEnd'],\
                                 total_tickets=self.input['totalTickets'], status=self.input['status'], remain_tickets=self.input['totalTickets'])
         new_activity.save()
         return new_activity.id
Beispiel #4
0
 def test_acti_create_fail_repeat(self):
     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()
     models.User.objects.create_user(username='******',
                                     email="*****@*****.**",
                                     password='******')
     c.login(username='******', password='******')
     resp = c.post(
         '/api/a/activity/create', {
             'name': a.name,
             'key': '11',
             'place': 'ss',
             'description': 'ss',
             'picUrl': 'ss',
             'startTime': a.start_time,
             'endTime': str(timezone.now()),
             'bookStart': str(timezone.now()),
             'bookEnd': str(timezone.now()),
             'totalTickets': '123',
             'status': Activity.STATUS_PUBLISHED
         })
     mess = json.loads(str(resp.content, encoding="utf-8"))
     self.assertEqual(mess['code'], 2)
     self.assertEqual(mess['msg'], 'already have this activity')
Beispiel #5
0
    def post(self):
        if self.request.user.is_authenticated():
            self.check_input('name', 'key', 'place', 'description', 'picUrl',
                             'startTime', 'endTime', 'bookStart', 'bookEnd',
                             'totalTickets', 'status')

            try:
                new_activity = Activity(
                    name=self.input['name'],
                    key=self.input['key'],
                    place=self.input['place'],
                    description=self.input['description'],
                    pic_url=self.input['picUrl'],
                    start_time=self.input['startTime'],
                    end_time=self.input['endTime'],
                    book_start=self.input['bookStart'],
                    book_end=self.input['bookEnd'],
                    total_tickets=self.input['totalTickets'],
                    status=self.input['status'],
                    remain_tickets=self.input['totalTickets'])
                new_activity.save()
            except:
                raise ValidateError('创建失败')
            else:
                return new_activity.id

        else:
            raise ValidateError('没有登录')
Beispiel #6
0
 def post(self):
     self.check_input('name', 'key', 'place', 'description', 'picUrl',
                      'startTime', 'endTime', 'bookStart', 'bookEnd',
                      'totalTickets', 'status')
     if not self.request.user.is_authenticated():
         raise ValidateError('User not logged in!')
     new_activity = Activity(
         name=self.input['name'],
         key=self.input['key'],
         place=self.input['place'],
         description=self.input['description'],
         pic_url=self.input['picUrl'],
         start_time=datetime.strptime(self.input['startTime'],
                                      "%Y-%m-%dT%H:%M:%S.%fZ") +
         timedelta(hours=8),
         end_time=datetime.strptime(self.input['endTime'],
                                    "%Y-%m-%dT%H:%M:%S.%fZ") +
         timedelta(hours=8),
         book_start=datetime.strptime(self.input['bookStart'],
                                      "%Y-%m-%dT%H:%M:%S.%fZ") +
         timedelta(hours=8),
         book_end=datetime.strptime(self.input['bookEnd'],
                                    "%Y-%m-%dT%H:%M:%S.%fZ") +
         timedelta(hours=8),
         remain_tickets=self.input['totalTickets'],
         total_tickets=self.input['totalTickets'],
         status=self.input['status'])
     new_activity.save()
     return new_activity.id
Beispiel #7
0
 def setUp(self):
     new_activity = Activity(
         name='玩玩',
         key='玩  ',
         description='桌游',
         start_time=datetime.datetime.fromtimestamp(1539844241),
         end_time=datetime.datetime.fromtimestamp(1539844945),
         place='THU ',
         book_start=datetime.datetime.fromtimestamp(1539844345),
         book_end=datetime.datetime.fromtimestamp(1539844545),
         total_tickets=11,
         pic_url='www.baidu.com',
         remain_tickets=10,
         status=1,
     )
     new_activity.save()
     self.id_success = new_activity.id
     new_activity = Activity(
         name='玩一玩',
         key='玩',
         description='玩桌游',
         start_time=datetime.datetime.fromtimestamp(1539844245),
         end_time=datetime.datetime.fromtimestamp(1539844945),
         place='THU',
         book_start=datetime.datetime.fromtimestamp(1539844345),
         book_end=datetime.datetime.fromtimestamp(1539844545),
         total_tickets=11,
         pic_url='www.baidu.com',
         remain_tickets=10,
         status=0,
     )
     new_activity.save()
     self.id_fail = new_activity.id
Beispiel #8
0
 def post(self):
     # if self.request.user.is_authenticated():
     self.check_input('name', 'key', 'place', 'description', 'picUrl', 'startTime', 'endTime', 
     'bookStart', 'bookEnd', 'totalTickets', 'status')
     
     name = self.input['name']
     key = self.input['key']
     place = self.input['place']
     description = self.input['description']
     pic_url = self.input['picUrl']
     start_time = self.input['startTime']
     end_time = self.input['endTime']
     book_start = self.input['bookStart']
     book_end = self.input['bookEnd']
     total_tickets = self.input['totalTickets']
     remain_tickets = self.input['totalTickets']
     status = self.input['status']
     try:
         new = Activity(name=name, key=key, place=place, 
         description=description, pic_url=pic_url, start_time=start_time, 
         end_time=end_time, book_start=book_start, book_end=book_end, 
         total_tickets=total_tickets, remain_tickets=remain_tickets, status=status)
         new.save()
         return new.id
     except:
         raise ValidateError('Create activity error!')
Beispiel #9
0
 def setUp(self):
     s = Activity(name='11111',
                  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')
     s.save()
Beispiel #10
0
def createActivityAfterBooking():
    act = Activity(name='act_after_booking',
                   key='after_booking',
                   description='desc1',
                   place='place1',
                   start_time=datetime.now(timezone.utc),
                   end_time=datetime.now(timezone.utc) + timedelta(days=1),
                   book_start=datetime.now(timezone.utc) - timedelta(days=2),
                   book_end=datetime.now(timezone.utc) - timedelta(days=1),
                   total_tickets=100,
                   status=Activity.STATUS_PUBLISHED,
                   pic_url='',
                   remain_tickets=100)
    act.save()
    return act
Beispiel #11
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 #12
0
 def test_acti_det_mod_succ(self):
     s = Activity(name='11111',
                  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_SAVED,
                  pic_url='sss',
                  remain_tickets='1')
     s.save()
     models.User.objects.create_user(username='******',
                                     email="*****@*****.**",
                                     password='******')
     c.login(username='******', password='******')
     resp = c.post(
         '/api/a/activity/detail', {
             'id': s.id,
             'name': 'test',
             'place': 'test',
             'description': 'ss',
             'picUrl': 'to test',
             'startTime': s.start_time,
             'endTime': s.end_time,
             'bookStart': "test",
             'bookEnd': s.book_end,
             'totalTickets': '123',
             'status': str(Activity.STATUS_SAVED)
         })
     mess = json.loads(str(resp.content, encoding="utf-8"))
     self.assertEqual(mess['code'], 0)
     self.assertEqual(mess['msg'], '')
     # change
     t = Activity.objects.filter(id=s.id).first()
     self.assertEqual(t.pic_url, 'to test')
     self.assertEqual(t.place, 'test')
     self.assertEqual(t.name, 'test')
     self.assertEqual(t.book_start, 'test')
Beispiel #13
0
 def post(self):
     self.check_input('name', 'key', 'place', 'description', 'startTime',
                      'endTime', 'bookStart', 'bookEnd', 'totalTickets',
                      'status', 'picUrl')
     act_info = self.input
     new_act = Activity(name=act_info["name"],
                        key=act_info["key"],
                        place=act_info["place"],
                        description=act_info["description"],
                        start_time=act_info["startTime"],
                        end_time=act_info["endTime"],
                        book_start=act_info["bookStart"],
                        book_end=act_info["bookEnd"],
                        total_tickets=act_info["totalTickets"],
                        status=act_info["status"],
                        pic_url=act_info["picUrl"],
                        remain_tickets=act_info["totalTickets"],
                        used_tickets=0)
     new_act.save()
     id = new_act.id
     return id
Beispiel #14
0
 def test_acti_del_fail(self):
     s = Activity(name='11111',
                  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')
     s.save()
     name_test = s.name
     resp = c.post('/api/a/activity/delete', {'id': s.id})
     mess = json.loads(str(resp.content, encoding="utf-8"))
     self.assertEqual(mess['code'], 4)
     self.assertEqual(mess['msg'], '')
     t = Activity.objects.filter(name=name_test)
     self.assertEqual(t[0].status, Activity.STATUS_PUBLISHED)
Beispiel #15
0
 def post(self):
     self.check_input('name', 'key', 'place', 'description', 'picUrl',
                      'startTime', 'endTime', 'bookStart', 'bookEnd',
                      'totalTickets', 'status')
     if len(list(Activity.objects.filter(key=self.input['key']))) > 0:
         raise InputError(
             "activity key %s already exists! use another key instead." %
             (self.input['key']))
     q = Activity(name=self.input['name'],
                  key=self.input['key'],
                  place=self.input['place'],
                  description=self.input['description'],
                  pic_url=self.input['picUrl'],
                  start_time=self.input['startTime'],
                  end_time=self.input['endTime'],
                  book_start=self.input['bookStart'],
                  book_end=self.input['bookEnd'],
                  total_tickets=self.input['totalTickets'],
                  status=self.input['status'])
     q.remain_tickets = q.total_tickets
     q.save()
     return q.id
Beispiel #16
0
    def post(self):
        data = json.loads(self.request.body.decode('utf-8'))

        actModels = Activity.objects.filter(name=data['name'])
        if len(actModels) != 0:
            raise DuplicateError('Duplicated activity name!')

        actModels = Activity.objects.filter(key=data['key'])
        if len(actModels) != 0:
            raise DuplicateError('Duplicated activity key!')

        data['remainTickets'] = data['totalTickets']
        camelList = ['startTime', 'endTime', 'totalTickets', 'remainTickets', \
                     'bookStart', 'bookEnd', 'picUrl']
        underList = ['start_time', 'end_time', 'total_tickets', 'remain_tickets', \
                     'book_start', 'book_end', 'pic_url']
        for index, key in enumerate(camelList):
            if key in data:
                data[underList[index]] = data[key]
                data.pop(key, None)

        activity = Activity(**data)
        activity.save()
Beispiel #17
0
    def post(self):
        data = json.loads(self.request.body.decode('utf-8'))
        data['remainTickets'] = data['totalTickets']

        camelList = ['startTime', 'endTime', 'totalTickets', 'remainTickets', \
                     'bookStart', 'bookEnd', 'picUrl']
        underList = ['start_time', 'end_time', 'total_tickets', 'remain_tickets', \
                     'book_start', 'book_end', 'pic_url']
        for index, key in enumerate(camelList):
            if key in data:
                data[underList[index]] = data[key]
                data.pop(key, None)

        uselessList = ['bookStart-month', 'bookStart-minute', 'bookStart-day', \
                       'bookStart-hour', 'bookStart-year', 'currentTime', 'usedTickets', 'bookedTickets']
        for key in uselessList:
            data.pop(key, None)

        activity = Activity.objects.filter(id=data['id'])[0]
        activity.delete()

        newActivity = Activity(**data)
        newActivity.save()
        return 1
Beispiel #18
0
 def test_acti_get_succ(self):
     s = Activity(name='11111',
                  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')
     s.save()
     models.User.objects.create_user(username='******',
                                     email="*****@*****.**",
                                     password='******')
     c.login(username='******', password='******')
     resp = c.get('/api/a/activity/list')
     mess = json.loads(str(resp.content, encoding="utf-8"))
     self.assertEqual(mess['code'], 0)
     self.assertEqual(mess['msg'], '')
     # return empty list
     self.assertEqual(mess['data'][0]['name'], '11111')
Beispiel #19
0
    def post(self):
        self.check_input('name', 'key', 'place', 'description', 'picUrl',
                         'startTime', 'endTime', 'bookStart', 'bookEnd',
                         'status', 'totalTickets')
        user = self.request.user
        if user.is_authenticated:
            activity = Activity(
                name=self.input['name'],
                key=self.input['key'],
                place=self.input['place'],
                description=self.input['description'],
                pic_url=self.input['picUrl'],
                start_time=self.input['startTime'],
                end_time=self.input['endTime'],
                book_start=self.input['bookStart'],
                book_end=self.input['bookEnd'],
                status=self.input['status'],
                total_tickets=self.input['totalTickets'],
                remain_tickets=self.input['totalTickets'],
            )
            activity.save()

        else:
            raise ValidateError("请先登录")
Beispiel #20
0
 def setUp(self):
     User.objects.create(open_id="123456789", student_id="2016010649")
     new_activity = Activity(
         name='玩玩',
         key='玩  ',
         description='桌游',
         start_time=datetime.datetime.fromtimestamp(1539844241),
         end_time=datetime.datetime.fromtimestamp(1539844945),
         place='THU ',
         book_start=datetime.datetime.fromtimestamp(1539844345),
         book_end=datetime.datetime.fromtimestamp(1539844545),
         total_tickets=11,
         pic_url='www.baidu.com',
         remain_tickets=10,
         status=1,
     )
     new_activity.save()
     new_ticket = Ticket(
         student_id='2016010649',
         unique_id='789456123',
         activity=new_activity,
         status=1,
     )
     new_ticket.save()
Beispiel #21
0
    def setUp(self):
        User.objects.create_superuser(adminForTest['username'],
                                      adminForTest['email'],
                                      adminForTest['password'])
        User.objects.create_user(userForTest['username'], userForTest['email'],
                                 userForTest['password'])

        deleted_activity.save()
        saved_activity.save()
        published_activity.save()

        n = 10

        for i in range(n):
            ticket = Ticket(student_id='Valid_' + str(i),
                            unique_id='Valid_' + str(i),
                            activity_id=published_activity.id,
                            status=Ticket.STATUS_VALID)
            ticket.save()
        for i in range(n):
            ticket = Ticket(student_id='Used_' + str(i),
                            unique_id='Used_' + str(i),
                            activity_id=published_activity.id,
                            status=Ticket.STATUS_USED)
            ticket.save()
        for i in range(n):
            ticket = Ticket(student_id='Canceled_' + str(i),
                            unique_id='Canceled_' + str(i),
                            activity_id=published_activity.id,
                            status=Ticket.STATUS_CANCELLED)
            ticket.save()

        published_activity.remain_tickets -= 3 * n
        published_activity.save()

        current_time = timezone.now()
        delta_1 = timezone.timedelta(hours=1)
        delta_2 = timezone.timedelta(hours=2)
        delta_3 = timezone.timedelta(days=1)

        book_started_act = Activity(id=4,
                                    name='book_start',
                                    key='key',
                                    place='place',
                                    description='description',
                                    start_time=current_time + delta_3,
                                    pic_url="pic_url",
                                    end_time=current_time + delta_1 + delta_3,
                                    book_start=current_time - delta_1,
                                    book_end=current_time + delta_1,
                                    total_tickets=100,
                                    status=Activity.STATUS_PUBLISHED,
                                    remain_tickets=100)
        book_started_act.save()

        started_act = Activity(id=5,
                               name='started',
                               key='key',
                               place='place',
                               description='description',
                               start_time=current_time - delta_1,
                               pic_url="pic_url",
                               end_time=current_time + delta_1,
                               book_start=current_time - delta_3 - delta_1,
                               book_end=current_time - delta_3,
                               total_tickets=100,
                               status=Activity.STATUS_PUBLISHED,
                               remain_tickets=100)
        started_act.save()

        ended_act = Activity(id=6,
                             name='ended',
                             key='key',
                             place='place',
                             description='description',
                             start_time=current_time - delta_2,
                             pic_url="pic_url",
                             end_time=current_time - delta_1,
                             book_start=current_time - delta_3 - delta_1,
                             book_end=current_time - delta_3,
                             total_tickets=100,
                             status=Activity.STATUS_PUBLISHED,
                             remain_tickets=100)
        ended_act.save()
Beispiel #22
0
    def setUp(self):
        User.objects.create_superuser(adminForTest['username'],
                                      adminForTest['email'],
                                      adminForTest['password'])
        User.objects.create_user(userForTest['username'], userForTest['email'],
                                 userForTest['password'])

        current_time = timezone.now()
        delta_1 = timezone.timedelta(hours=1)
        delta_2 = timezone.timedelta(days=1)

        valid_activity = Activity(id=self.ValidID,
                                  name='published',
                                  key='key',
                                  place='place',
                                  description='description',
                                  start_time=current_time - delta_1,
                                  pic_url="pic_url",
                                  end_time=current_time + delta_1,
                                  book_start=timezone.now(),
                                  book_end=timezone.now(),
                                  total_tickets=100,
                                  status=Activity.STATUS_PUBLISHED,
                                  remain_tickets=100)

        ended_activity = Activity(id=self.EndedID,
                                  name='published',
                                  key='key',
                                  place='place',
                                  description='description',
                                  start_time=current_time - delta_2,
                                  pic_url="pic_url",
                                  end_time=current_time - delta_1,
                                  book_start=timezone.now(),
                                  book_end=timezone.now(),
                                  total_tickets=100,
                                  status=Activity.STATUS_PUBLISHED,
                                  remain_tickets=100)

        wrong_activity = Activity(
            id=self.WrongID,
            name='published',
            key='key',
            place='place',
            description='description',
            start_time=timezone.make_aware(datetime(2018, 10, 15, 18, 0, 0,
                                                    0)),
            pic_url="pic_url",
            end_time=timezone.make_aware(datetime(2018, 10, 15, 23, 0, 0, 0)),
            book_start=timezone.now(),
            book_end=timezone.now(),
            total_tickets=100,
            status=Activity.STATUS_PUBLISHED,
            remain_tickets=100)

        valid_ticket = Ticket(student_id='valid_student_id',
                              unique_id='valid_unique_id',
                              activity_id=valid_activity.id,
                              status=Ticket.STATUS_VALID)
        used_ticket = Ticket(student_id='used_student_id',
                             unique_id='used_unique_id',
                             activity_id=valid_activity.id,
                             status=Ticket.STATUS_USED)
        canceled_ticket = Ticket(student_id='canceled_student_id',
                                 unique_id='canceled_unique_id',
                                 activity_id=valid_activity.id,
                                 status=Ticket.STATUS_CANCELLED)
        ended_ticket = Ticket(student_id='ended_student_id',
                              unique_id='ended_unique_id',
                              activity_id=ended_activity.id,
                              status=Ticket.STATUS_VALID)

        valid_activity.save()
        ended_activity.save()
        wrong_activity.save()
        valid_ticket.save()
        used_ticket.save()
        canceled_ticket.save()
        ended_ticket.save()