예제 #1
0
def get_attendees(request, format):
    staff_domains = get_staff_domains()
    fdomains = ['@%s' % domain
                for domain in staff_domains] if staff_domains else []
    fcoupon = set([c.id for c in CouponCode.objects.filter(is_staff=True)])

    out = []
    prefix = '' if (
        format == 'zip' or not request
    ) else request.build_absolute_uri('/register/badges/qrcode/')
    compact = format != 'json'
    for ticket in Ticket.objects.filter(success=True,
                                        event=get_current_event()).order_by(
                                            'sale__created').select_related():
        out.append(get_badge(ticket, prefix, compact))

    if format == 'json':
        return HttpResponse(json.dumps({'attendees': out}),
                            content_type="application/json")
    elif format in ('csv', 'zip'):
        csvbuff = StringIO()
        outc = csv.DictWriter(csvbuff, [
            'first_name', 'last_name', 'registered', 'qrcode', 'qrcode_png',
            'qrcode_svg', 'email', 'twitter', 'organization', 'is_staff',
            'icon', 'checked_in', 'ambassador_program'
        ])
        outc.writeheader()

        for row in out:
            outc.writerow(
                dict([
                    (key,
                     value.encode('utf8') if type(value) == unicode else value)
                    for key, value in row.items()
                ]))

        if format == 'csv':
            return HttpResponse(csvbuff.getvalue(), content_type="text/csv")
        elif format == 'zip':
            zipbuff = StringIO()
            outz = zipfile.ZipFile(zipbuff, 'w', zipfile.ZIP_DEFLATED)

            outz.writestr('export.csv', csvbuff.getvalue())
            for row in out:
                img_data = get_qrcode_image(row['qrcode'], 'both')
                outz.writestr(row['qrcode_png'], img_data['png'],
                              zipfile.ZIP_STORED)
                outz.writestr(row['qrcode_svg'], img_data['svg'])

            outz.close()

            return HttpResponse(zipbuff.getvalue(),
                                content_type="application/zip")
예제 #2
0
def get_badge(ticket, prefix='', compact=True):
    # prime the staff info dict
    if not STAFF_INFO:
        staff_domains = get_staff_domains()
        STAFF_INFO['domains'] = ['@%s' % domain for domain in staff_domains
                                 ] if staff_domains else []
        STAFF_INFO['coupons'] = set(
            [c.id for c in CouponCode.objects.filter(is_staff=True)])

    # are they staff?
    is_staff = True if (ticket.email and any([fdomain in ticket.email for fdomain in STAFF_INFO['domains']])) or \
        (ticket.sale.coupon_code and ticket.sale.coupon_code.id in STAFF_INFO['coupons']) else False

    # prep their qr code
    qrcode_uuid = uuid.UUID(ticket.barcode)
    qrcode = shortuuid.encode(qrcode_uuid)
    out = {
        'first_name': ticket.first_name,
        'last_name': ticket.last_name,
        'registered': ticket.sale.created.isoformat(),
        'qrcode': qrcode,
        'qrcode_png': '%s%s.png' % (prefix, qrcode),
        'qrcode_svg': '%s%s.svg' % (prefix, qrcode),
        'email': ticket.email,
        'twitter': ticket.clean_twitter,
        'organization': ticket.organization,
        'is_staff': is_staff,
        'icon': ICON_NAMES[int(math.floor(10 * (qrcode_uuid.int / MAX_UUID)))],
        'checked_in':
        ticket.checked_in.isoformat() if ticket.checked_in else None,
        'ambassador_program': ticket.ambassador_program,
    }
    if not compact:
        out['title'] = ticket.title
        out['website'] = ticket.website
        out['diet'] = {
            'vegetarian': ticket.diet_vegetarian,
            'vegan': ticket.diet_vegan,
            'gluten_free': ticket.diet_gluten_free,
            'allergies': ticket.diet_allergies,
            'other': ticket.diet_other,
            'desc': {}
        }
        if out['diet']['allergies']:
            out['diet']['desc']['allergies'] = ticket.diet_allergies_desc
        if out['diet']['other']:
            out['diet']['desc']['other'] = ticket.diet_other_desc

        out['lobby_day'] = ticket.lobby_day
        out['days'] = {'day1': ticket.attend_day1, 'day2': ticket.attend_day2}
        out['ticket_type'] = ticket.type.short_name
    return out
예제 #3
0
파일: badges.py 프로젝트: crdunwel/tcamp
def get_badge(ticket, prefix='', compact=True):
    # prime the staff info dict
    if not STAFF_INFO:
        staff_domains = get_staff_domains()
        STAFF_INFO['domains'] = ['@%s' % domain for domain in staff_domains] if staff_domains else []
        STAFF_INFO['coupons'] = set([c.id for c in CouponCode.objects.filter(is_staff=True)])

    # are they staff?
    is_staff = True if (ticket.email and any([fdomain in ticket.email for fdomain in STAFF_INFO['domains']])) or \
        (ticket.sale.coupon_code and ticket.sale.coupon_code.id in STAFF_INFO['coupons']) else False

    # prep their qr code
    qrcode_uuid = uuid.UUID(ticket.barcode)
    qrcode = shortuuid.encode(qrcode_uuid)
    out = {
        'first_name': ticket.first_name,
        'last_name': ticket.last_name,
        'registered': ticket.sale.created.isoformat(),
        'qrcode': qrcode,
        'qrcode_png': '%s%s.png' % (prefix, qrcode),
        'qrcode_svg': '%s%s.svg' % (prefix, qrcode),
        'email': ticket.email,
        'twitter': ticket.clean_twitter,
        'organization': ticket.organization,
        'is_staff': is_staff,
        'icon': ICON_NAMES[int(math.floor(10 * (qrcode_uuid.int / MAX_UUID)))],
        'checked_in': ticket.checked_in.isoformat() if ticket.checked_in else None,
        'ambassador_program': ticket.ambassador_program,
    }
    if not compact:
        out['title'] = ticket.title
        out['website'] = ticket.website
        out['diet'] = {
            'vegetarian': ticket.diet_vegetarian,
            'vegan': ticket.diet_vegan,
            'gluten_free': ticket.diet_gluten_free,
            'allergies': ticket.diet_allergies,
            'other': ticket.diet_other,
            'desc': {}
        }
        if out['diet']['allergies']:
            out['diet']['desc']['allergies'] = ticket.diet_allergies_desc
        if out['diet']['other']:
            out['diet']['desc']['other'] = ticket.diet_other_desc

        out['lobby_day'] = ticket.lobby_day
        out['days'] = {'day1': ticket.attend_day1, 'day2': ticket.attend_day2}
        out['ticket_type'] = ticket.type.short_name
    return out
예제 #4
0
파일: badges.py 프로젝트: crdunwel/tcamp
def get_attendees(request, format):
    staff_domains = get_staff_domains()
    fdomains = ['@%s' % domain for domain in staff_domains] if staff_domains else []
    fcoupon = set([c.id for c in CouponCode.objects.filter(is_staff=True)])

    out = []
    prefix = '' if (format == 'zip' or not request) else request.build_absolute_uri('/register/badges/qrcode/')
    compact = format != 'json'
    for ticket in Ticket.objects.filter(success=True, event=get_current_event()).order_by('sale__created').select_related():
        out.append(get_badge(ticket, prefix, compact))

    if format == 'json':
        return HttpResponse(json.dumps({'attendees': out}), content_type="application/json")
    elif format in ('csv', 'zip'):
        csvbuff = StringIO()        
        outc = csv.DictWriter(csvbuff, ['first_name', 'last_name', 'registered', 'qrcode', 'qrcode_png', 'qrcode_svg', 'email', 'twitter', 'organization', 'is_staff', 'icon', 'checked_in', 'ambassador_program'])
        outc.writeheader()
        
        for row in out:
            outc.writerow(
                dict([(key, value.encode('utf8') if type(value) == unicode else value) for key, value in row.items()])
            )

        if format == 'csv':
            return HttpResponse(csvbuff.getvalue(), content_type="text/csv")
        elif format == 'zip':
            zipbuff = StringIO()
            outz = zipfile.ZipFile(zipbuff, 'w', zipfile.ZIP_DEFLATED)

            outz.writestr('export.csv', csvbuff.getvalue())
            for row in out:
                img_data = get_qrcode_image(row['qrcode'], 'both')
                outz.writestr(row['qrcode_png'], img_data['png'], zipfile.ZIP_STORED)
                outz.writestr(row['qrcode_svg'], img_data['svg'])

            outz.close()

            return HttpResponse(zipbuff.getvalue(), content_type="application/zip")