Beispiel #1
0
 def post(self):
     self.check_input('actId')
     if ('ticket' in self.input and 'studentId' in self.input) or (
             'ticket' not in self.input and 'studentId' not in self.input):
         raise InputError(
             "Ticket and student ID, you can provide and only provide one.")
     with transaction.atomic():
         if 'ticket' in self.input:
             x = Ticket.objects.select_for_update().get(
                 unique_id=self.input['ticket'])
         else:
             x = Ticket.objects.select_for_update().get(
                 student_id=self.input['studentId'])
         if x.status != Ticket.STATUS_VALID:
             raise Exception('ticket already used' if x.status == Ticket.
                             STATUS_USED else 'ticket already cancelled')
         x.status = Ticket.STATUS_USED
         x.save()
     return {'ticket': x.unique_id, 'studentId': x.student_id}
Beispiel #2
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 #3
0
 def check_input(self, *keys):
     for k in keys:
         if k not in self.input:
             raise InputError('Field "%s" required' % (k, ))
 def check_input(self, *keys):
     print('apiview checkinput')
     for k in keys:
         if k not in self.input:
             raise InputError('Field "%s" required' % (k, ))