Ejemplo n.º 1
0
    def post(self):
        if not self.request.user.is_authenticated():
            raise ValidateError('You need to login first.')
        try:
            if 'ticket' in self.input:
                ticket = Ticket.get_by_id(self.input['ticket'])
                res = {
                    'ticket': ticket.unique_id,
                    'studentId': ticket.student_id
                }
                return res
            elif 'studentId' in self.input:
                tickets = Ticket.get_by_studentId(self.input['studentId'])

                input_id = self.input['actId']

                for ticket in tickets:
                    if str(ticket.activity.id) == input_id:
                        res = {
                            'ticket': ticket.unique_id,
                            'studentId': ticket.student_id
                        }
                        return res
                raise MySQLError('Find ticket failed!')
            else:
                raise ValidateError(
                    'You need to input your ticketId or studentId.')
        except Exception as e:
            raise LogicError('Check ticket failed!')
Ejemplo n.º 2
0
 def handle(self):
     if not self.user.student_id:
         return self.reply_text(self.get_message('bind_account'))
     tickets = []
     this_user = self.user
     ticket_list = Ticket.get_by_studentId(student_id=this_user.student_id)
     if len(ticket_list) == 0:
         return self.reply_text('您还没有订票!')
     for ticket in ticket_list:
         tickets.append({
             'Url':
             settings.get_url('/u/ticket', {
                 'openid': this_user.open_id,
                 'ticket': ticket.unique_id
             }),
             'Title':
             '%s' % ticket.activity.name,
             'Description':
             ticket.activity.description,
             'PicUrl':
             ticket.activity.pic_url
         })
     return self.reply_news(articles=tickets)