Beispiel #1
0
def public_non_liu_sell(request):
    error = ''
    success = False
    visitor_form = PublicVisitorForm(request.POST or None)
    ticket_type_form = PublicTicketTypeForm(request.POST or None)

    if visitor_form.is_valid() and ticket_type_form.is_valid():
        try:
            visitor = visitor_form.save()
            person = visitor.person_ptr

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

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

            for ticket_type_id in ticket_type_ids:
                ticket_type = TicketType.objects.select_for_update().get(pk=ticket_type_id)

                if ticket_type.ticket_set.count() >= ticket_type.max_amount:
                    # 4 o'clock in the morning hack...
                    invoice.delete()
                    person.delete()
                    raise TicketSoldOut()

                Ticket.objects.create(invoice=invoice, ticket_type=ticket_type, person=person)
            invoice.send_verify_email()

            success = True
            visitor_form = PublicVisitorForm()
            ticket_type_form = PublicTicketTypeForm()

        except TicketSoldOut:
            error = _('This ticket type is sold out')

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

        except StudentNotFound:
            error = _('Student was not found')

        except InvalidForm:
            error = _('The form was not filled in properly')

    return render(request, 'tickets/public_non_liu_sell.html',
                  {'ticket_type_form': ticket_type_form,
                   'visitor_form': visitor_form,
                   'error': error, 'success': success})
Beispiel #2
0
def public_sell(request):
    error = ''
    success = False
    liu_id_form = LiuIDForm(request.POST or None)
    ticket_type_form = PublicTicketTypeForm(request.POST or None)

    if liu_id_form.is_valid() and ticket_type_form.is_valid():
        try:
            term = liu_id_form.cleaned_data['liu_id']

            try:
                person = Person.objects.search(term=term)

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

            except Person.DoesNotExist:
                client = KOBRAClient(settings.KOBRA_USER, settings.KOBRA_KEY)
                student = client.get_student(term)
                visitor = Visitor.objects.create(**get_kwargs(student))
                person = visitor.person_ptr

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

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

            for ticket_type_id in ticket_type_ids:
                ticket_type = TicketType.objects.select_for_update().get(pk=ticket_type_id)

                if ticket_type.ticket_set.count() >= ticket_type.max_amount:
                    raise TicketSoldOut()

                Ticket.objects.create(invoice=invoice, ticket_type=ticket_type, person=person)
            invoice.send_verify_email()

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

        except TicketSoldOut:
            error = _('This ticket type is sold out')

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

        except StudentNotFound:
            error = _('Student was not found')

    return render(request, 'tickets/public_sell.html',
                  {'ticket_type_form': ticket_type_form,
                   'liu_id_form': liu_id_form,
                   'error': error, 'success': success})
Beispiel #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})
Beispiel #4
0
def create_invoice(person):
    invoice = Invoice(person=person, is_verified=True)
    invoice.generate_data()
    invoice.save()
    return invoice
    reader = csv.reader(csvfile)

    for row in reader:
        _, ticket_types, first_name, last_name, orig_pid, email, status = row
        email = email.lower()

        if not status == "Redo för import":
            continue

        pid = format_pid(orig_pid)

        if try_get_person(pid=pid):
            error('Person exists')
            continue

        person = try_create_manually(first_name, last_name, pid, email)

        if not person:
            error('Could not create person')
            continue

        person.save()
        print ' '.join((first_name, last_name))

        invoice = Invoice(person=person, is_verified=True)
        invoice.generate_data()
        invoice.save()

        create_tickets(invoice, ticket_types)
        invoice.send_as_email()
 def create_stuff():
     invoice = Invoice(person=visitor.person_ptr, is_verified=True)
     invoice.generate_data()
     invoice.save()
     Ticket.objects.create(invoice=invoice, ticket_type_id=1)
def main():
    edited = []
    manual_visitors = 0
    liu_visitors = 0
    failed = 0
    invalid_pid = 0

    with open('people.csv', 'rb') as csvfile:
        def error(msg):
            print
            print msg
            print name
            print ', '.join(row)
            print '-------------------------------'

        reader = csv.reader(csvfile)
        for row in reader:
            _, _, liu_id, name, orig_pid, email, reason, ticket_types, _ = row
            name = unicode(name, 'utf-8')
            name_split = name.split()

            fname, lname = name_split[0], ' '.join(name_split[1:])
            liu_id = liu_id.lower().strip()
            pid = format_pid(orig_pid)

            if '@' in email and '.' in email:
                email = email.lower()
            else:
                email = None

            # if not reason:
            #     error('No reason given')
            #     no_reason += 1
            #     continue

            person = try_get_person(pid=pid, liu_id=liu_id)

            if not person:
                visitor = try_get_from_kobra(pid=pid, liu_id=liu_id)

                if visitor:
                    person = try_get_person(pid=visitor.pid,
                                            liu_id=visitor.liu_id)

                    if person:
                        visitor = None

                    if email:
                        if visitor:
                            visitor.email = email.lower()
                        elif person:
                            person.email = email.lower()
                    liu_visitors += 1
                else:
                    visitor = try_create_manually(fname, lname, pid, email)

                    if visitor:
                        manual_visitors += 1

                if not (visitor or person):
                    if orig_pid and not pid:
                        error('Invalid PID')
                        invalid_pid += 1
                        continue
                    error('Could not find or create user')
                    failed += 1
                    continue

                if visitor:
                    visitor.save()
                    person = visitor.person_ptr
                elif person:
                    person.save()

            if Invoice.objects.filter(person=person).exists():
                ticket_types = ticket_types.replace(' (tors, fre, lör)', '')
                if [TYPES[tt] for tt in ticket_types.split(', ')] != [1]:
                    edited.append(person)
                continue

            invoice = Invoice(person=person, is_verified=True)
            invoice.generate_data()
            invoice.save()

            create_tickets(invoice, ticket_types)
            invoice.send_as_email()

        print '\n========================================================'
        print '%d manual visitors' % manual_visitors
        print '%d liu visitors' % liu_visitors
        print '%d failed' % failed
        print '%d invalid PID' % invalid_pid

        print '\n========================================================'
        print '%d edited ticket types' % len(edited)
        print
        for p in edited:
            print unicode(p)
            print p.liu_id or p.pid
            print