Ejemplo n.º 1
0
 def get_student_ticket(cls, openid, ticket):
     try:
         return cls.objects.filter(
             student_id=User.get_by_openid(openid).student_id).get(
                 unique_id=ticket)
     except cls.DoesNotExist:
         raise LogicError('Ticket owned by the owner not found')
Ejemplo n.º 2
0
 def get(self):
     self.check_input('id')
     activity = Activity.objects.get(id=self.input['id'])
     if activity.status == Activity.STATUS_PUBLISHED:
         return self.activity_to_dict(activity)
     else:
         raise LogicError(self.input)
Ejemplo n.º 3
0
 def del_event(self, id):
     if id >= len(self.event_list):
         raise LogicError('The given id is out of range')
     events = json.loads(self.event_list)
     Event.get_by_id(events[id]).delete()
     del events[id]
     self.event_list = json.dumps(events)
     self.save()
Ejemplo n.º 4
0
 def post(self):
     self.check_input('id')
     try:
         activity = Activity.objects.get(id=self.input['id'])
     except Activity.DoesNotExist:
         raise DatabaseError(self.input)
     if activity.status == Activity.STATUS_DELETED:
         raise LogicError(self.input)
     activity.status = Activity.STATUS_DELETED
     activity.save()
Ejemplo n.º 5
0
 def get(self):
     buttons = CustomWeChatView.lib.get_wechat_menu()
     if not buttons:
         raise LogicError("Empty WeChat list.")
     names = [x['name'] for x in buttons]
     if "抢票" not in names:
         raise LogicError("No ticket menu.")
     index = names.index("抢票")
     already_in = [x['name'] for x in buttons[index]['sub_button']]
     data = list(
         Activity.objects.filter(status=Activity.STATUS_PUBLISHED,
                                 book_end__gt=timezone.now()))
     return [{
         'id':
         x.id,
         'name':
         x.name,
         'menuIndex':
         0 if x.name not in already_in else already_in.index(x.name) + 1
     } for x in data]
Ejemplo n.º 6
0
    def handle(self):
        try:
            activity = self.get_activity()
            if activity.status != Activity.STATUS_PUBLISHED:
                raise LogicError('activity not published')
        except LogicError:
            return self.reply_text(self.get_message('activity_not_found'))

        if self.user.student_id == '':  # not bind yet
            return self.reply_text(self.get_message('id_not_bind'))

        old_ticket = Ticket.objects.filter(student_id=self.user.student_id,
                                           activity=activity,
                                           status=Ticket.STATUS_VALID).first()
        if old_ticket is not None:  # in fact, it is not snap up ticket, it is withdraw ticket
            return self.reply_single_news({
                'Title':
                self.get_message('withdraw_ticket_title'),
                'Description':
                self.get_message('withdraw_ticket_detail', activity=activity),
                'Url':
                self.url_ticket_detail(old_ticket),
                'PicUrl':
                activity.pic_url,
            })

        if self.get_current_time() < activity.book_start.timestamp(
        ):  # not start yet
            return self.reply_text(self.get_message('book_not_start'))

        if self.get_current_time() > activity.book_end.timestamp(
        ):  # end already
            return self.reply_text(self.get_message('book_end_already'))

        result = Activity.decrease_ticket_exclusive(activity.id)
        if not result:
            return self.reply_text(self.get_message('sold_out'))

        ticket = Ticket.create_ticket(student_id=self.user.student_id,
                                      activity=activity)
        return self.reply_single_news({
            'Title':
            self.get_message('book_ticket_success_title'),
            'Description':
            self.get_message('book_ticket_success_detail', activity=activity),
            'Url':
            self.url_ticket_detail(ticket),
            'PicUrl':
            activity.pic_url,
        })
Ejemplo n.º 7
0
 def get_activity(self):
     """
     note: command can be followed by ONE space and activity key
     :return: current activity id, int
     """
     if self.is_text_command('抢票'):
         text = self.extract_activity_name()
         return Activity.get_by_activity_key(text)
     else:
         key = self.input['EventKey']
         key = key[len(self.view.event_keys['book_header']):]
         if key.isdigit():
             activity_id = int(key)
             return Activity.get_by_activity_id(activity_id)
         else:
             raise LogicError('EventKey does not contain id')
Ejemplo n.º 8
0
 def get_a_ticket(cls, student_id, unique_id):
     try:
         ticket = cls.objects.get(student_id=student_id,
                                  unique_id=unique_id)
         foreignkey = ticket.activity
         res = {
             'activityName': foreignkey.name,
             'place': foreignkey.place,
             'activityKey': foreignkey.key,
             'uniqueId': ticket.unique_id,
             'startTime': int(foreignkey.start_time.timestamp()),
             'endTime': int(foreignkey.end_time.timestamp()),
             'currentTime': 0,
             'status': ticket.status
         }
         return res
     except cls.DoesNotExist:
         raise LogicError('Ticket not found')
Ejemplo n.º 9
0
    def get(self):
        self.check_input('id')
        get_id = self.input['id']
        try:
            task = Task.objects.get(id=get_id)
        except ObjectDoesNotExist:
            raise LogicError("No Task!")

        return {
            'config': json.load(task.config),
            'creator': task.creator.username,
            'name': task.name,
            'description': task.description,
            'create_at': task.created_at,
            'status': task.status,
            'input_model': task.input_model,
            'type': task.type,
            'link': task.dataset.link,
            'path': task.dataset.path,
            'dataset_status': task.dataset.status,
        }
Ejemplo n.º 10
0
 def get_by_personid(cls, personid):
     try:
         return cls.objects.get(person_id=personid)
     except cls.DoesNotExist:
         raise LogicError('User not found')
Ejemplo n.º 11
0
 def get_by_activity_id(cls, id):
     try:
         return cls.objects.filter(activity_id=id)
     except:
         raise LogicError('get ticket by activity error!')
Ejemplo n.º 12
0
 def get_by_id(cls, id):
     try:
         return cls.objects.filter(status=cls.STATUS_PUBLISHED).get(id=id)
     except cls.DoesNotExist:
         raise LogicError('Activity not found')
Ejemplo n.º 13
0
 def get_by_id(cls, id):
     try:
         # print("id=" + str(id))
         return cls.objects.get(id=id)
     except:
         raise LogicError('get activity by id error!')
Ejemplo n.º 14
0
 def remove_by_id(cls, id):
     try:
         cls.objects.get(id=id).delete()
     except:
         raise LogicError('delete activity error!')
Ejemplo n.º 15
0
 def get_nonegtive_status(cls):
     try:
         return cls.objects.filter(status__gte=0)
     except:
         raise LogicError('get activity by status error!')
Ejemplo n.º 16
0
 def get_by_roomid(cls, roomid):
     try:
         return cls.objects.get(room_id=roomid)
     except cls.DoesNotExist:
         raise LogicError('Room not found')
Ejemplo n.º 17
0
 def get_by_student_id(cls, student_id):
     try:
         return cls.objects.get(student_id=student_id)
     except cls.DoesNotExist:
         raise LogicError('User not found')
Ejemplo n.º 18
0
 def get_by_studentId(cls, student_id):
     try:
         return cls.objects.filter(student_id=student_id)
     except cls.DoesNotExist:
         raise LogicError('Ticket not found')
Ejemplo n.º 19
0
 def get_status_ge_0(cls):
     try:
         return cls.objects.filter(status__gte = 0)
     except cls.DoesNotExist:
         raise LogicError('Activity Not Found')
Ejemplo n.º 20
0
 def get_by_activity_key(cls, activity_key):
     try:
         return cls.objects.get(key=activity_key)
     except cls.DoesNotExist:
         raise LogicError('Activity not found')
Ejemplo n.º 21
0
 def safe_get(**args):
     try:
         Journal.objects.get(args)
     except:
         raise LogicError("No Such Journal")
Ejemplo n.º 22
0
 def get_by_openid(cls, openid):
     try:
         return cls.objects.get(open_id=openid)
     except cls.DoesNotExist:
         raise LogicError('User not found')
Ejemplo n.º 23
0
 def get_status_published(cls):
     try:
         return cls.objects.filter(status=cls.STATUS_PUBLISHED)
     except:
         raise LogicError('get activity by status=1 error!')
Ejemplo n.º 24
0
 def get_by_id(cls,id):
     try:
         return cls.objects.get(id=id)
     except cls.DoesNotExist:
         raise LogicError("Activity not found")
Ejemplo n.º 25
0
 def get_by_openid(cls, openid):
     with transaction.atomic():
         try:
             return cls.objects.select_for_update().get(open_id=openid)
         except cls.DoesNotExist:
             raise LogicError('User not found')
Ejemplo n.º 26
0
 def get_by_id(cls, unique_id):
     try:
         return cls.objects.get(unique_id=unique_id)
     except cls.DoesNotExist:
         raise LogicError('Ticket not found')
Ejemplo n.º 27
0
 def get_by_id(cls, id):
     try:
         return cls.objects.get(id=id)
     except cls.DoesNotExist:
         raise LogicError('Event not found')