<commit_before>from django.core.management.base import BaseCommand, CommandError
from reg.models import *

from optparse import make_option
import cStringIO, csv
from collections import defaultdict

class Command(BaseCommand):
    help = 'Closes the specified poll for voting'
    option_list = BaseCommand.option_list + (
        make_option('--staff-domain',
            action='store',
            dest='staff_domain',
            default=None,
            help='Exclude tickets with email addresses from this domain'),
        make_option('--staff-coupon',
            action='store',
            dest='staff_coupon',
            default=None,
            help='Exclude tickets that used this coupon'),
        make_option('--output',
            action='store',
            dest='output',
            default=None,
            help='Output CSV to a file'),
    )

    def handle(self, *args, **options):
        from reg.views import CURRENT_EVENT

        search = {
            'success': True,
            'event': CURRENT_EVENT
        }

        query = Ticket.objects.filter(**search)

        fdomain = '@%s' % options['staff_domain'] if options['staff_domain'] else None
        fcoupon = CouponCode.objects.get(code=options['staff_coupon']) if options['staff_coupon'] else CouponCode()

        outs = cStringIO.StringIO()
        outc = csv.DictWriter(outs, ['first_name', 'last_name', 'email', 'state', 'organization', 'ticket_type', 'is_staff'])
        outc.writeheader()

        for ticket in query.order_by('id').select_related():
            if ticket.lobby_day:
                staff = (ticket.email and fdomain and fdomain in ticket.email) or \
                    (ticket.sale.email and fdomain and fdomain in ticket.sale.email) or \
                    (ticket.sale.coupon_code and ticket.sale.coupon_code.id == fcoupon.id)

                outc.writerow({
                    'first_name': ticket.first_name.encode('utf8'),
                    'last_name': ticket.last_name.encode('utf8'),
                    'email': ticket.email.encode('utf8'),
                    'state': ticket.sale.state.encode('utf8'),
                    'organization': ticket.organization.encode('utf8'),<commit_msg>Tweak the lobby day report slightly.<commit_after>from django.core.management.base import BaseCommand, CommandError
from reg.models import *

from optparse import make_option
import cStringIO, csv
from collections import defaultdict

class Command(BaseCommand):
    help = 'Closes the specified poll for voting'
    option_list = BaseCommand.option_list + (
        make_option('--staff-domain',
            action='store',
            dest='staff_domain',
            default=None,
            help='Exclude tickets with email addresses from this domain'),
        make_option('--staff-coupon',
            action='store',
            dest='staff_coupon',
            default=None,
            help='Exclude tickets that used this coupon'),
        make_option('--output',
            action='store',
            dest='output',
            default=None,
            help='Output CSV to a file'),
    )

    def handle(self, *args, **options):
        from reg.views import CURRENT_EVENT

        search = {
            'success': True,
            'event': CURRENT_EVENT
        }

        query = Ticket.objects.filter(**search)

        fdomain = '@%s' % options['staff_domain'] if options['staff_domain'] else None
        fcoupon = CouponCode.objects.get(code=options['staff_coupon']) if options['staff_coupon'] else CouponCode()

        outs = cStringIO.StringIO()
        outc = csv.DictWriter(outs, ['first_name', 'last_name', 'email', 'address1', 'address2', 'city', 'state', 'zip', 'organization', 'ticket_type', 'is_staff'])
        outc.writeheader()

        for ticket in query.order_by('id').select_related():
            if ticket.lobby_day:
                staff = (ticket.email and fdomain and fdomain in ticket.email) or \
                    (ticket.sale.email and fdomain and fdomain in ticket.sale.email) or \
                    (ticket.sale.coupon_code and ticket.sale.coupon_code.id == fcoupon.id)

                if ticket.sale.state == 'non-us':
                    continue

                outc.writerow({
                    'first_name': ticket.first_name.encode('utf8'),
                    'last_name': ticket.last_name.encode('utf8'),
                    'email': ticket.email.encode('utf8'),
                    'address1': ticket.sale.address1.encode('utf8'),
                    'address2': ticket.sale.address2.encode('utf8'),
                    'city': ticket.sale.city.encode('utf8'),
                    'state': ticket.sale.state.encode('utf8'),
                    'zip': ticket.sale.zip.encode('utf8'),
                    'organization': ticket.organization.encode('utf8'),
{'fraction_non_alphanumeric': 0.1224700536968195, 'fraction_numerical': 0.004130524576621231, 'mean_word_length': 2.161227154046997, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3132210', 'n_tokens_mistral': 1360, 'n_tokens_neox': 1299, 'n_words': 298}