<commit_before>from django.contrib import admin

import datetime

from mptt.admin import MPTTModelAdmin
from fsm_admin.mixins import FSMTransitionMixin

from .inlines import (
    ArrangerInline,
    AwardInline,
    CertificationInline,
    ContestantInline,
    SessionInline,
    PerformerInline,
    PerformerStackedInline,
    DirectorInline,
    GroupInline,
    JudgeInline,
    PerformanceInline,
    ScoreInline,
    RoundInline,
    RankingInline,
    SingerInline,
    SongStackedInline,
    OrganizationInline,
)

from .models import (
    Arranger,
    Award,
    Catalog,
    Chapter,
    Contestant,
    Session,
    Performer,
    Convention,
    Group,
    Judge,
    Organization,
    Performance,
    Person,
    Score,
    Round,
    Song,
    Tune,
    User,
)

import arrow

# from grappelli.forms import GrappelliSortableHiddenMixin
from super_inlines.admin import SuperModelAdmin

@admin.register(Arranger)
class ArrangerAdmin(admin.ModelAdmin):
    list_display = [
        'name',
        'catalog',
        'person',
    ]

@admin.register(Award)
class AwardAdmin(admin.ModelAdmin):
    change_list_template = "admin/change_list_filter_sidebar.html"
    list_display = [
        'name',
        'organization',
        'get_long_name',
        'get_level',
        'kind',
        'long_name',
        'stix_name',
    ]

    list_filter = [
        'status',
        'kind',
        'organization',
    ]

    def get_long_name(self, obj):
        return obj.organization.long_name
    get_long_name.short_description = 'Org Name'
    get_long_name.admin_order_field = 'organization__long_name'

    def get_level(self, obj):
        return obj.organization.get_kind_display()
    get_level.short_description = 'Org Level'
    get_level.admin_order_field = 'organization__level'

@admin.register(Catalog)
class CatalogAdmin(admin.ModelAdmin):
    list_display = [
        'song_name',
        'tune',
        'bhs_id',
        'bhs_songname',
        'bhs_arranger',
    ]

@admin.register(Chapter)
class ChapterAdmin(admin.ModelAdmin):
    search_fields = (
        'name',
        'code',
    )

    list_display = (
        'name',
        'organization',
        'code',
        # 'status',
        # 'status_monitor',
        # 'location',
        # 'website',
        # 'facebook',
        # 'twitter',
        # 'email',
        # 'phone',
        # 'picture',
    )

    list_filter = (
        'organization',
        'status',
    )

    fields = (
        'name',
        # ('status', 'status_monitor',),
        'organization',
        'location',
        'website',
        'facebook',
        'twitter',
        'email',
        'phone',
        'picture',
        'description',
        'code',
        'notes',
    )

    inlines = [
        GroupInline,
    ]

    readonly_fields = (
        # 'status_monitor',
    )
    save_on_top = True

@admin.register(Contestant)
class ContestantAdmin(admin.ModelAdmin):
    change_list_template = "admin/change_list_filter_sidebar.html"
    search_fields = [
        'name',
    ]
    fields = [
        'name',
        ('status', 'status_monitor',),
        'performer',
        'place',
        'total_score',
    ]
    list_filter = (
        'status',
    )

    autocomplete_lookup_fields = {
        'fk': [
            'performer',
        ]
    }
    readonly_fields = [
        'name',
        'status_monitor',
        'place',
        'total_score',
    ]

    raw_id_fields = [
        'performer',
    ]

@admin.register(Convention)
class ConventionAdmin(FSMTransitionMixin, admin.ModelAdmin):

    def human_range(self, obj):
        if obj.date:
            if obj.date.upper - obj.date.lower == datetime.timedelta(1):
                dates = "{0}".format(
                    arrow.get(obj.date.lower).format('MMMM D, YYYY'),
                )
            else:
                dates = "{0} - {1}".format(
                    arrow.get(obj.date.lower).format('MMMM D'),
                    arrow.get(obj.date.upper).format('MMMM D, YYYY'),
                )
        else:
            dates = obj.date
        return dates
    human_range.short_description = "Dates22"

    fsm_field = [
        'status',
    ]

    change_list_template = "admin/change_list_filter_sidebar.html"
    search_fields = (
        'name',
    )

    list_display = (
        'name',
        'status',
        'organization',
        'kind',
        'division',
        # 'date',
        'human_range',
        # 'location',
    )

    fields = (
        'name',
        ('status', 'status_monitor',),
        # 'stix_name',
        # 'stix_div',
        ('location', 'timezone',),
        # 'dates',
        'date',
        'organization',
        'drcj',
        'kind',
        # 'stix_file',
        'division',
    )

    list_filter = (
        'status',
        'kind',
        'year',
        'organization__level',
        'division',
        'organization',
    )

    inlines = [
        SessionInline,
        # OrganizationInline,
    ]

    readonly_fields = (
        'name',
        'status_monitor',
        'year',
    )

    raw_id_fields = [
        'drcj',
    ]

    save_on_top = True

@admin.register(Group)
class GroupAdmin(admin.ModelAdmin):
    search_fields = (
        'name',
        'chapter__name',
    )

    list_display = (
        'name',
        'chapter',
        'status',
        'status_monitor',
        'location',
        'website',
        'facebook',
        'twitter',
        'email',
        'phone',
        'picture',
    )

    fields = (
        'name',
        ('status', 'status_monitor',),
        'kind',
        'organization',
        'chapter',
        'location',
        'website',
        'facebook',
        'twitter',
        'email',
        'phone',
        'picture',
        'description',
        'notes',
    )

    list_filter = (
        'kind',
    )

    inlines = [
        PerformerInline,
    ]

    readonly_fields = (
        'status_monitor',
    )

    raw_id_fields = [
        'chapter',
    ]

    autocomplete_lookup_fields = {
        'fk': [
            'chapter',
        ]
    }

    save_on_top = True

@admin.register(Judge)
class JudgeAdmin(admin.ModelAdmin):
    change_list_template = "admin/change_list_filter_sidebar.html"
    save_on_top = True
    fields = [
        'name',
        ('status', 'status_monitor',),
        'session',
        'person',
        'organization',
        ('category', 'slot',),
    ]

    list_display = [
        'name',
        'status',
        'person',
        'organization',
    ]

    list_filter = (
        'status',
    )

    list_select_related = [
        'organization',
        'session',
        'person',
    ]

    raw_id_fields = (
        'session',
        'person',
    )

    autocomplete_lookup_fields = {
        'fk': [
            'session',
            'person',
        ]
    }

    readonly_fields = [
        'name',
    ]

    inlines = [
        ScoreInline,
    ]

@admin.register(Organization)
class OrganizationAdmin(MPTTModelAdmin):
    fields = [
        'name',
        ('status', 'status_monitor',),
        'parent',
        'kind',
        'code',
        'short_name',
        'long_name',
        'location',
        'website',
        'facebook',
        'twitter',
        'email',
        'phone',
        'picture',
        'description',
        'notes',
    ]

    list_filter = [
        'status',
        'level',
        'kind',
    ]

    readonly_fields = [
        'status_monitor',
    ]

    list_display = [
        'name',
        'short_name',
        'long_name',
        'status',
        'kind',
    ]

    inlines = [
        AwardInline,
    ]

    # ordering = [
    #     'tree_id',
    # ]

@admin.register(Performance)
class PerformanceAdmin(FSMTransitionMixin, SuperModelAdmin):
    fsm_field = [
        'status',
    ]

    save_on_top = True
    change_list_template = "admin/change_list_filter_sidebar.html"

    inlines = [
        SongStackedInline,
        # RoundInline,
    ]
    list_display = [
        'name',
        'status',
        'draw',
        'total_score',
    ]
    list_filter = [
        'status',
        'round',
    ]

    fields = [
        'name',
        ('status', 'status_monitor',),
        'performer',
        ('draw', 'scheduled'),
        ('mus_points', 'prs_points', 'sng_points', 'total_points',),
        ('mus_score', 'prs_score', 'sng_score', 'total_score',),
    ]

    readonly_fields = [
        'name',
        'status_monitor',
        'mus_points',
        'prs_points',
        'sng_points',
        'total_points',
        'mus_score',
        'prs_score',
        'sng_score',
        'total_score',
        'draw',
    ]

    raw_id_fields = (
        'performer',
    )
    autocomplete_lookup_fields = {
        'fk': [
            'performer',
        ]
    }

    search_fields = (
        'name',
    )

@admin.register(Performer)
class PerformerAdmin(FSMTransitionMixin, admin.ModelAdmin):
    fsm_field = [
        'status',
    ]

    change_list_template = "admin/change_list_filter_sidebar.html"

    inlines = [
        SingerInline,
        DirectorInline,
        PerformanceInline,
        ContestantInline,
    ]

    list_display = (
        'name',
        'status',
        'seed',
        'prelim',
        # 'mus_score',
        # 'prs_score',
        # 'sng_score',
        # 'total_score',
        'men',
    )

    search_fields = (
        'name',
    )

    list_filter = (
        'status',
    )

    raw_id_fields = (
        'session',
        'group',
    )

    autocomplete_lookup_fields = {
        'fk': [
            'session',
            'group',
        ]
    }
    fields = (
        'name',
        ('status', 'status_monitor',),
        'session',
        ('group', 'organization',),
        ('seed', 'prelim',),
        ('men',),
        # ('mus_points', 'prs_points', 'sng_points', 'total_points',),
        # ('mus_score', 'prs_score', 'sng_score', 'total_score',),
    )

    readonly_fields = (
        'organization',
        'name',
        'status_monitor',
        'mus_points',
        'prs_points',
        'sng_points',
        'total_points',
        'mus_score',
        'prs_score',
        'sng_score',
        'total_score',
    )

    save_on_top = True

@admin.register(Person)
class PersonAdmin(admin.ModelAdmin):
    search_fields = (
        'name',
    )

    save_on_top = True
    list_display = (
        'name',
        'status',
        'status_monitor',
        'member',
        'location',
        'website',
        'facebook',
        'twitter',
        'email',
        'phone',
        'picture',
        'bhs_member_id',
        'bhs_name',
        'bhs_city',
        'bhs_state',
        'bhs_phone',
        'bhs_email',
    )

    fields = (
        'name',
        ('status', 'status_monitor',),
        'organization',
        'location',
        'website',
        'facebook',
        'twitter',
        'email',
        'phone',
        'member',
        'picture',
        'description',
        'bhs_city',
        'notes',
    )

    list_filter = [
        'status',
    ]

    readonly_fields = (
        'status_monitor',
    )
    inlines = [
        DirectorInline,
        SingerInline,
        ArrangerInline,
        CertificationInline,
    ]

@admin.register(Round)
class RoundAdmin(FSMTransitionMixin, admin.ModelAdmin):
    fsm_field = [
        'status',
    ]

    save_on_top = True
    change_list_template = "admin/change_list_filter_sidebar.html"
    list_display = [
        'name',
        'status',
        'slots',
    ]
    fields = [
        'name',
        ('status', 'status_monitor',),
        ('session', 'kind',),
        ('slots',),
    ]

    readonly_fields = [
        'name',
        'status_monitor',
        'session',
        'kind',
    ]

    list_filter = (
        'status',
    )

    raw_id_fields = (
        'session',
    )

    autocomplete_lookup_fields = {
        'fk': [
            'session',
        ]
    }

    inlines = [
        PerformanceInline,
    ]

    search_fields = [
        'name',
    ]

@admin.register(Score)
class ScoreAdmin(admin.ModelAdmin):
    change_list_template = "admin/change_list_filter_sidebar.html"
    save_on_top = True
    fields = [
        'name',
        # ('status', 'status_monitor',),
        'song',
        'judge',
        'points',
    ]

    readonly_fields = [
        'name',
        # 'status_monitor',
        'song',
        'judge',
    ]

    list_display = [
        'name',
        # 'status',
        'points',
    ]

    # list_filter = [
    #     'status',
    # ]

    raw_id_fields = [
        'song',
        'judge',
    ]

    autocomplete_lookup_fields = {
        'fk': [
            'song',
            'judge',
        ]
    }

    ordering = [
        'song',
        'judge',
    ]

@admin.register(Session)
class SessionAdmin(FSMTransitionMixin, SuperModelAdmin):
    fsm_field = [
        'status',
    ]

    change_list_template = "admin/change_list_filter_sidebar.html"
    save_on_top = True
    fields = [
        'name',
        ('status', 'status_monitor',),
        ('history', 'history_monitor',),
        'convention',
        'kind',
        'administrator',
        # 'organization',
        # 'year',
        # # 'size',
        # 'num_rounds',
    ]

    list_display = [
        'name',
        'status',
        'convention',
        'kind',
        'administrator',
        # 'size',
        # 'num_rounds',
    ]

    list_filter = (
        'status',
        'history',
        'kind',
        'convention__year',
        'organization',
        'administrator',
    )

    raw_id_fields = (
        'convention',
    )

    autocomplete_lookup_fields = {
        'fk': [
            'convention',
        ]
    }

    readonly_fields = [
        'name',
        'status_monitor',
        'history_monitor',
        'organization',
    ]

    inlines = [
        RoundInline,
        PerformerInline,
        JudgeInline,
    ]

@admin.register(Song)
class SongAdmin(admin.ModelAdmin):
    change_list_template = "admin/change_list_filter_sidebar.html"
    save_on_top = True
    list_display = (
        'name',
        # 'status',
        'title',
        # 'tune',
        'mus_points',
        'prs_points',
        'sng_points',
        'total_points'
    )

    search_fields = (
        'name',
        'title',
    )

    fields = [
        'name',
        # ('status', 'status_monitor',),
        'order',
        ('mus_points', 'prs_points', 'sng_points', 'total_points',),
        ('mus_score', 'prs_score', 'sng_score', 'total_score',),
        'title',
        # 'tune',
        # 'catalog',
    ]

    inlines = [
        # ArrangersInline,
        ScoreInline,
    ]

    # list_filter = (
    #     'status',
    # )

    readonly_fields = (
        'name',
        'order',
        'mus_points',
        'prs_points',
        'sng_points',
        'total_points',
        'mus_score',
        'prs_score',
        'sng_score',
        'total_score',
        # 'status_monitor',
    )
    raw_id_fields = (
        'performance',
        # 'tune',
        # 'catalog',
    )
    autocomplete_lookup_fields = {
        'fk': [
            'performance',
            # 'tune',
        ]
    }

    ordering = (
        'name',
        'order',
    )

@admin.register(Tune)
class TuneAdmin(admin.ModelAdmin):
    save_on_top = True
    fields = (
        'name',
    )

    search_fields = (
        'name',
    )

@admin.register(User)
class UserAdmin(admin.ModelAdmin):
    model = User
    save_on_top = True
<commit_msg>Re-enable status<commit_after>from django.contrib import admin

import datetime

from mptt.admin import MPTTModelAdmin
from fsm_admin.mixins import FSMTransitionMixin

from .inlines import (
    ArrangerInline,
    AwardInline,
    CertificationInline,
    ContestantInline,
    SessionInline,
    PerformerInline,
    PerformerStackedInline,
    DirectorInline,
    GroupInline,
    JudgeInline,
    PerformanceInline,
    ScoreInline,
    RoundInline,
    RankingInline,
    SingerInline,
    SongStackedInline,
    OrganizationInline,
)

from .models import (
    Arranger,
    Award,
    Catalog,
    Chapter,
    Contestant,
    Session,
    Performer,
    Convention,
    Group,
    Judge,
    Organization,
    Performance,
    Person,
    Score,
    Round,
    Song,
    Tune,
    User,
)

import arrow

# from grappelli.forms import GrappelliSortableHiddenMixin
from super_inlines.admin import SuperModelAdmin

@admin.register(Arranger)
class ArrangerAdmin(admin.ModelAdmin):
    list_display = [
        'name',
        'catalog',
        'person',
    ]

@admin.register(Award)
class AwardAdmin(admin.ModelAdmin):
    change_list_template = "admin/change_list_filter_sidebar.html"
    list_display = [
        'name',
        'organization',
        'get_long_name',
        'get_level',
        'kind',
        'long_name',
        'stix_name',
    ]

    list_filter = [
        'status',
        'kind',
        'organization',
    ]

    def get_long_name(self, obj):
        return obj.organization.long_name
    get_long_name.short_description = 'Org Name'
    get_long_name.admin_order_field = 'organization__long_name'

    def get_level(self, obj):
        return obj.organization.get_kind_display()
    get_level.short_description = 'Org Level'
    get_level.admin_order_field = 'organization__level'

@admin.register(Catalog)
class CatalogAdmin(admin.ModelAdmin):
    list_display = [
        'song_name',
        'tune',
        'bhs_id',
        'bhs_songname',
        'bhs_arranger',
    ]

@admin.register(Chapter)
class ChapterAdmin(admin.ModelAdmin):
    search_fields = (
        'name',
        'code',
    )

    list_display = (
        'name',
        'organization',
        'code',
        'status',
        # 'status_monitor',
        # 'location',
        # 'website',
        # 'facebook',
        # 'twitter',
        # 'email',
        # 'phone',
        # 'picture',
    )

    list_filter = (
        'organization',
        'status',
    )

    fields = (
        'name',
        ('status', 'status_monitor',),
        'organization',
        'location',
        'website',
        'facebook',
        'twitter',
        'email',
        'phone',
        'picture',
        'description',
        'code',
        'notes',
    )

    inlines = [
        GroupInline,
    ]

    readonly_fields = (
        'status_monitor',
    )
    save_on_top = True

@admin.register(Contestant)
class ContestantAdmin(admin.ModelAdmin):
    change_list_template = "admin/change_list_filter_sidebar.html"
    search_fields = [
        'name',
    ]
    fields = [
        'name',
        ('status', 'status_monitor',),
        'performer',
        'place',
        'total_score',
    ]
    list_filter = (
        'status',
    )

    autocomplete_lookup_fields = {
        'fk': [
            'performer',
        ]
    }
    readonly_fields = [
        'name',
        'status_monitor',
        'place',
        'total_score',
    ]

    raw_id_fields = [
        'performer',
    ]

@admin.register(Convention)
class ConventionAdmin(FSMTransitionMixin, admin.ModelAdmin):

    def human_range(self, obj):
        if obj.date:
            if obj.date.upper - obj.date.lower == datetime.timedelta(1):
                dates = "{0}".format(
                    arrow.get(obj.date.lower).format('MMMM D, YYYY'),
                )
            else:
                dates = "{0} - {1}".format(
                    arrow.get(obj.date.lower).format('MMMM D'),
                    arrow.get(obj.date.upper).format('MMMM D, YYYY'),
                )
        else:
            dates = obj.date
        return dates
    human_range.short_description = "Dates22"

    fsm_field = [
        'status',
    ]

    change_list_template = "admin/change_list_filter_sidebar.html"
    search_fields = (
        'name',
    )

    list_display = (
        'name',
        'status',
        'organization',
        'kind',
        'division',
        # 'date',
        'human_range',
        # 'location',
    )

    fields = (
        'name',
        ('status', 'status_monitor',),
        # 'stix_name',
        # 'stix_div',
        ('location', 'timezone',),
        # 'dates',
        'date',
        'organization',
        'drcj',
        'kind',
        # 'stix_file',
        'division',
    )

    list_filter = (
        'status',
        'kind',
        'year',
        'organization__level',
        'division',
        'organization',
    )

    inlines = [
        SessionInline,
        # OrganizationInline,
    ]

    readonly_fields = (
        'name',
        'status_monitor',
        'year',
    )

    raw_id_fields = [
        'drcj',
    ]

    save_on_top = True

@admin.register(Group)
class GroupAdmin(admin.ModelAdmin):
    search_fields = (
        'name',
        'chapter__name',
    )

    list_display = (
        'name',
        'chapter',
        'status',
        'status_monitor',
        'location',
        'website',
        'facebook',
        'twitter',
        'email',
        'phone',
        'picture',
    )

    fields = (
        'name',
        ('status', 'status_monitor',),
        'kind',
        'organization',
        'chapter',
        'location',
        'website',
        'facebook',
        'twitter',
        'email',
        'phone',
        'picture',
        'description',
        'notes',
    )

    list_filter = (
        'kind',
    )

    inlines = [
        PerformerInline,
    ]

    readonly_fields = (
        'status_monitor',
    )

    raw_id_fields = [
        'chapter',
    ]

    autocomplete_lookup_fields = {
        'fk': [
            'chapter',
        ]
    }

    save_on_top = True

@admin.register(Judge)
class JudgeAdmin(admin.ModelAdmin):
    change_list_template = "admin/change_list_filter_sidebar.html"
    save_on_top = True
    fields = [
        'name',
        ('status', 'status_monitor',),
        'session',
        'person',
        'organization',
        ('category', 'slot',),
    ]

    list_display = [
        'name',
        'status',
        'person',
        'organization',
    ]

    list_filter = (
        'status',
    )

    list_select_related = [
        'organization',
        'session',
        'person',
    ]

    raw_id_fields = (
        'session',
        'person',
    )

    autocomplete_lookup_fields = {
        'fk': [
            'session',
            'person',
        ]
    }

    readonly_fields = [
        'name',
    ]

    inlines = [
        ScoreInline,
    ]

@admin.register(Organization)
class OrganizationAdmin(MPTTModelAdmin):
    fields = [
        'name',
        ('status', 'status_monitor',),
        'parent',
        'kind',
        'code',
        'short_name',
        'long_name',
        'location',
        'website',
        'facebook',
        'twitter',
        'email',
        'phone',
        'picture',
        'description',
        'notes',
    ]

    list_filter = [
        'status',
        'level',
        'kind',
    ]

    readonly_fields = [
        'status_monitor',
    ]

    list_display = [
        'name',
        'short_name',
        'long_name',
        'status',
        'kind',
    ]

    inlines = [
        AwardInline,
    ]

    # ordering = [
    #     'tree_id',
    # ]

@admin.register(Performance)
class PerformanceAdmin(FSMTransitionMixin, SuperModelAdmin):
    fsm_field = [
        'status',
    ]

    save_on_top = True
    change_list_template = "admin/change_list_filter_sidebar.html"

    inlines = [
        SongStackedInline,
        # RoundInline,
    ]
    list_display = [
        'name',
        'status',
        'draw',
        'total_score',
    ]
    list_filter = [
        'status',
        'round',
    ]

    fields = [
        'name',
        ('status', 'status_monitor',),
        'performer',
        ('draw', 'scheduled'),
        ('mus_points', 'prs_points', 'sng_points', 'total_points',),
        ('mus_score', 'prs_score', 'sng_score', 'total_score',),
    ]

    readonly_fields = [
        'name',
        'status_monitor',
        'mus_points',
        'prs_points',
        'sng_points',
        'total_points',
        'mus_score',
        'prs_score',
        'sng_score',
        'total_score',
        'draw',
    ]

    raw_id_fields = (
        'performer',
    )
    autocomplete_lookup_fields = {
        'fk': [
            'performer',
        ]
    }

    search_fields = (
        'name',
    )

@admin.register(Performer)
class PerformerAdmin(FSMTransitionMixin, admin.ModelAdmin):
    fsm_field = [
        'status',
    ]

    change_list_template = "admin/change_list_filter_sidebar.html"

    inlines = [
        SingerInline,
        DirectorInline,
        PerformanceInline,
        ContestantInline,
    ]

    list_display = (
        'name',
        'status',
        'seed',
        'prelim',
        # 'mus_score',
        # 'prs_score',
        # 'sng_score',
        # 'total_score',
        'men',
    )

    search_fields = (
        'name',
    )

    list_filter = (
        'status',
    )

    raw_id_fields = (
        'session',
        'group',
    )

    autocomplete_lookup_fields = {
        'fk': [
            'session',
            'group',
        ]
    }
    fields = (
        'name',
        ('status', 'status_monitor',),
        'session',
        ('group', 'organization',),
        ('seed', 'prelim',),
        ('men',),
        # ('mus_points', 'prs_points', 'sng_points', 'total_points',),
        # ('mus_score', 'prs_score', 'sng_score', 'total_score',),
    )

    readonly_fields = (
        'organization',
        'name',
        'status_monitor',
        'mus_points',
        'prs_points',
        'sng_points',
        'total_points',
        'mus_score',
        'prs_score',
        'sng_score',
        'total_score',
    )

    save_on_top = True

@admin.register(Person)
class PersonAdmin(admin.ModelAdmin):
    search_fields = (
        'name',
    )

    save_on_top = True
    list_display = (
        'name',
        'status',
        'status_monitor',
        'member',
        'location',
        'website',
        'facebook',
        'twitter',
        'email',
        'phone',
        'picture',
        'bhs_member_id',
        'bhs_name',
        'bhs_city',
        'bhs_state',
        'bhs_phone',
        'bhs_email',
    )

    fields = (
        'name',
        ('status', 'status_monitor',),
        'organization',
        'location',
        'website',
        'facebook',
        'twitter',
        'email',
        'phone',
        'member',
        'picture',
        'description',
        'bhs_city',
        'notes',
    )

    list_filter = [
        'status',
    ]

    readonly_fields = (
        'status_monitor',
    )
    inlines = [
        DirectorInline,
        SingerInline,
        ArrangerInline,
        CertificationInline,
    ]

@admin.register(Round)
class RoundAdmin(FSMTransitionMixin, admin.ModelAdmin):
    fsm_field = [
        'status',
    ]

    save_on_top = True
    change_list_template = "admin/change_list_filter_sidebar.html"
    list_display = [
        'name',
        'status',
        'slots',
    ]
    fields = [
        'name',
        ('status', 'status_monitor',),
        ('session', 'kind',),
        ('slots',),
    ]

    readonly_fields = [
        'name',
        'status_monitor',
        'session',
        'kind',
    ]

    list_filter = (
        'status',
    )

    raw_id_fields = (
        'session',
    )

    autocomplete_lookup_fields = {
        'fk': [
            'session',
        ]
    }

    inlines = [
        PerformanceInline,
    ]

    search_fields = [
        'name',
    ]

@admin.register(Score)
class ScoreAdmin(admin.ModelAdmin):
    change_list_template = "admin/change_list_filter_sidebar.html"
    save_on_top = True
    fields = [
        'name',
        # ('status', 'status_monitor',),
        'song',
        'judge',
        'points',
    ]

    readonly_fields = [
        'name',
        # 'status_monitor',
        'song',
        'judge',
    ]

    list_display = [
        'name',
        # 'status',
        'points',
    ]

    # list_filter = [
    #     'status',
    # ]

    raw_id_fields = [
        'song',
        'judge',
    ]

    autocomplete_lookup_fields = {
        'fk': [
            'song',
            'judge',
        ]
    }

    ordering = [
        'song',
        'judge',
    ]

@admin.register(Session)
class SessionAdmin(FSMTransitionMixin, SuperModelAdmin):
    fsm_field = [
        'status',
    ]

    change_list_template = "admin/change_list_filter_sidebar.html"
    save_on_top = True
    fields = [
        'name',
        ('status', 'status_monitor',),
        ('history', 'history_monitor',),
        'convention',
        'kind',
        'administrator',
        # 'organization',
        # 'year',
        # # 'size',
        # 'num_rounds',
    ]

    list_display = [
        'name',
        'status',
        'convention',
        'kind',
        'administrator',
        # 'size',
        # 'num_rounds',
    ]

    list_filter = (
        'status',
        'history',
        'kind',
        'convention__year',
        'organization',
        'administrator',
    )

    raw_id_fields = (
        'convention',
    )

    autocomplete_lookup_fields = {
        'fk': [
            'convention',
        ]
    }

    readonly_fields = [
        'name',
        'status_monitor',
        'history_monitor',
        'organization',
    ]

    inlines = [
        RoundInline,
        PerformerInline,
        JudgeInline,
    ]

@admin.register(Song)
class SongAdmin(admin.ModelAdmin):
    change_list_template = "admin/change_list_filter_sidebar.html"
    save_on_top = True
    list_display = (
        'name',
        # 'status',
        'title',
        # 'tune',
        'mus_points',
        'prs_points',
        'sng_points',
        'total_points'
    )

    search_fields = (
        'name',
        'title',
    )

    fields = [
        'name',
        # ('status', 'status_monitor',),
        'order',
        ('mus_points', 'prs_points', 'sng_points', 'total_points',),
        ('mus_score', 'prs_score', 'sng_score', 'total_score',),
        'title',
        # 'tune',
        # 'catalog',
    ]

    inlines = [
        # ArrangersInline,
        ScoreInline,
    ]

    # list_filter = (
    #     'status',
    # )

    readonly_fields = (
        'name',
        'order',
        'mus_points',
        'prs_points',
        'sng_points',
        'total_points',
        'mus_score',
        'prs_score',
        'sng_score',
        'total_score',
        # 'status_monitor',
    )
    raw_id_fields = (
        'performance',
        # 'tune',
        # 'catalog',
    )
    autocomplete_lookup_fields = {
        'fk': [
            'performance',
            # 'tune',
        ]
    }

    ordering = (
        'name',
        'order',
    )

@admin.register(Tune)
class TuneAdmin(admin.ModelAdmin):
    save_on_top = True
    fields = (
        'name',
    )

    search_fields = (
        'name',
    )

@admin.register(User)
class UserAdmin(admin.ModelAdmin):
    model = User
    save_on_top = True
<|endoftext|>


<commit_before>#############################################################################
#
# Copyright 2008 Tungsten Graphics, Inc.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################

"""C basic types"""

import debug

all_types = {}

class Type:

    def __init__(self, name):
        self.name = name

    def __str__(self):
        return self.name

    def identifier(self):
        return self.name.replace(' ', '_')

    def isoutput(self):
        return False

    def decl(self):
        pass

    def impl(self):
        pass

    def dump(self, instance):
        raise NotImplementedError

    def wrap_instance(self, instance):
        pass

    def unwrap_instance(self, instance):
        pass

class _Void(Type):

    def __init__(self):
        Type.__init__(self, "void")

Void = _Void()

class Concrete(Type):

    def __init__(self, name):
        for char in name:
            assert char.isalnum() or char in '_ '

        Type.__init__(self, name)

        assert self.name not in all_types
        if self.name not in all_types:
            all_types[self.name] = self

    def decl(self):
        print 'void Dump%s(const %s &value);' % (self.identifier(), str(self))

    def impl(self):
        print 'void Dump%s(const %s &value) {' % (self.identifier(), str(self))
        self._dump("value");
        print '}'
        print

    def _dump(self, instance):
        raise NotImplementedError

    def dump(self, instance):
        print '    Dump%s(%s);' % (self.identifier(), instance)

class Intrinsic(Concrete):

    def __init__(self, expr, format, name = None):
        if name is None:
            name = expr
        Concrete.__init__(self, name)
        self.expr = expr
        self.format = format

    def _dump(self, instance):
        print '    Log::TextF("%s", %s);' % (self.format, instance)

    def __str__(self):
        return self.expr

class Const(Type):

    def __init__(self, type):
        Type.__init__(self, 'C' + type.name)
        self.type = type

    def dump(self, instance):
        self.type.dump(instance)

    def __str__(self):
        return "const " + str(self.type)

class Pointer(Type):

    def __init__(self, type):
        Type.__init__(self, 'P' + type.name)
        self.type = type

    def __str__(self):
        return str(self.type) + " *"

    def dump(self, instance):
        print '    if(%s) {' % instance
        print '        Log::BeginReference("%s", %s);' % (self.type, instance)
        try:
            self.type.dump("*" + instance)
        except NotImplementedError:
            pass
        print '        Log::EndReference();'
        print '    }'
        print '    else'
        print '        Log::Text("NULL");'

    def wrap_instance(self, instance):
        self.type.wrap_instance("*" + instance)

    def unwrap_instance(self, instance):
        self.type.wrap_instance("*" + instance)

def ConstPointer(type):
    return Pointer(Const(type))

class OutPointer(Pointer):

    def isoutput(self):
        return True

class Enum(Concrete):

    def __init__(self, name, values):
        Concrete.__init__(self, name)
        self.values = values

    def _dump(self, instance):
        print '    switch(%s) {' % instance
        for value in self.values:
            print '    case %s:' % value
            print '        Log::Text("%s");' % value
            print '        break;'
        print '    default:'
        print '        Log::TextF("%%i", %s);' % instance
        print '        break;'
        print '    }'

class FakeEnum(Enum):

    __seq = 0

    def __init__(self, type, values):
        FakeEnum.__seq += 1
        Enum.__init__(self, type.name + str(FakeEnum.__seq), values)
        self.type = type

    def __str__(self):
        return str(self.type)

class Flags(Concrete):

    __seq = 0

    def __init__(self, type, values):
        Flags.__seq += 1
        Concrete.__init__(self, type.name + str(Flags.__seq))
        self.type = type
        self.values = values

    def __str__(self):
        return str(self.type)

    def _dump(self, instance):
        print '    bool l_First = TRUE;'
        print '    %s l_Value = %s;' % (self.type, instance)
        for value in self.values:
            print '    if((l_Value & %s) == %s) {' % (value, value)
            print '        if(!l_First)'
            print '            Log::Text(" | ");'
            print '        Log::Text("%s");' % value
            print '        l_Value &= ~%s;' % value
            print '        l_First = FALSE;'
            print '    }'
        print '    if(l_Value || l_First) {'
        print '        if(!l_First)'
        print '            Log::Text(" | ");'
        self.type.dump("l_Value");
        print '    }'

class Struct(Concrete):

    def __init__(self, name, members):
        Concrete.__init__(self, name)
        self.members = members

    def _dump(self, instance):
        for type, name in self.members:
            print '    Log::BeginElement("%s", "%s");' % (type, name)
            type.dump('(%s).%s' % (instance, name))
            print '    Log::EndElement();'

class Alias(Type):

    def __init__(self, name, type):
        Type.__init__(self, name)
        self.type = type

    def dump(self, instance):
        self.type.dump(instance)

class Function:

    def __init__(self, type, name, args, call = '__stdcall', fail = None):
        self.type = type
        self.name = name
        self.args = args
        self.call = call
        self.fail = fail

    def prototype(self, name=None):
        if name is not None:
            name = name.strip()
        else:
            name = self.name
        s = name
        if self.call:
            s = self.call + ' ' + s
        if name.startswith('*'):
            s = '(' + s + ')'
        s = str(self.type) + ' ' + s
        s += "("
        if self.args:
            s += ", ".join(["%s %s" % (type, name) for type, name in self.args])
        else:
            s += "void"
        s += ")"
        return s

    def pointer_type(self):
        return 'P' + self.name

    def pointer_value(self):
        return 'p' + self.name

    def wrap_decl(self):
        ptype = self.pointer_type()
        pvalue = self.pointer_value()
        print 'typedef ' + self.prototype('* %s' % ptype) + ';'
        print 'static %s %s = NULL;' % (ptype, pvalue)
        print

    def get_true_pointer(self):
        raise NotImplementedError

    def fail_impl(self):
        if self.fail is not None:
            assert self.type is not Void
            print '            return %s;' % self.fail
        else:
            print '            ExitProcess(0);'

    def wrap_impl(self):
        pvalue = self.pointer_value()
        print self.prototype() + ' {'
        if self.type is Void:
            result = ''
        else:
            print '    %s result;' % self.type
            result = 'result = '
        self.get_true_pointer()
        print '    Log::BeginCall("%s");' % (self.name)
        for type, name in self.args:
            if not type.isoutput():
                type.unwrap_instance(name)
                print '    Log::BeginArg("%s", "%s");' % (type, name)
                type.dump(name)
                print '    Log::EndArg();'
        print '    %s%s(%s);' % (result, pvalue, ', '.join([str(name) for type, name in self.args]))
        for type, name in self.args:
            if type.isoutput():
                print '    Log::BeginArg("%s", "%s");' % (type, name)
                type.dump(name)
                print '    Log::EndArg();'
                type.wrap_instance(name)
        if self.type is not Void:
            print '    Log::BeginReturn("%s");' % self.type
            self.type.dump("result")
            print '    Log::EndReturn();'
            self.type.wrap_instance('result')
        print '    Log::EndCall();'
        self.post_call_impl()
        if self.type is not Void:
            print '    return result;'
        print '}'
        print

    def post_call_impl(self):
        pass

class Interface(Type):

    def __init__(self, name, base=None):
        Type.__init__(self, name)
        self.base = base
        self.methods = []

    def itermethods(self):
        if self.base is not None:
            for method in self.base.itermethods():
                yield method
        for method in self.methods:
            yield method
        raise StopIteration

    def wrap_name(self):
        return "Wrap" + self.name

    def wrap_pre_decl(self):
        print "class %s;" % self.wrap_name()

    def wrap_decl(self):
        print "class %s : public %s " % (self.wrap_name(), self.name)
        print "{"
        print "public:"
        print "    %s(%s * pInstance);" % (self.wrap_name(), self.name)
        print "    virtual ~%s();" % self.wrap_name()
        print
        for method in self.itermethods():
            print "    " + method.prototype() + ";"
        print
        #print "private:"
        print "    %s * m_pInstance;" % (self.name,)
        print "};"
        print

    def wrap_impl(self):
        print '%s::%s(%s * pInstance) {' % (self.wrap_name(), self.wrap_name(), self.name)
        print '    m_pInstance = pInstance;'
        print '}'
        print
        print '%s::~%s() {' % (self.wrap_name(), self.wrap_name())
        print '}'
        print
        for method in self.itermethods():
            print method.prototype(self.wrap_name() + '::' + method.name) + ' {'
            if method.type is Void:
                result = ''
            else:
                print '    %s result;' % method.type
                result = 'result = '
            print '    Log::BeginCall("%s");' % (self.name + '::' + method.name)
            print '    Log::BeginArg("%s *", "this");' % self.name
            print '    Log::BeginReference("%s", m_pInstance);' % self.name
            print '    Log::EndReference();'
            print '    Log::EndArg();'
            for type, name in method.args:
                if not type.isoutput():
                    type.unwrap_instance(name)
                    print '    Log::BeginArg("%s", "%s");' % (type, name)
                    type.dump(name)
                    print '    Log::EndArg();'
            print '    %sm_pInstance->%s(%s);' % (result, method.name, ', '.join([str(name) for type, name in method.args]))
            for type, name in method.args:
                if type.isoutput():
                    print '    Log::BeginArg("%s", "%s");' % (type, name)
                    type.dump(name)
                    print '    Log::EndArg();'
                    type.wrap_instance(name)
            if method.type is not Void:
                print '    Log::BeginReturn("%s");' % method.type
                method.type.dump("result")
                print '    Log::EndReturn();'
                method.type.wrap_instance('result')
            print '    Log::EndCall();'
            if method.name == 'QueryInterface':
                print '    if(*ppvObj == m_pInstance)'
                print '        *ppvObj = this;'
            if method.name == 'Release':
                assert method.type is not Void
                print '    if(!result)'
                print '        delete this;'
            if method.type is not Void:
                print '    return result;'
            print '}'
            print
        print

class Method(Function):

    def __init__(self, type, name, args):
        Function.__init__(self, type, name, args)

towrap = []

class WrapPointer(Pointer):

    def __init__(self, type):
        Pointer.__init__(self, type)
        if type not in towrap:
            towrap.append(type)

    def wrap_instance(self, instance):
        print "    if(%s)" % instance
        print "        %s = new %s(%s);" % (instance, self.type.wrap_name(), instance)

    def unwrap_instance(self, instance):
        print "    if(%s)" % instance
        print "        %s = static_cast<%s *>(%s)->m_pInstance;" % (instance, self.type.wrap_name(), instance)

class _String(Type):

    def __init__(self):
        Type.__init__(self, "String")

    def __str__(self):
        return "const char *"

    def dump(self, instance):
        print '    Log::DumpString((const char *)%s);' % instance

String = _String()

class _WString(Type):

    def __init__(self):
        Type.__init__(self, "WString")

    def __str__(self):
        return "const wchar_t *"

    def dump(self, instance):
        print '    Log::DumpWString(%s);' % instance

WString = _WString()

SChar = Intrinsic("signed char", "%i")
UChar = Intrinsic("unsigned char", "%u")
Short = Intrinsic("short", "%i")
Int = Intrinsic("int", "%i")
Long = Intrinsic("long", "%li")
UShort = Intrinsic("unsigned short", "%u")
UInt = Intrinsic("unsigned int", "%u")
ULong = Intrinsic("unsigned long", "%lu")
Float = Intrinsic("float", "%f")
Double = Intrinsic("double", "%f")

def wrap():
    for type in all_types.itervalues():
        type.decl()
    print
    for type in all_types.itervalues():
        type.impl()
    print
    for type in towrap:
        type.wrap_pre_decl()
    print
    for type in towrap:
        type.wrap_decl()
    print
    for type in towrap:
        type.wrap_impl()
    print
<commit_msg>Allow failure handling for functions without return value.<commit_after>#############################################################################
#
# Copyright 2008 Tungsten Graphics, Inc.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################

"""C basic types"""

import debug

all_types = {}

class Type:

    def __init__(self, name):
        self.name = name

    def __str__(self):
        return self.name

    def identifier(self):
        return self.name.replace(' ', '_')

    def isoutput(self):
        return False

    def decl(self):
        pass

    def impl(self):
        pass

    def dump(self, instance):
        raise NotImplementedError

    def wrap_instance(self, instance):
        pass

    def unwrap_instance(self, instance):
        pass

class _Void(Type):

    def __init__(self):
        Type.__init__(self, "void")

Void = _Void()

class Concrete(Type):

    def __init__(self, name):
        for char in name:
            assert char.isalnum() or char in '_ '

        Type.__init__(self, name)

        assert self.name not in all_types
        if self.name not in all_types:
            all_types[self.name] = self

    def decl(self):
        print 'void Dump%s(const %s &value);' % (self.identifier(), str(self))

    def impl(self):
        print 'void Dump%s(const %s &value) {' % (self.identifier(), str(self))
        self._dump("value");
        print '}'
        print

    def _dump(self, instance):
        raise NotImplementedError

    def dump(self, instance):
        print '    Dump%s(%s);' % (self.identifier(), instance)

class Intrinsic(Concrete):

    def __init__(self, expr, format, name = None):
        if name is None:
            name = expr
        Concrete.__init__(self, name)
        self.expr = expr
        self.format = format

    def _dump(self, instance):
        print '    Log::TextF("%s", %s);' % (self.format, instance)

    def __str__(self):
        return self.expr

class Const(Type):

    def __init__(self, type):
        Type.__init__(self, 'C' + type.name)
        self.type = type

    def dump(self, instance):
        self.type.dump(instance)

    def __str__(self):
        return "const " + str(self.type)

class Pointer(Type):

    def __init__(self, type):
        Type.__init__(self, 'P' + type.name)
        self.type = type

    def __str__(self):
        return str(self.type) + " *"

    def dump(self, instance):
        print '    if(%s) {' % instance
        print '        Log::BeginReference("%s", %s);' % (self.type, instance)
        try:
            self.type.dump("*" + instance)
        except NotImplementedError:
            pass
        print '        Log::EndReference();'
        print '    }'
        print '    else'
        print '        Log::Text("NULL");'

    def wrap_instance(self, instance):
        self.type.wrap_instance("*" + instance)

    def unwrap_instance(self, instance):
        self.type.wrap_instance("*" + instance)

def ConstPointer(type):
    return Pointer(Const(type))

class OutPointer(Pointer):

    def isoutput(self):
        return True

class Enum(Concrete):

    def __init__(self, name, values):
        Concrete.__init__(self, name)
        self.values = values

    def _dump(self, instance):
        print '    switch(%s) {' % instance
        for value in self.values:
            print '    case %s:' % value
            print '        Log::Text("%s");' % value
            print '        break;'
        print '    default:'
        print '        Log::TextF("%%i", %s);' % instance
        print '        break;'
        print '    }'

class FakeEnum(Enum):

    __seq = 0

    def __init__(self, type, values):
        FakeEnum.__seq += 1
        Enum.__init__(self, type.name + str(FakeEnum.__seq), values)
        self.type = type

    def __str__(self):
        return str(self.type)

class Flags(Concrete):

    __seq = 0

    def __init__(self, type, values):
        Flags.__seq += 1
        Concrete.__init__(self, type.name + str(Flags.__seq))
        self.type = type
        self.values = values

    def __str__(self):
        return str(self.type)

    def _dump(self, instance):
        print '    bool l_First = TRUE;'
        print '    %s l_Value = %s;' % (self.type, instance)
        for value in self.values:
            print '    if((l_Value & %s) == %s) {' % (value, value)
            print '        if(!l_First)'
            print '            Log::Text(" | ");'
            print '        Log::Text("%s");' % value
            print '        l_Value &= ~%s;' % value
            print '        l_First = FALSE;'
            print '    }'
        print '    if(l_Value || l_First) {'
        print '        if(!l_First)'
        print '            Log::Text(" | ");'
        self.type.dump("l_Value");
        print '    }'

class Struct(Concrete):

    def __init__(self, name, members):
        Concrete.__init__(self, name)
        self.members = members

    def _dump(self, instance):
        for type, name in self.members:
            print '    Log::BeginElement("%s", "%s");' % (type, name)
            type.dump('(%s).%s' % (instance, name))
            print '    Log::EndElement();'

class Alias(Type):

    def __init__(self, name, type):
        Type.__init__(self, name)
        self.type = type

    def dump(self, instance):
        self.type.dump(instance)

class Function:

    def __init__(self, type, name, args, call = '__stdcall', fail = None):
        self.type = type
        self.name = name
        self.args = args
        self.call = call
        self.fail = fail

    def prototype(self, name=None):
        if name is not None:
            name = name.strip()
        else:
            name = self.name
        s = name
        if self.call:
            s = self.call + ' ' + s
        if name.startswith('*'):
            s = '(' + s + ')'
        s = str(self.type) + ' ' + s
        s += "("
        if self.args:
            s += ", ".join(["%s %s" % (type, name) for type, name in self.args])
        else:
            s += "void"
        s += ")"
        return s

    def pointer_type(self):
        return 'P' + self.name

    def pointer_value(self):
        return 'p' + self.name

    def wrap_decl(self):
        ptype = self.pointer_type()
        pvalue = self.pointer_value()
        print 'typedef ' + self.prototype('* %s' % ptype) + ';'
        print 'static %s %s = NULL;' % (ptype, pvalue)
        print

    def get_true_pointer(self):
        raise NotImplementedError

    def fail_impl(self):
        if self.fail is not None:
            if self.type is Void:
                assert self.fail == ''
                print '            return;'
            else:
                assert self.fail != ''
                print '            return %s;' % self.fail
        else:
            print '            ExitProcess(0);'

    def wrap_impl(self):
        pvalue = self.pointer_value()
        print self.prototype() + ' {'
        if self.type is Void:
            result = ''
        else:
            print '    %s result;' % self.type
            result = 'result = '
        self.get_true_pointer()
        print '    Log::BeginCall("%s");' % (self.name)
        for type, name in self.args:
            if not type.isoutput():
                type.unwrap_instance(name)
                print '    Log::BeginArg("%s", "%s");' % (type, name)
                type.dump(name)
                print '    Log::EndArg();'
        print '    %s%s(%s);' % (result, pvalue, ', '.join([str(name) for type, name in self.args]))
        for type, name in self.args:
            if type.isoutput():
                print '    Log::BeginArg("%s", "%s");' % (type, name)
                type.dump(name)
                print '    Log::EndArg();'
                type.wrap_instance(name)
        if self.type is not Void:
            print '    Log::BeginReturn("%s");' % self.type
            self.type.dump("result")
            print '    Log::EndReturn();'
            self.type.wrap_instance('result')
        print '    Log::EndCall();'
        self.post_call_impl()
        if self.type is not Void:
            print '    return result;'
        print '}'
        print

    def post_call_impl(self):
        pass

class Interface(Type):

    def __init__(self, name, base=None):
        Type.__init__(self, name)
        self.base = base
        self.methods = []

    def itermethods(self):
        if self.base is not None:
            for method in self.base.itermethods():
                yield method
        for method in self.methods:
            yield method
        raise StopIteration

    def wrap_name(self):
        return "Wrap" + self.name

    def wrap_pre_decl(self):
        print "class %s;" % self.wrap_name()

    def wrap_decl(self):
        print "class %s : public %s " % (self.wrap_name(), self.name)
        print "{"
        print "public:"
        print "    %s(%s * pInstance);" % (self.wrap_name(), self.name)
        print "    virtual ~%s();" % self.wrap_name()
        print
        for method in self.itermethods():
            print "    " + method.prototype() + ";"
        print
        #print "private:"
        print "    %s * m_pInstance;" % (self.name,)
        print "};"
        print

    def wrap_impl(self):
        print '%s::%s(%s * pInstance) {' % (self.wrap_name(), self.wrap_name(), self.name)
        print '    m_pInstance = pInstance;'
        print '}'
        print
        print '%s::~%s() {' % (self.wrap_name(), self.wrap_name())
        print '}'
        print
        for method in self.itermethods():
            print method.prototype(self.wrap_name() + '::' + method.name) + ' {'
            if method.type is Void:
                result = ''
            else:
                print '    %s result;' % method.type
                result = 'result = '
            print '    Log::BeginCall("%s");' % (self.name + '::' + method.name)
            print '    Log::BeginArg("%s *", "this");' % self.name
            print '    Log::BeginReference("%s", m_pInstance);' % self.name
            print '    Log::EndReference();'
            print '    Log::EndArg();'
            for type, name in method.args:
                if not type.isoutput():
                    type.unwrap_instance(name)
                    print '    Log::BeginArg("%s", "%s");' % (type, name)
                    type.dump(name)
                    print '    Log::EndArg();'
            print '    %sm_pInstance->%s(%s);' % (result, method.name, ', '.join([str(name) for type, name in method.args]))
            for type, name in method.args:
                if type.isoutput():
                    print '    Log::BeginArg("%s", "%s");' % (type, name)
                    type.dump(name)
                    print '    Log::EndArg();'
                    type.wrap_instance(name)
            if method.type is not Void:
                print '    Log::BeginReturn("%s");' % method.type
                method.type.dump("result")
                print '    Log::EndReturn();'
                method.type.wrap_instance('result')
            print '    Log::EndCall();'
            if method.name == 'QueryInterface':
                print '    if(*ppvObj == m_pInstance)'
                print '        *ppvObj = this;'
            if method.name == 'Release':
                assert method.type is not Void
                print '    if(!result)'
                print '        delete this;'
            if method.type is not Void:
                print '    return result;'
            print '}'
            print
        print

class Method(Function):

    def __init__(self, type, name, args):
        Function.__init__(self, type, name, args)

towrap = []

class WrapPointer(Pointer):

    def __init__(self, type):
        Pointer.__init__(self, type)
        if type not in towrap:
            towrap.append(type)

    def wrap_instance(self, instance):
        print "    if(%s)" % instance
        print "        %s = new %s(%s);" % (instance, self.type.wrap_name(), instance)

    def unwrap_instance(self, instance):
        print "    if(%s)" % instance
        print "        %s = static_cast<%s *>(%s)->m_pInstance;" % (instance, self.type.wrap_name(), instance)

class _String(Type):

    def __init__(self):
        Type.__init__(self, "String")

    def __str__(self):
        return "const char *"

    def dump(self, instance):
        print '    Log::DumpString((const char *)%s);' % instance

String = _String()

class _WString(Type):

    def __init__(self):
        Type.__init__(self, "WString")

    def __str__(self):
        return "const wchar_t *"

    def dump(self, instance):
        print '    Log::DumpWString(%s);' % instance

WString = _WString()

SChar = Intrinsic("signed char", "%i")
UChar = Intrinsic("unsigned char", "%u")
Short = Intrinsic("short", "%i")
Int = Intrinsic("int", "%i")
Long = Intrinsic("long", "%li")
UShort = Intrinsic("unsigned short", "%u")
UInt = Intrinsic("unsigned int", "%u")
ULong = Intrinsic("unsigned long", "%lu")
Float = Intrinsic("float", "%f")
Double = Intrinsic("double", "%f")

def wrap():
    for type in all_types.itervalues():
        type.decl()
    print
    for type in all_types.itervalues():
        type.impl()
    print
    for type in towrap:
        type.wrap_pre_decl()
    print
    for type in towrap:
        type.wrap_decl()
    print
    for type in towrap:
        type.wrap_impl()
    print
<|endoftext|>


<commit_before># import logging
# log = logging.getLogger(__name__)

from django.contrib import admin

from django_object_actions import (
    DjangoObjectActions,
    takes_instance_or_queryset,
)

from easy_select2 import select2_modelform

from .models import (
    Convention,
    Contest,
    Contestant,
    Group,
    Singer,
    Note,
    District,
    Director,
    Judge,
    Song,
)

class ContestantInline(admin.TabularInline):
    form = select2_modelform(
        Contestant,
        attrs={'width': '250px'},
    )
    model = Contestant
    extra = 0
    show_change_link = True
    fields = (
        'contest',
        'group',
        # 'director',
        # 'district',
        # 'tenor',
        # 'lead',
        # 'baritone',
        # 'bass',
        # 'prelim',
        # 'seed',
        # 'score',
        # 'place',
    )

@admin.register(Convention)
class ConventionAdmin(admin.ModelAdmin):
    form = select2_modelform(
        Convention,
        attrs={'width': '250px'},
    )

    list_display = (
        'name',
        'location',
        'dates',
        'kind',
        'year',
        'district',
        'is_active',
    )

    fields = (
        'is_active',
        'name',
        'location',
        'dates',
        'timezone',
        'district',
        'kind',
        'year',
    )

    list_filter = (
        'kind',
        'year',
        'district',
    )

    readonly_fields = (
        'name',
    )

    save_on_top = True

@admin.register(Contest)
class ContestAdmin(DjangoObjectActions, admin.ModelAdmin):
    # @takes_instance_or_queryset
    # def import_scores(self, request, queryset):
    #     for obj in queryset:
    #         obj.import_scores()
    # import_scores.label = 'Import Scores'
    form = select2_modelform(
        Contest,
        attrs={'width': '250px'},
    )
    save_on_top = True
    # objectactions = [
    #     'import_scores',
    # ]

    # inlines = [
    #     ContestantInline,
    # ]

    list_filter = (
        'level',
        'kind',
        'year',
        'district',
    )

    list_display = (
        'name',
        'district',
        'convention',
        'level',
        'kind',
        'year',
        'panel',
        'scoresheet_pdf',
        'scoresheet_csv',
        'is_active',
    )

    fields = (
        ('is_active', 'is_complete',),
        'name',
        'convention',
        'level',
        'kind',
        'year',
        'district',
        'panel',
        'scoresheet_pdf',
        'scoresheet_csv',
    )

    readonly_fields = (
        'name',
    )

@admin.register(Group)
class GroupAdmin(admin.ModelAdmin):
    form = select2_modelform(
        Group,
        attrs={'width': '250px'},
    )

    search_fields = (
        'name',
    )

    list_display = (
        'name',
        'location',
        'website',
        'facebook',
        'twitter',
        'email',
        'phone',
        'chapter_name',
        'chapter_code',
        # 'bsmdb_id',
        'picture',
    )

    inlines = [
        ContestantInline,
    ]

    list_filter = (
        'kind',
    )

    readonly_fields = (
        'director',
        'lead',
        'tenor',
        'baritone',
        'bass',
    )

    save_on_top = True

@admin.register(Contestant)
class ContestantAdmin(admin.ModelAdmin):
    @takes_instance_or_queryset
    def update_contestants(self, request, queryset):
        for obj in queryset:
            obj.save()
    update_contestants.label = 'Update Contestants'

    form = select2_modelform(
        Contestant,
        attrs={'width': '150px'},
    )

    objectactions = [
        'update_contestants',
    ]

    list_display = (
        'name',
        'district',
        # 'director',
        # 'tenor',
        # 'lead',
        # 'baritone',
        # 'bass',
        # 'seed',
        # 'prelim',
        'place',
        'score',
        'finals_song1',
        'finals_mus1_points',
        'finals_prs1_points',
        'finals_sng1_points',
        'finals_song2',
        'finals_mus2_points',
        'finals_prs2_points',
        'finals_sng2_points',
        'men',
    )

    search_fields = (
        'name',
    )

    list_filter = (
        'contest__level',
        'contest__kind',
        'contest__year',
    )

    # inlines = [
    #     PerformanceInline,
    # ]

    fields = (
        (
            'contest',
            'group',
            'district',
        ), (
            'director', 'men',
        ), (
            'tenor',
            'lead',
            'baritone',
            'bass',
        ), (
            'seed',
            'prelim',
            'draw',
            'stagetime',
        ), (
            'place',
            'score',
        ), (
            'quarters_song1',
            'quarters_mus1_points',
            'quarters_prs1_points',
            'quarters_sng1_points',
        ), (
            'quarters_song2',
            'quarters_mus2_points',
            'quarters_prs2_points',
            'quarters_sng2_points',
        ), (
            'semis_song1',
            'semis_mus1_points',
            'semis_prs1_points',
            'semis_sng1_points',
        ), (
            'semis_song2',
            'semis_mus2_points',
            'semis_prs2_points',
            'semis_sng2_points',
        ), (
            'finals_song1',
            'finals_mus1_points',
            'finals_prs1_points',
            'finals_sng1_points',
        ), (
            'finals_song2',
            'finals_mus2_points',
            'finals_prs2_points',
            'finals_sng2_points',
        ),
    )

    readonly_fields = (
        'name',
    )

    save_on_top = True

@admin.register(Singer)
class SingerAdmin(admin.ModelAdmin):
    form = select2_modelform(
        Singer,
        attrs={'width': '100px'},
    )

    search_fields = (
        'name',
    )

    save_on_top = True
    list_display = (
        'name',
        'location',
        'website',
        'facebook',
        'twitter',
        'email',
        'phone',
        'picture',
    )

    fields = (
        'name',
        'location',
        'website',
        'facebook',
        'twitter',
        'email',
        'phone',
        'picture',
        'description',
    )

@admin.register(Director)
class DirectorAdmin(admin.ModelAdmin):
    form = select2_modelform(
        Director,
        attrs={'width': '250px'},
    )

    search_fields = (
        'name',
    )

    save_on_top = True
    list_display = (
        'name',
        'location',
        'website',
        'facebook',
        'twitter',
        'email',
        'phone',
        'picture',
    )

    fields = (
        'name',
        'location',
        'website',
        'facebook',
        'twitter',
        'email',
        'phone',
        'picture',
        'description',
    )

@admin.register(Judge)
class JudgeAdmin(admin.ModelAdmin):
    form = select2_modelform(
        Judge,
        attrs={'width': '250px'},
    )

    save_on_top = True
    fields = (
        'name',
    )

@admin.register(Note)
class NoteAdmin(admin.ModelAdmin):
    form = select2_modelform(
        Note,
        attrs={'width': '250px'},
    )

    save_on_top = True
    fields = (
        'user',
        'performance',
        'text',
    )

@admin.register(Song)
class SongAdmin(admin.ModelAdmin):
    form = select2_modelform(
        Song,
        attrs={'width': '250px'},
    )

    save_on_top = True
    fields = (
        'name',
    )

@admin.register(District)
class DistrictAdmin(admin.ModelAdmin):
    form = select2_modelform(
        District,
        attrs={'width': '250px'},
    )

    search_fields = (
        'name',
    )

    list_display = (
        'name',
        'location',
        'website',
        'facebook',
        'twitter',
        'email',
        'phone',
        'picture',
        'long_name',
        'kind',
    )

    list_filter = (
        'kind',
    )

    save_on_top = True
<commit_msg>Re-enable object action import legacy<commit_after># import logging
# log = logging.getLogger(__name__)

from django.contrib import admin

from django_object_actions import (
    DjangoObjectActions,
    takes_instance_or_queryset,
)

from easy_select2 import select2_modelform

from .models import (
    Convention,
    Contest,
    Contestant,
    Group,
    Singer,
    Note,
    District,
    Director,
    Judge,
    Song,
)

class ContestantInline(admin.TabularInline):
    form = select2_modelform(
        Contestant,
        attrs={'width': '250px'},
    )
    model = Contestant
    extra = 0
    show_change_link = True
    fields = (
        'contest',
        'group',
        # 'director',
        # 'district',
        # 'tenor',
        # 'lead',
        # 'baritone',
        # 'bass',
        # 'prelim',
        # 'seed',
        # 'score',
        # 'place',
    )

@admin.register(Convention)
class ConventionAdmin(admin.ModelAdmin):
    form = select2_modelform(
        Convention,
        attrs={'width': '250px'},
    )

    list_display = (
        'name',
        'location',
        'dates',
        'kind',
        'year',
        'district',
        'is_active',
    )

    fields = (
        'is_active',
        'name',
        'location',
        'dates',
        'timezone',
        'district',
        'kind',
        'year',
    )

    list_filter = (
        'kind',
        'year',
        'district',
    )

    readonly_fields = (
        'name',
    )

    save_on_top = True

@admin.register(Contest)
class ContestAdmin(DjangoObjectActions, admin.ModelAdmin):
    @takes_instance_or_queryset
    def import_legacy(self, request, queryset):
        for obj in queryset:
            obj.import_legacy()
    import_legacy.label = 'Import Legacy'
    form = select2_modelform(
        Contest,
        attrs={'width': '250px'},
    )
    save_on_top = True
    objectactions = [
        'import_legacy',
    ]

    # inlines = [
    #     ContestantInline,
    # ]

    list_filter = (
        'level',
        'kind',
        'year',
        'district',
    )

    list_display = (
        'name',
        'district',
        'convention',
        'level',
        'kind',
        'year',
        'panel',
        'scoresheet_pdf',
        'scoresheet_csv',
        'is_active',
    )

    fields = (
        ('is_active', 'is_complete',),
        'name',
        'convention',
        'level',
        'kind',
        'year',
        'district',
        'panel',
        'scoresheet_pdf',
        'scoresheet_csv',
    )

    readonly_fields = (
        'name',
    )

@admin.register(Group)
class GroupAdmin(admin.ModelAdmin):
    form = select2_modelform(
        Group,
        attrs={'width': '250px'},
    )

    search_fields = (
        'name',
    )

    list_display = (
        'name',
        'location',
        'website',
        'facebook',
        'twitter',
        'email',
        'phone',
        'chapter_name',
        'chapter_code',
        # 'bsmdb_id',
        'picture',
    )

    inlines = [
        ContestantInline,
    ]

    list_filter = (
        'kind',
    )

    readonly_fields = (
        'director',
        'lead',
        'tenor',
        'baritone',
        'bass',
    )

    save_on_top = True

@admin.register(Contestant)
class ContestantAdmin(admin.ModelAdmin):
    @takes_instance_or_queryset
    def update_contestants(self, request, queryset):
        for obj in queryset:
            obj.save()
    update_contestants.label = 'Update Contestants'

    form = select2_modelform(
        Contestant,
        attrs={'width': '150px'},
    )

    objectactions = [
        'update_contestants',
    ]

    list_display = (
        'name',
        'district',
        # 'director',
        # 'tenor',
        # 'lead',
        # 'baritone',
        # 'bass',
        # 'seed',
        # 'prelim',
        'place',
        'score',
        'finals_song1',
        'finals_mus1_points',
        'finals_prs1_points',
        'finals_sng1_points',
        'finals_song2',
        'finals_mus2_points',
        'finals_prs2_points',
        'finals_sng2_points',
        'men',
    )

    search_fields = (
        'name',
    )

    list_filter = (
        'contest__level',
        'contest__kind',
        'contest__year',
    )

    # inlines = [
    #     PerformanceInline,
    # ]

    fields = (
        (
            'contest',
            'group',
            'district',
        ), (
            'director', 'men',
        ), (
            'tenor',
            'lead',
            'baritone',
            'bass',
        ), (
            'seed',
            'prelim',
            'draw',
            'stagetime',
        ), (
            'place',
            'score',
        ), (
            'quarters_song1',
            'quarters_mus1_points',
            'quarters_prs1_points',
            'quarters_sng1_points',
        ), (
            'quarters_song2',
            'quarters_mus2_points',
            'quarters_prs2_points',
            'quarters_sng2_points',
        ), (
            'semis_song1',
            'semis_mus1_points',
            'semis_prs1_points',
            'semis_sng1_points',
        ), (
            'semis_song2',
            'semis_mus2_points',
            'semis_prs2_points',
            'semis_sng2_points',
        ), (
            'finals_song1',
            'finals_mus1_points',
            'finals_prs1_points',
            'finals_sng1_points',
        ), (
            'finals_song2',
            'finals_mus2_points',
            'finals_prs2_points',
            'finals_sng2_points',
        ),
    )

    readonly_fields = (
        'name',
    )

    save_on_top = True

@admin.register(Singer)
class SingerAdmin(admin.ModelAdmin):
    form = select2_modelform(
        Singer,
        attrs={'width': '100px'},
    )

    search_fields = (
        'name',
    )

    save_on_top = True
    list_display = (
        'name',
        'location',
        'website',
        'facebook',
        'twitter',
        'email',
        'phone',
        'picture',
    )

    fields = (
        'name',
        'location',
        'website',
        'facebook',
        'twitter',
        'email',
        'phone',
        'picture',
        'description',
    )

@admin.register(Director)
class DirectorAdmin(admin.ModelAdmin):
    form = select2_modelform(
        Director,
        attrs={'width': '250px'},
    )

    search_fields = (
        'name',
    )

    save_on_top = True
    list_display = (
        'name',
        'location',
        'website',
        'facebook',
        'twitter',
        'email',
        'phone',
        'picture',
    )

    fields = (
        'name',
        'location',
        'website',
        'facebook',
        'twitter',
        'email',
        'phone',
        'picture',
        'description',
    )

@admin.register(Judge)
class JudgeAdmin(admin.ModelAdmin):
    form = select2_modelform(
        Judge,
        attrs={'width': '250px'},
    )

    save_on_top = True
    fields = (
        'name',
    )

@admin.register(Note)
class NoteAdmin(admin.ModelAdmin):
    form = select2_modelform(
        Note,
        attrs={'width': '250px'},
    )

    save_on_top = True
    fields = (
        'user',
        'performance',
        'text',
    )

@admin.register(Song)
class SongAdmin(admin.ModelAdmin):
    form = select2_modelform(
        Song,
        attrs={'width': '250px'},
    )

    save_on_top = True
    fields = (
        'name',
    )

@admin.register(District)
class DistrictAdmin(admin.ModelAdmin):
    form = select2_modelform(
        District,
        attrs={'width': '250px'},
    )

    search_fields = (
        'name',
    )

    list_display = (
        'name',
        'location',
        'website',
        'facebook',
        'twitter',
        'email',
        'phone',
        'picture',
        'long_name',
        'kind',
    )

    list_filter = (
        'kind',
    )

    save_on_top = True
<|endoftext|>


<commit_before>"""Base class for the components in other modules."""
import numpy
import theano
from theano import tensor

#from pylearn.gd.sgd import sgd_updates
#from pylearn.algorithms.mcRBM import contrastive_cost, contrastive_grad
theano.config.warn.sum_div_dimshuffle_bug = False
floatX = theano.config.floatX
sharedX = lambda X, name : theano.shared(numpy.asarray(X, dtype=floatX), name=name)
if 0:
    print 'WARNING: using SLOW rng'
    RandomStreams = tensor.shared_randomstreams.RandomStreams
else:
    import theano.sandbox.rng_mrg
    RandomStreams = theano.sandbox.rng_mrg.MRG_RandomStreams

class Block(object):
    """
    Basic building block for deep architectures.
    """
    def __init__(self, inputs, **kwargs):
        # Symbolic inputs
        self.inputs = inputs
        self._params = []
        self.__dict__.update(kwargs)

    def alloc(cls, conf, rng=None):
        raise NotImplementedError('alloc')

    def params(self):
        """
        Returns a list of *shared* learnable parameters that
        are, in your judgment, typically learned in this
        model.
        """
        return list(self._params)

class Trainer(object):
    """
    Basic abstract class for training
    """
    def __init__(self, inputs, **kwargs):
        self.__dict__.update(kwargs)

    def updates(self):
        """Do one step of training."""
        raise NotImplementedError()
<commit_msg>Refactored PCA class to inherit from framework base classes.<commit_after>"""Base class for the components in other modules."""
import numpy
import theano
from theano import tensor

#from pylearn.gd.sgd import sgd_updates
#from pylearn.algorithms.mcRBM import contrastive_cost, contrastive_grad
theano.config.warn.sum_div_dimshuffle_bug = False
floatX = theano.config.floatX
sharedX = lambda X, name : theano.shared(numpy.asarray(X, dtype=floatX), name=name)
if 0:
    print 'WARNING: using SLOW rng'
    RandomStreams = tensor.shared_randomstreams.RandomStreams
else:
    import theano.sandbox.rng_mrg
    RandomStreams = theano.sandbox.rng_mrg.MRG_RandomStreams

class Block(object):
    """
    Basic building block for deep architectures.
    """
    def __init__(self, inputs, **kwargs):
        # Symbolic inputs
        self.inputs = inputs
        self._params = []
        self.__dict__.update(kwargs)

    def alloc(cls, conf, rng=None):
        raise NotImplementedError('alloc')

    def load(self, load_dir, load_filename):
        raise NotImplementedError('load')

    def params(self):
        """
        Returns a list of *shared* learnable parameters that
        are, in your judgment, typically learned in this
        model.
        """
        return self._params

    def outputs(self):
        """Output to pass on to layers above."""
        raise NotImplementedError('outputs')

class Trainer(object):
    """
    Basic abstract class for training
    """
    def __init__(self, inputs, **kwargs):
        self.inputs = inputs
        self.__dict__.update(kwargs)

    def updates(self):
        """Do one step of training."""
        raise NotImplementedError()

    def save(self, save_dir, save_filename):
        raise NotImplementedError('save')
<|endoftext|>