|
# -*- coding: utf-8 -*-
import monetary
from django.conf import settings
from django.contrib import admin
from django.contrib.auth.hashers import make_password
from django_admin import AdvancedActionsModelAdmin, AdvancedExportExcelModelAdmin, DeleteModelAdmin, ReadOnlyModelAdmin
from django_models_ext import ProvinceShortModelMixin
from pysnippets.strsnippets import strip
from integral.models import SaleclerkSubmitLogInfo
from mch.models import (ActivityInfo, AdministratorInfo, BrandInfo, CameraModelInfo, ConsumeInfoSubmitLogInfo,
DistributorInfo, LatestAppInfo, LatestAppScreenInfo, MaintenancemanInfo, ModelCameraBodyInfo,
ModelInfo, OperatorInfo, SaleclerkInfo, ConsumeShotUnbindingInfo)
from utils.redis.rshot import update_member_shot_data
class AdministratorInfoAdmin(admin.ModelAdmin):
list_display = ('admin_id', 'admin_type', 'phone', 'password', 'encryption', 'name', 'brand_id', 'brand_name', 'user_status', 'status', 'created_at', 'updated_at')
list_filter = ('admin_type', 'user_status', 'status', 'brand_name')
readonly_fields = ('encryption', 'brand_name')
def save_model(self, request, obj, form, change):
obj.phone = strip(obj.phone)
obj.password = strip(obj.password)
if obj.password:
obj.encryption = make_password(obj.password, settings.MAKE_PASSWORD_SALT, settings.MAKE_PASSWORD_HASHER)
obj.password = ''
obj.brand_id = strip(obj.brand_id)
try:
obj.brand_name = BrandInfo.objects.get(brand_id=obj.brand_id).brand_name
except BrandInfo.DoesNotExist:
obj.brand_name = ''
obj.save()
class OperatorInfoAdmin(admin.ModelAdmin):
list_display = ('operator_id', 'phone', 'password', 'encryption', 'name', 'brand_id', 'brand_name', 'brand_domain', 'user_status', 'status', 'created_at', 'updated_at')
list_filter = ('user_status', 'status', 'brand_name')
readonly_fields = ('brand_domain', 'encryption', 'brand_name')
def save_model(self, request, obj, form, change):
obj.phone = strip(obj.phone)
obj.password = strip(obj.password)
if obj.password:
obj.encryption = make_password(obj.password, settings.MAKE_PASSWORD_SALT, settings.MAKE_PASSWORD_HASHER)
obj.password = ''
obj.brand_id = strip(obj.brand_id)
try:
obj.brand_name = BrandInfo.objects.get(brand_id=obj.brand_id).brand_name
except BrandInfo.DoesNotExist:
obj.brand_name = ''
obj.save()
class BrandInfoAdmin(admin.ModelAdmin):
list_display = ('brand_id', 'brand_name', 'brand_descr', 'brand_logo', 'brand_domain', 'position', 'status', 'created_at', 'updated_at')
def save_model(self, request, obj, form, change):
obj.save()
OperatorInfo.objects.filter(brand_id=obj.brand_id).update(brand_domain=obj.brand_domain)
class ModelInfoAdmin(AdvancedExportExcelModelAdmin, DeleteModelAdmin, admin.ModelAdmin):
list_display = ('pk', 'brand_id', 'brand_name', 'jancode', 'model_id', 'model_name', 'model_uni_name', 'model_full_name', 'model_descr', 'image', 'url', 'image2', 'integral', 'position', 'display', 'is_important', 'shot_type_id', 'shot_member_integral', 'shot_member_image', 'shot_member_name', 'status', 'created_at', 'updated_at')
list_filter = ('brand_name', 'shot_type_id', 'display', 'status')
readonly_fields = ('brand_name', )
search_fields = ('brand_id', 'brand_name', 'jancode', 'model_id', 'model_name', 'model_uni_name', 'model_full_name', 'model_descr')
def save_model(self, request, obj, form, change):
obj.brand_id = strip(obj.brand_id)
try:
obj.brand_name = BrandInfo.objects.get(brand_id=obj.brand_id).brand_name
except BrandInfo.DoesNotExist:
obj.brand_name = ''
obj.is_show_shot = True
obj.save()
ModelInfo.objects.filter(brand_id=obj.brand_id, model_uni_name=obj.model_uni_name).exclude(model_id=obj.model_id).update(is_show_shot=False)
update_member_shot_data()
# 更新用户提交列表和销售员提交列表
SaleclerkSubmitLogInfo.objects.filter(model_pk=obj.pk).update(
model_name=obj.model_name,
model_uni_name=obj.model_uni_name,
)
ConsumeInfoSubmitLogInfo.objects.filter(model_id=obj.model_id).update(
model_uni_name=obj.model_uni_name,
model_name=obj.model_name,
)
# 更新"型号机身适配"型号图片
ModelCameraBodyInfo.objects.filter(
brand_id=obj.brand_id,
model_name=obj.model_uni_name,
).update(
model_image=obj.shot_member_image,
is_important=obj.is_important,
)
def delete_model(self, request, obj):
obj.delete()
update_member_shot_data()
class CameraModelInfoAdmin(admin.ModelAdmin):
list_display = ('brand_id', 'brand_name', 'camera_brand_name', 'camera_name', 'camera_image', 'camera_market_time', 'status', 'created_at', 'updated_at')
list_filter = ('brand_name', 'camera_brand_name', 'status')
def save_model(self, request, obj, form, change):
obj.save()
# 更新"型号机身适配"机身图片
ModelCameraBodyInfo.objects.filter(
brand_id=obj.brand_id,
camera_brand_name=obj.camera_brand_name,
camera_name=obj.camera_name,
).update(
camera_image=obj.camera_image,
camera_market_time=obj.camera_market_time,
)
class ModelCameraBodyInfoAdmin(DeleteModelAdmin, admin.ModelAdmin):
list_display = ('brand_id', 'brand_name', 'model_name', 'model_full_name', 'model_image', 'is_important', 'camera_brand_name', 'camera_name', 'camera_image', 'camera_market_time', 'status', 'created_at', 'updated_at')
list_filter = ('brand_name', 'model_name', 'is_important', 'camera_brand_name', 'status')
readonly_fields = ('model_image', 'camera_image', 'camera_market_time')
search_fields = ('brand_id', 'brand_name', 'model_name', 'model_full_name', 'camera_name')
class ModelImageInfoAdmin(admin.ModelAdmin):
list_display = ('model_id', 'model_name', 'image', 'url', 'position', 'status', 'created_at', 'updated_at')
list_filter = ('model_name', 'status')
def save_model(self, request, obj, form, change):
obj.model_id = strip(obj.model_id)
try:
obj.model_name = ModelInfo.objects.get(model_id=obj.model_id).model_name
except BrandInfo.DoesNotExist:
obj.model_name = ''
obj.save()
class DistributorInfoAdmin(admin.ModelAdmin):
list_display = ('brand_id', 'brand_name', 'department_id', 'distributor_id', 'distributor_name', 'distributor_short_name', 'distributor_province_name', 'position', 'status', 'created_at', 'updated_at')
list_filter = ('brand_name', 'sr_id', 'distributor_province_name', 'status')
readonly_fields = ('brand_name', 'distributor_province_code')
search_fields = ('brand_id', 'brand_name', 'distributor_id', 'distributor_name', 'distributor_short_name', 'distributor_descr', 'distributor_province_code', 'distributor_province_name')
def save_model(self, request, obj, form, change):
obj.brand_id = strip(obj.brand_id)
try:
obj.brand_name = BrandInfo.objects.get(brand_id=obj.brand_id).brand_name
except BrandInfo.DoesNotExist:
obj.brand_name = ''
obj.distributor_province_code = ProvinceShortModelMixin.PROVINCE_NAME_CODE_DICT.get(obj.distributor_province_name, '')
obj.save()
class SaleclerkInfoAdmin(AdvancedExportExcelModelAdmin, AdvancedActionsModelAdmin, admin.ModelAdmin):
list_display = ('brand_id', 'brand_name', 'distributor_id', 'distributor_name', 'clerk_id', 'clerk_name', 'clerk_sex', 'clerk_phone', 'unionid', 'openid', 'num', 'integral', 'total_integral', 'user_status', 'test_user', 'is_online_sales', 'status', 'created_at', 'updated_at')
list_filter = ('test_user', 'user_status', 'is_online_sales', 'status')
search_fields = ('brand_id', 'brand_name', 'distributor_id', 'distributor_name', 'clerk_id', 'clerk_name', 'clerk_phone', 'unionid', 'openid')
actions_exclude = ('delete_selected', )
class MaintenancemanInfoAdmin(AdvancedExportExcelModelAdmin, AdvancedActionsModelAdmin, admin.ModelAdmin):
list_display = ('brand_name', 'wx_userid', 'maintenance_id', 'maintenance_name', 'maintenance_phone', 'status', 'created_at', 'updated_at')
search_fields = ('maintenance_id', 'maintenance_name', 'maintenance_phone')
actions_exclude = ('delete_selected', )
class BrandModelDistributorPriceInfoAdmin(admin.ModelAdmin):
list_display = ('brand_id', 'brand_name', 'model_id', 'model_name', 'distributor_id', 'distributor_name', 'factory_yuan', 'integral', 'status', 'created_at', 'updated_at')
list_filter = ('brand_name', 'model_name', 'distributor_name', 'status')
readonly_fields = ('brand_name', 'model_name', 'distributor_name', 'factory_fee', )
search_fields = ('brand_id', 'brand_name', 'model_id', 'model_name', 'distributor_id', 'distributor_name')
def save_model(self, request, obj, form, change):
obj.brand_id = strip(obj.brand_id)
try:
obj.brand_name = BrandInfo.objects.get(brand_id=obj.brand_id).brand_name
except BrandInfo.DoesNotExist:
obj.brand_name = ''
obj.model_id = strip(obj.model_id)
try:
obj.model_name = ModelInfo.objects.get(model_id=obj.model_id).model_name
except BrandInfo.DoesNotExist:
obj.model_name = ''
obj.distributor_id = strip(obj.distributor_id)
try:
obj.distributor_name = DistributorInfo.objects.get(distributor_id=obj.distributor_id).distributor_name
except BrandInfo.DoesNotExist:
obj.distributor_name = ''
obj.save()
class LatestAppInfoAdmin(admin.ModelAdmin):
list_display = ('latest_adr_version_code', 'latest_adr_version_name', 'latest_adr_app', 'latest_adr_url', 'status', 'created_at', 'updated_at')
list_filter = ('status', )
readonly_fields = ('status', )
def save_model(self, request, obj, form, change):
if not obj.pk and LatestAppInfo.objects.filter(status=True).exists():
return
obj.latest_adr_version_name = strip(obj.latest_adr_version_name)
obj.latest_adr_app = strip(obj.latest_adr_app)
obj.latest_adr_url = strip(obj.latest_adr_url)
obj.save()
class LatestAppScreenInfoAdmin(admin.ModelAdmin):
list_display = ('latest_adr_version_code', 'latest_adr_version_name', 'latest_adr_app', 'latest_adr_url', 'status', 'created_at', 'updated_at')
list_filter = ('status', )
readonly_fields = ('status', )
def save_model(self, request, obj, form, change):
if not obj.pk and LatestAppInfo.objects.filter(status=True).exists():
return
obj.latest_adr_version_name = strip(obj.latest_adr_version_name)
obj.latest_adr_app = strip(obj.latest_adr_app)
obj.latest_adr_url = strip(obj.latest_adr_url)
obj.save()
class ConsumeInfoSubmitLogInfoAdmin(AdvancedExportExcelModelAdmin, admin.ModelAdmin):
list_display = ('user_id', 'phone', 'model_name', 'serialNo', 'dupload', 'submit_during_activity', 'integral', 'has_used', 'created_at')
list_filter = ('brand_id', 'submit_during_activity', 'activity_id', 'dupload', 'test_user', 'verifyResult', 'has_used', 'status', 'code_version', 'created_at')
excel_fields = ('created_at', 'phone', 'model_uni_name', 'model_name', 'serialNo')
search_fields = ('user_id', 'phone', 'serialNo', 'model_name')
class ConsumeShotUnbindingInfoAdmin(admin.ModelAdmin):
list_display = ('user_id', 'submit_pk', 'submit_at', 'model_id', 'sn', 'reason', 'created_at')
search_fields = ('sn', )
class ActivityInfoAdmin(admin.ModelAdmin):
list_display = ('activity_id', 'activity_name', 'model_uni_names', 'start_at', 'end_at', 'coupon_expire_type', 'coupon_valid_period', 'coupon_expire_at', 'coupon_value', 'status', 'created_at', 'updated_at')
list_filter = ('coupon_expire_type', 'status')
admin.site.register(AdministratorInfo, AdministratorInfoAdmin)
admin.site.register(OperatorInfo, OperatorInfoAdmin)
admin.site.register(BrandInfo, BrandInfoAdmin)
admin.site.register(ModelInfo, ModelInfoAdmin)
admin.site.register(CameraModelInfo, CameraModelInfoAdmin)
admin.site.register(ModelCameraBodyInfo, ModelCameraBodyInfoAdmin)
# admin.site.register(ModelImageInfo, ModelImageInfoAdmin)
admin.site.register(DistributorInfo, DistributorInfoAdmin)
admin.site.register(SaleclerkInfo, SaleclerkInfoAdmin)
# admin.site.register(BrandModelDistributorPriceInfo, BrandModelDistributorPriceInfoAdmin)
admin.site.register(LatestAppInfo, LatestAppInfoAdmin)
admin.site.register(LatestAppScreenInfo, LatestAppScreenInfoAdmin)
admin.site.register(ConsumeInfoSubmitLogInfo, ConsumeInfoSubmitLogInfoAdmin)
admin.site.register(ActivityInfo, ActivityInfoAdmin)
admin.site.register(MaintenancemanInfo, MaintenancemanInfoAdmin)
admin.site.register(ConsumeShotUnbindingInfo, ConsumeShotUnbindingInfoAdmin)
|