<commit_before># -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.contrib import admin
from . import models
from crm.models import Person, PersonState
from organizer.admin import admin_site

def signup_approver(modeladmin, request, queryset):
    for signup in queryset:
        person, _ = Person.objects.update_or_create(email=signup.email)
        if signup.event is not None:
            event = signup.event
            event.attendees.add(person)
            event.save()
        signup.approved = True
        signup.save()
signup_approver.short_description = "Approve selected signups"

class SignupAdmin(admin.ModelAdmin):
    actions = [
        signup_approver
    ]

    list_display = [
        'email', 'created', 'event', 'approved'
    ]
    search_fields = [
        'email', 'event__name'
    ]
    list_filter = ('approved', ('event', admin.RelatedOnlyFieldListFilter))
    raw_id_fields = ('event',)

class StatusAdmin(admin.ModelAdmin):
    list_display = [
        'person', 'component', 'created', 'success'
    ]

    list_filter = ('component', 'success')
    readonly_fields = ('message','created')

def disable_components(modeladmin, request, queryset):
    queryset.update(enabled=False)
disable_components.short_description = "Disable selected components"

def enable_components(modeladmin, request, queryset):
    queryset.update(enabled=False)
enable_components.short_description = "Enable selected components"
<commit_msg>[feature] onboarding: admin: support importing signups<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.contrib import admin
from . import models
from crm.models import Person, PersonState
from events.models import Event
from organizer.admin import admin_site
from import_export.admin import ImportExportModelAdmin
from import_export import resources

def signup_approver(modeladmin, request, queryset):
    for signup in queryset:
        person, _ = Person.objects.update_or_create(email=signup.email)
        if signup.event is not None:
            event = signup.event
            event.attendees.add(person)
            event.save()
        signup.approved = True
        signup.save()
signup_approver.short_description = "Approve selected signups"

class EventSignupResource(resources.ModelResource):
    class Meta:
        model = models.Signup
        fields = ('email', 'address', 'phone', 'event')
        import_id_fields = ('email', 'event')

class SignupAdmin(ImportExportModelAdmin):
    resource_class = EventSignupResource

    actions = [
        signup_approver
    ]

    list_display = [
        'email', 'created', 'event', 'approved'
    ]
    search_fields = [
        'email', 'event__name'
    ]
    list_filter = ('approved', ('event', admin.RelatedOnlyFieldListFilter))
    raw_id_fields = ('event',)

class StatusAdmin(admin.ModelAdmin):
    list_display = [
        'person', 'component', 'created', 'success'
    ]

    list_filter = ('component', 'success')
    readonly_fields = ('message','created')

def disable_components(modeladmin, request, queryset):
    queryset.update(enabled=False)
disable_components.short_description = "Disable selected components"

def enable_components(modeladmin, request, queryset):
    queryset.update(enabled=False)
enable_components.short_description = "Enable selected components"

{'fraction_non_alphanumeric': 0.1040616661725467, 'fraction_numerical': 0.0005929439667951378, 'mean_word_length': 3.7454289732770745, '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': '4771127', 'n_tokens_mistral': 963, 'n_tokens_neox': 942, 'n_words': 227}