admin.py 2.16 KB
Newer Older
1 2 3 4 5 6
# encoding: utf-8
"""
Admin site configurations for verify_student.
"""

from config_models.admin import ConfigurationModelAdmin
7
from ratelimitbackend import admin
8
from lms.djangoapps.verify_student.models import (
9 10
    IcrvStatusEmailsConfiguration,
    SkippedReverification,
11
    SoftwareSecurePhotoVerification,
12
    VerificationStatus,
13
)
14

15 16 17 18 19 20

class SoftwareSecurePhotoVerificationAdmin(admin.ModelAdmin):
    """
    Admin for the SoftwareSecurePhotoVerification table.
    """
    list_display = ('id', 'user', 'status', 'receipt_id', 'submitted_at', 'updated_at')
21
    raw_id_fields = ('user', 'reviewing_user')
22 23 24 25 26 27 28 29 30
    search_fields = (
        'receipt_id',
    )


class VerificationStatusAdmin(admin.ModelAdmin):
    """
    Admin for the VerificationStatus table.
    """
31
    list_display = ('timestamp', 'user', 'status', 'checkpoint')
32
    readonly_fields = ()
33
    search_fields = ('checkpoint__checkpoint_location', 'user__username')
34
    raw_id_fields = ('user',)
35 36 37 38 39 40 41 42 43 44

    def get_readonly_fields(self, request, obj=None):
        """When editing an existing record, all fields should be read-only.

        VerificationStatus records should be immutable; to change the user's
        status, create a new record with the updated status and a more
        recent timestamp.

        """
        if obj:
45
            return self.readonly_fields + ('status', 'checkpoint', 'user', 'response', 'error')
46 47 48 49 50 51
        return self.readonly_fields


class SkippedReverificationAdmin(admin.ModelAdmin):
    """Admin for the SkippedReverification table. """
    list_display = ('created_at', 'user', 'course_id', 'checkpoint')
52
    raw_id_fields = ('user',)
53
    readonly_fields = ('user', 'course_id')
54
    search_fields = ('user__username', 'course_id', 'checkpoint__checkpoint_location')
55 56 57 58

    def has_add_permission(self, request):
        """Skipped verifications can't be created in Django admin. """
        return False
59 60 61


admin.site.register(SoftwareSecurePhotoVerification, SoftwareSecurePhotoVerificationAdmin)
62
admin.site.register(SkippedReverification, SkippedReverificationAdmin)
63
admin.site.register(VerificationStatus, VerificationStatusAdmin)
64
admin.site.register(IcrvStatusEmailsConfiguration, ConfigurationModelAdmin)