<commit_before>from django.contrib import admin
from django.http import HttpResponse

from djforms.athletics.soccer.models import SoccerCampAttender

import datetime
import csv

def export_attenders(modeladmin, request, queryset):
    """
    Export soccer camp attenders to CSV
    """
    field_names = [
        'last_name','first_name','created_at','dob','age','football',
        'gender','address1','city','state','postal_code','phone','email',
        'order','parent_guard','roommate', 'dorm','years_attend','goalkeeper',
        'shirt_size','session','amount','payment_method','reg_fee',
        'medical_history','assumption_risk','insurance_card_links'
    ]

    headers = [
        'last_name','first_name','created_at','dob','age','football',
        'gender','address1','city','state','postal_code','phone','email',
        'order_total','order_transid','order_status','parent_guard',
        'roommate', 'dorm','years_attend', 'goalkeeper',
        'shirt_size','session','amount','payment_method','reg_fee',
        'medical_history','assumption_risk','insurance_card_links'
    ]

    response = HttpResponse("", content_type="text/csv; charset=utf-8")
    filename = "soccer_soccercampattenders.csv"
    response['Content-Disposition']='attachment; filename={}'.format(filename)
    writer = csv.writer(response)
    writer.writerow(headers)
    for reg in queryset:
        fields = []
        for field in field_names:
            if field == "order":
                # somehow, a transaction comes through w/out these two
                try:
                    transid = reg.order.all()[0].transid
                    status = reg.order.all()[0].status
                    total = reg.order.all()[0].total
                except:
                    transid=""
                    status=""
                    total=""
                fields.append(transid)
                fields.append(status)
                fields.append(total)
            else:
                fields.append(
                    unicode(getattr(reg, field, None)).encode("utf-8", "ignore")
                )
        writer.writerow(fields)
    return response

export_attenders.short_description = "Export Soccer Camp Attenders"

class SoccerCampAttenderAdmin(admin.ModelAdmin):
    model = SoccerCampAttender
    exclude       = ('country','second_name','previous_name','salutation')
    raw_id_fields = ('order',)
    actions = [export_attenders]

    list_display  = (
        'last_name','first_name','created_at','dob','age','football',
        'gender','address1','address2','city','state','postal_code','phone',
        'email','order_transid','order_status','parent_guard','roommate',
        'dorm','years_attend','goalkeeper','shirt_size','session','reg_fee',
        'amount','order_total','payment_method',
        'medical_history','assumption_risk','insurance_card_links'
    )
    ordering      = ('-created_at',)
    search_fields = ('last_name','email','postal_code')

    list_max_show_all   = 1000
    list_per_page       = 1000
    list_editable = [
        'medical_history','assumption_risk'
    ]

    def insurance_card_links(self, instance):
        try:
            code = '''
                <a href="{}" target="_blank">Front</a> |
                <a href="{}" target="_blank">Back</a>
            '''.format(<commit_msg>removed address2 from soccer camp registration admin list display<commit_after>from django.contrib import admin
from django.http import HttpResponse

from djforms.athletics.soccer.models import SoccerCampAttender

import datetime
import csv

def export_attenders(modeladmin, request, queryset):
    """
    Export soccer camp attenders to CSV
    """
    field_names = [
        'last_name','first_name','created_at','dob','age','football',
        'gender','address1','city','state','postal_code','phone','email',
        'order','parent_guard','roommate', 'dorm','years_attend','goalkeeper',
        'shirt_size','session','amount','payment_method','reg_fee',
        'medical_history','assumption_risk','insurance_card_links'
    ]

    headers = [
        'last_name','first_name','created_at','dob','age','football',
        'gender','address1','city','state','postal_code','phone','email',
        'order_total','order_transid','order_status','parent_guard',
        'roommate', 'dorm','years_attend', 'goalkeeper',
        'shirt_size','session','amount','payment_method','reg_fee',
        'medical_history','assumption_risk','insurance_card_links'
    ]

    response = HttpResponse("", content_type="text/csv; charset=utf-8")
    filename = "soccer_soccercampattenders.csv"
    response['Content-Disposition']='attachment; filename={}'.format(filename)
    writer = csv.writer(response)
    writer.writerow(headers)
    for reg in queryset:
        fields = []
        for field in field_names:
            if field == "order":
                # somehow, a transaction comes through w/out these two
                try:
                    transid = reg.order.all()[0].transid
                    status = reg.order.all()[0].status
                    total = reg.order.all()[0].total
                except:
                    transid=""
                    status=""
                    total=""
                fields.append(transid)
                fields.append(status)
                fields.append(total)
            else:
                fields.append(
                    unicode(getattr(reg, field, None)).encode("utf-8", "ignore")
                )
        writer.writerow(fields)
    return response

export_attenders.short_description = "Export Soccer Camp Attenders"

class SoccerCampAttenderAdmin(admin.ModelAdmin):
    model = SoccerCampAttender
    exclude       = ('country','second_name','previous_name','salutation')
    raw_id_fields = ('order',)
    actions = [export_attenders]

    list_display  = (
        'last_name','first_name','created_at','dob','age','football',
        'gender','address1','city','state','postal_code','phone',
        'email','order_transid','order_status','parent_guard','roommate',
        'dorm','years_attend','goalkeeper','shirt_size','session','reg_fee',
        'amount','order_total','payment_method',
        'medical_history','assumption_risk','insurance_card_links'
    )
    ordering      = ('-created_at',)
    search_fields = ('last_name','email','postal_code')

    list_max_show_all   = 1000
    list_per_page       = 1000
    list_editable = [
        'medical_history','assumption_risk'
    ]

    def insurance_card_links(self, instance):
        try:
            code = '''
                <a href="{}" target="_blank">Front</a> |
                <a href="{}" target="_blank">Back</a>
            '''.format(
{'fraction_non_alphanumeric': 0.14858245509870863, 'fraction_numerical': 0.005046756716639454, 'mean_word_length': 2.8393162393162394, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 11, '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': '3847136', 'n_tokens_mistral': 1987, 'n_tokens_neox': 1868, 'n_words': 287}