<commit_before>from django.contrib import admin

from attendance.models import Member, AccessCard, LoggingEvent


# Customised model admin objects
class MemberAdmin(admin.ModelAdmin):
    # formfield_overrides = {
    # models.: {'widget': TextInput(attrs={'size':'8'})},
    # models.TextField: {'widget': Textarea(attrs={'rows':4, 'cols':40})},
    # }
    fieldsets = [
        ('Registration', {'fields': ['student_id', 'reg_date']}),
        ('Identity', {'fields': ['f_name', 'l_name']}),
        ('Contact details', {'fields': []}),
        # TODO: admin should also see and update address, phone, card, ... in the same form
    ]
    list_display = ('student_id', 'f_name', 'l_name', 'reg_date')
    readonly_fields = ('reg_date',)


class AccessCardAdmin(admin.ModelAdmin):
    # formfield_overrides = {
    # models.: {'widget': TextInput(attrs={'size':'8'})},
    # models.TextField: {'widget': Textarea(attrs={'rows':4, 'cols':40})},
    # }
    fieldsets = [
        ('Registration', {'fields': ['member', 'rfid', 'reg_date']}), # TODO: the dropdown menu to chose member should list f_name,l_name in addition to student_id
    ]
    list_display = ('rfid', 'member', 'get_f_name', 'get_l_name', 'reg_date')
    readonly_fields = ('reg_date',)

    def get_f_name(self, obj):
        return obj.member.f_name

    get_f_name.short_description = 'First name'

    def get_l_name(self, obj):
        return obj.member.l_name

    get_l_name.short_description = 'Last name'


class LoggingEventAdmin(admin.ModelAdmin):
    # formfield_overrides = {
    # models.: {'widget': TextInput(attrs={'size':'8'})},
    # models.TextField: {'widget': Textarea(attrs={'rows':4, 'cols':40})},
    # }
    fieldsets = [
        ('Check-in', {'fields': ['check_in', 'rfid']}),
        ('Check-out', {'fields': ['check_out']}),
    ]
    list_display = ('rfid', 'get_f_name', 'get_l_name', 'check_in', 'check_out')

    def get_f_name(self, obj):
        print(obj.rfid)
        return AccessCard.objects.get(pk=obj.rfid).member.f_name

    get_f_name.short_description = 'First name'

    def get_l_name(self, obj):
        print(obj.rfid)
        return AccessCard.objects.get(pk=obj.rfid).member.l_name

    get_f_name.short_description = 'Last name'


# Register models
admin.site.register(Member, MemberAdmin)
admin.site.register(AccessCard, AccessCardAdmin)
admin.site.register(LoggingEvent, LoggingEventAdmin)

members__name__startswith = 'Paul'<commit_msg>cleanup and column title fix<commit_after>from django.contrib import admin

from attendance.models import Member, AccessCard, LoggingEvent


# Customised model admin objects
class MemberAdmin(admin.ModelAdmin):
    # formfield_overrides = {
    # models.: {'widget': TextInput(attrs={'size':'8'})},
    # models.TextField: {'widget': Textarea(attrs={'rows':4, 'cols':40})},
    # }
    fieldsets = [
        ('Registration', {'fields': ['student_id', 'reg_date']}),
        ('Identity', {'fields': ['f_name', 'l_name']}),
        ('Contact details', {'fields': []}),
        # TODO: admin should also see and update address, phone, card, ... in the same form
    ]
    list_display = ('student_id', 'f_name', 'l_name', 'reg_date')
    readonly_fields = ('reg_date',)


class AccessCardAdmin(admin.ModelAdmin):
    # formfield_overrides = {
    # models.: {'widget': TextInput(attrs={'size':'8'})},
    # models.TextField: {'widget': Textarea(attrs={'rows':4, 'cols':40})},
    # }
    fieldsets = [
        ('Registration', {'fields': ['member', 'rfid', 'reg_date']}), # TODO: the dropdown menu to chose member should list f_name,l_name in addition to student_id
    ]
    list_display = ('rfid', 'member', 'get_f_name', 'get_l_name', 'reg_date')
    readonly_fields = ('reg_date',)

    def get_f_name(self, obj):
        return obj.member.f_name

    get_f_name.short_description = 'First name'

    def get_l_name(self, obj):
        return obj.member.l_name

    get_l_name.short_description = 'Last name'


class LoggingEventAdmin(admin.ModelAdmin):
    # formfield_overrides = {
    # models.: {'widget': TextInput(attrs={'size':'8'})},
    # models.TextField: {'widget': Textarea(attrs={'rows':4, 'cols':40})},
    # }
    fieldsets = [
        ('Check-in', {'fields': ['check_in', 'rfid']}),
        ('Check-out', {'fields': ['check_out']}),
    ]
    list_display = ('rfid', 'get_f_name', 'get_l_name', 'check_in', 'check_out')

    def get_f_name(self, obj):
        return AccessCard.objects.get(pk=obj.rfid).member.f_name

    get_f_name.short_description = 'First name'

    def get_l_name(self, obj):
        return AccessCard.objects.get(pk=obj.rfid).member.l_name

    get_l_name.short_description = 'Last name'


# Register models
admin.site.register(Member, MemberAdmin)
admin.site.register(AccessCard, AccessCardAdmin)
admin.site.register(LoggingEvent, LoggingEventAdmin)

members__name__startswith = 'Paul'
{'fraction_non_alphanumeric': 0.16949846468781984, 'fraction_numerical': 0.004912998976458547, 'mean_word_length': 4.001023541453429, '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': '5600365', 'n_tokens_mistral': 1623, 'n_tokens_neox': 1602, 'n_words': 327}