<commit_before>from django import forms
from django.contrib import admin
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.contrib.auth.admin import UserAdmin

from djspace.core.models import UserProfile, GenericChoice
from djspace.core.utils import get_email_auxiliary

PROFILE_LIST_DISPLAY = [
    'salutation','first_name','second_name','last_name', 'email',
    'email_auxiliary', 'phone_primary','phone_mobile',
    'address1','address2','city','state','postal_code',
    'address1_current','address2_current', 'city_current','state_current',
    'postal_code_current','date_of_birth','gender','race','tribe',
    'disability','disability_specify','employment','military','us_citizen',
    'registration_type'
]

class GenericAdmin(admin.ModelAdmin):
    """
    Base admin class that represents the shared elements that
    most models can use, or override in their respective classes.
    """

    list_display = PROFILE_LIST_DISPLAY
    list_display_links = None

    date_hierarchy = 'date_created'
    ordering = [
        '-date_created','user__last_name','user__email'
    ]

    list_per_page = 500
    raw_id_fields = ("user","updated_by",)

    # user/profile data
    salutation =  lambda s, o: o.user.profile.salutation

    def first_name(self, obj):
        return obj.user.first_name

    def second_name(self, obj):
        return obj.user.profile.second_name

    def last_name(self, obj):
        return '<a href="{}">{}</a>'.format(
            reverse("application_print", args=(obj.get_slug(),obj.id)),
            obj.user.last_name
        )
    last_name.allow_tags = True
    last_name.short_description = 'Last Name (print)'

    def phone_primary(self, obj):
        return obj.user.profile.phone_primary

    def phone_mobile(self, obj):
        return obj.user.profile.phone_mobile

    def address1(self, obj):
        return obj.user.profile.address1
    address1.short_description = "Address1 permanent"

    def address2(self, obj):
        return obj.user.profile.address2
    address2.short_description = "Address2 permanent"

    def city(self, obj):
        return obj.user.profile.city
    city.short_description = "City permanent"

    def state(self, obj):
        return obj.user.profile.state
    state.short_description = "State permanent"

    def postal_code(self, obj):
        return obj.user.profile.postal_code
    postal_code.short_description = "Postal code permanent"

    def address1_current(self, obj):
        return obj.user.profile.address1_current

    def address2_current(self, obj):
        return obj.user.profile.address2_current

    def city_current(self, obj):
        return obj.user.profile.city_current

    def state_current(self, obj):
        return obj.user.profile.state_current

    def postal_code_current(self, obj):
        return obj.user.profile.postal_code_current

    def gender(self, obj):
        return obj.user.profile.gender

    def disability(self, obj):
        return obj.user.profile.disability

    def disability_specify(self, obj):
        return obj.user.profile.disability_specify

    def us_citizen(self, obj):
        return obj.user.profile.us_citizen

    def employment(self, obj):
        return obj.user.profile.employment

    def military(self, obj):
        return obj.user.profile.military

    def race(self, obj):
        return "/".join([r.name for r in obj.user.profile.race.all()])

    def tribe(self, obj):
        return obj.user.profile.tribe

    def email(self, obj):
        return '<a href="%s">%s</a>' % (
            reverse("admin:auth_user_change", args=(obj.user.id,)),
            obj.user.email
        )
    email.allow_tags = True
    email.short_description = 'Profile (view/edit)'

    def email_auxiliary(self, obj):
        return get_email_auxiliary(obj)

    def registration_type(self, obj):
        try:
            reg_type = '<a href="%s">%s</a>' % (
                reverse(
                    "admin:registration_{}_change".format(
                        obj.user.profile.registration_type.lower()<commit_msg>new ordering for all admin list views by user's last name, then first name; fixed email_auxiliary() method which was sending the object rather than the object's user to the get_email_auxiliary() function<commit_after>from django import forms
from django.contrib import admin
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.contrib.auth.admin import UserAdmin

from djspace.core.models import UserProfile, GenericChoice
from djspace.core.utils import get_email_auxiliary

PROFILE_LIST_DISPLAY = [
    'salutation','first_name','second_name','last_name', 'email',
    'email_auxiliary', 'phone_primary','phone_mobile',
    'address1','address2','city','state','postal_code',
    'address1_current','address2_current', 'city_current','state_current',
    'postal_code_current','date_of_birth','gender','race','tribe',
    'disability','disability_specify','employment','military','us_citizen',
    'registration_type'
]

class GenericAdmin(admin.ModelAdmin):
    """
    Base admin class that represents the shared elements that
    most models can use, or override in their respective classes.
    """

    list_display = PROFILE_LIST_DISPLAY
    list_display_links = None

    date_hierarchy = 'date_created'
    ordering = [
        'user__last_name','user__first_name'
    ]
    search_fields = (
        'user__last_name','user__first_name','user__email','user__username'
    )

    list_per_page = 500
    raw_id_fields = ("user","updated_by",)

    # user/profile data
    salutation =  lambda s, o: o.user.profile.salutation

    def first_name(self, obj):
        return obj.user.first_name

    def second_name(self, obj):
        return obj.user.profile.second_name

    def last_name(self, obj):
        return '<a href="{}">{}</a>'.format(
            reverse("application_print", args=(obj.get_slug(),obj.id)),
            obj.user.last_name
        )
    last_name.allow_tags = True
    last_name.short_description = 'Last Name (print)'

    def phone_primary(self, obj):
        return obj.user.profile.phone_primary

    def phone_mobile(self, obj):
        return obj.user.profile.phone_mobile

    def address1(self, obj):
        return obj.user.profile.address1
    address1.short_description = "Address1 permanent"

    def address2(self, obj):
        return obj.user.profile.address2
    address2.short_description = "Address2 permanent"

    def city(self, obj):
        return obj.user.profile.city
    city.short_description = "City permanent"

    def state(self, obj):
        return obj.user.profile.state
    state.short_description = "State permanent"

    def postal_code(self, obj):
        return obj.user.profile.postal_code
    postal_code.short_description = "Postal code permanent"

    def address1_current(self, obj):
        return obj.user.profile.address1_current

    def address2_current(self, obj):
        return obj.user.profile.address2_current

    def city_current(self, obj):
        return obj.user.profile.city_current

    def state_current(self, obj):
        return obj.user.profile.state_current

    def postal_code_current(self, obj):
        return obj.user.profile.postal_code_current

    def gender(self, obj):
        return obj.user.profile.gender

    def disability(self, obj):
        return obj.user.profile.disability

    def disability_specify(self, obj):
        return obj.user.profile.disability_specify

    def us_citizen(self, obj):
        return obj.user.profile.us_citizen

    def employment(self, obj):
        return obj.user.profile.employment

    def military(self, obj):
        return obj.user.profile.military

    def race(self, obj):
        return "/".join([r.name for r in obj.user.profile.race.all()])

    def tribe(self, obj):
        return obj.user.profile.tribe

    def email(self, obj):
        return '<a href="%s">%s</a>' % (
            reverse("admin:auth_user_change", args=(obj.user.id,)),
            obj.user.email
        )
    email.allow_tags = True
    email.short_description = 'Profile (view/edit)'

    def email_auxiliary(self, obj):
        return get_email_auxiliary(obj.user)

    def registration_type(self, obj):
        try:
            reg_type = '<a href="%s">%s</a>' % (
                reverse(
                    "admin:registration_{}_change".format(
                        obj.user.profile.registration_type.lower()
{'fraction_non_alphanumeric': 0.11101973684210527, 'fraction_numerical': 0.004464285714285714, 'mean_word_length': 3.124515503875969, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '771105', 'n_tokens_mistral': 2592, 'n_tokens_neox': 2491, 'n_words': 539}