<commit_before>"""
Admin views for ecommerce models
"""

from django.contrib import admin

from ecommerce.models import (
    Coupon,
    CoursePrice,
    Line,
    Order,
    OrderAudit,
    Receipt,
    RedeemedCoupon,
    UserCoupon,
)
from micromasters.utils import get_field_names


class CoursePriceAdmin(admin.ModelAdmin):
    """Admin for CoursePrice"""
    model = CoursePrice


class LineAdmin(admin.ModelAdmin):
    """Admin for Line"""
    model = Line

    readonly_fields = get_field_names(Line)

    def has_add_permission(self, request):
        return False

    def has_delete_permission(self, request, obj=None):
        return False


class OrderAdmin(admin.ModelAdmin):
    """Admin for Order"""
    model = Order

    readonly_fields = [name for name in get_field_names(Order) if name != 'status']

    def has_add_permission(self, request):
        return False

    def has_delete_permission(self, request, obj=None):
        return False

    def save_model(self, request, obj, form, change):
        """
        Saves object and logs change to object
        """
        obj.save_and_log(request.user)


class OrderAuditAdmin(admin.ModelAdmin):
    """Admin for OrderAudit"""
    model = OrderAudit
    readonly_fields = get_field_names(OrderAudit)

    def has_add_permission(self, request):
        return False

    def has_delete_permission(self, request, obj=None):
        return False


class ReceiptAdmin(admin.ModelAdmin):
    """Admin for Receipt"""
    model = Receipt
    readonly_fields = get_field_names(Receipt)

    def has_add_permission(self, request):
        return False

    def has_delete_permission(self, request, obj=None):
        return False


class CouponAdmin(admin.ModelAdmin):
    """Admin for Coupon"""
    model = Coupon
    readonly_fields = get_field_names(Coupon)


class UserCouponAdmin(admin.ModelAdmin):
    """Admin for UserCoupon"""
    model = UserCoupon
    readonly_fields = get_field_names(UserCoupon)


class RedeemedCouponAdmin(admin.ModelAdmin):
    """Admin for RedeemedCoupon"""
    model = RedeemedCoupon
    readonly_fields = get_field_names(RedeemedCoupon)


admin.site.register(Coupon, CouponAdmin)
admin.site.register(CoursePrice, CoursePriceAdmin)
admin.site.register(Line, LineAdmin)
admin.site.register(Order, OrderAdmin)
admin.site.register(OrderAudit, OrderAuditAdmin)
admin.site.register(RedeemedCoupon, RedeemedCouponAdmin)
admin.site.register(Receipt, ReceiptAdmin)
admin.site.register(UserCoupon, UserCouponAdmin)
<commit_msg>Remove UserCoupon from admin<commit_after>"""
Admin views for ecommerce models
"""

from django.contrib import admin

from ecommerce.models import (
    Coupon,
    CoursePrice,
    Line,
    Order,
    OrderAudit,
    Receipt,
    RedeemedCoupon,
)
from micromasters.utils import get_field_names


class CoursePriceAdmin(admin.ModelAdmin):
    """Admin for CoursePrice"""
    model = CoursePrice


class LineAdmin(admin.ModelAdmin):
    """Admin for Line"""
    model = Line

    readonly_fields = get_field_names(Line)

    def has_add_permission(self, request):
        return False

    def has_delete_permission(self, request, obj=None):
        return False


class OrderAdmin(admin.ModelAdmin):
    """Admin for Order"""
    model = Order

    readonly_fields = [name for name in get_field_names(Order) if name != 'status']

    def has_add_permission(self, request):
        return False

    def has_delete_permission(self, request, obj=None):
        return False

    def save_model(self, request, obj, form, change):
        """
        Saves object and logs change to object
        """
        obj.save_and_log(request.user)


class OrderAuditAdmin(admin.ModelAdmin):
    """Admin for OrderAudit"""
    model = OrderAudit
    readonly_fields = get_field_names(OrderAudit)

    def has_add_permission(self, request):
        return False

    def has_delete_permission(self, request, obj=None):
        return False


class ReceiptAdmin(admin.ModelAdmin):
    """Admin for Receipt"""
    model = Receipt
    readonly_fields = get_field_names(Receipt)

    def has_add_permission(self, request):
        return False

    def has_delete_permission(self, request, obj=None):
        return False


class CouponAdmin(admin.ModelAdmin):
    """Admin for Coupon"""
    model = Coupon
    readonly_fields = get_field_names(Coupon)


class RedeemedCouponAdmin(admin.ModelAdmin):
    """Admin for RedeemedCoupon"""
    model = RedeemedCoupon
    readonly_fields = get_field_names(RedeemedCoupon)


admin.site.register(Coupon, CouponAdmin)
admin.site.register(CoursePrice, CoursePriceAdmin)
admin.site.register(Line, LineAdmin)
admin.site.register(Order, OrderAdmin)
admin.site.register(OrderAudit, OrderAuditAdmin)
admin.site.register(RedeemedCoupon, RedeemedCouponAdmin)
admin.site.register(Receipt, ReceiptAdmin)

{'fraction_non_alphanumeric': 0.09261939218523878, 'fraction_numerical': 0.0, 'mean_word_length': 3.862311557788945, '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': '4848486', 'n_tokens_mistral': 1516, 'n_tokens_neox': 1468, 'n_words': 343}