Example #1
0
def get_kwargs(student):
    return {'first_name': student.get('first_name').title(),
            'last_name': student.get('last_name').title(),
            'email': student.get('email'),
            'lintek_member': student.get('union') == 'LinTek',
            'liu_id': student.get('liu_id') or '',
            'rfid_number': student.get('rfid_number') or '',
            'barcode_number': student.get('barcode_number') or '',
            'pid': format_pid(student.get('personal_number'))}
Example #2
0
    def get_student(self, id_or_card_number):
        # LiU-ID is normally 8 chars long (or 5 chars for some employees)
        valid_pid = format_pid(id_or_card_number)
        if valid_pid:
            return self.get_student_by_pid(format_kobra_pid(valid_pid))

        if len(id_or_card_number) <= 8:
            return self.get_student_by_liu_id(id_or_card_number)
        return self.get_student_by_card(id_or_card_number)
Example #3
0
def preemption(request):
    error = ''
    success = False
    liu_id_form = LiuIDForm(request.POST or None)
    ticket_type_form = PreemptionTicketTypeForm(request.POST or None)

    if liu_id_form.is_valid() and ticket_type_form.is_valid():
        try:
            try:
                worker = Worker.objects.select_for_update().get(liu_id=liu_id_form.cleaned_data.get('liu_id'))
            except Worker.DoesNotExist:
                pid = format_pid(liu_id_form.cleaned_data.get('liu_id'))
                if pid:
                    worker = Worker.objects.select_for_update().get(pid=pid)
                else:
                    raise Worker.DoesNotExist

            if worker.invoice_set.exists():
                raise InvoiceExists()

            person = worker.person_ptr
            invoice = Invoice(person=person, is_verified=False)
            invoice.generate_data()
            invoice.send_verify_email()
            invoice.save()

            ticket_type_ids = ticket_type_form.cleaned_data.get('ticket_type')

            for ticket_type_id in ticket_type_ids:
                Ticket.objects.create(invoice=invoice,
                                      ticket_type_id=ticket_type_id,
                                      person=person)

            success = True
            liu_id_form = LiuIDForm()
            ticket_type_form = PreemptionTicketTypeForm()

        except Worker.DoesNotExist:
            error = _('The functionary was not found')

        except InvoiceExists:
            error = _('An invoice already exist for this person')

    return render(request, 'tickets/preemption.html',
                  {'ticket_type_form': ticket_type_form,
                   'liu_id_form': liu_id_form,
                   'error': error, 'success': success})
Example #4
0
 def search(self, term):
     return self.filter(Q(liu_id=term) |
                        Q(rfid_number=term) |
                        Q(barcode_number=term) |
                        Q(pid=format_pid(term))).get()