Keine Beschreibung

admin.py 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. # -*- coding: utf-8 -*-
  2. import monetary
  3. from django.conf import settings
  4. from django.contrib import admin
  5. from django.contrib.auth.hashers import make_password
  6. from django_admin import ReadOnlyModelAdmin
  7. from django_models_ext import ProvinceShortModelMixin
  8. from pysnippets.strsnippets import strip
  9. from mch.models import (AdministratorInfo, BrandInfo, ConsumeInfoSubmitLogInfo, DistributorInfo, LatestAppInfo,
  10. LatestAppScreenInfo, ModelInfo, OperatorInfo, SaleclerkInfo)
  11. class AdministratorInfoAdmin(admin.ModelAdmin):
  12. list_display = ('admin_id', 'phone', 'password', 'encryption', 'name', 'brand_id', 'brand_name', 'user_status', 'status', 'created_at', 'updated_at')
  13. list_filter = ('user_status', 'status', 'brand_name')
  14. readonly_fields = ('encryption', 'brand_name')
  15. def save_model(self, request, obj, form, change):
  16. obj.phone = strip(obj.phone)
  17. obj.password = strip(obj.password)
  18. if obj.password:
  19. obj.encryption = make_password(obj.password, settings.MAKE_PASSWORD_SALT, settings.MAKE_PASSWORD_HASHER)
  20. obj.password = ''
  21. obj.brand_id = strip(obj.brand_id)
  22. try:
  23. obj.brand_name = BrandInfo.objects.get(brand_id=obj.brand_id).brand_name
  24. except BrandInfo.DoesNotExist:
  25. obj.brand_name = ''
  26. obj.save()
  27. class OperatorInfoAdmin(admin.ModelAdmin):
  28. list_display = ('operator_id', 'phone', 'password', 'encryption', 'name', 'brand_id', 'brand_name', 'brand_domain', 'user_status', 'status', 'created_at', 'updated_at')
  29. list_filter = ('user_status', 'status', 'brand_name')
  30. readonly_fields = ('brand_domain', 'encryption', 'brand_name')
  31. def save_model(self, request, obj, form, change):
  32. obj.phone = strip(obj.phone)
  33. obj.password = strip(obj.password)
  34. if obj.password:
  35. obj.encryption = make_password(obj.password, settings.MAKE_PASSWORD_SALT, settings.MAKE_PASSWORD_HASHER)
  36. obj.password = ''
  37. obj.brand_id = strip(obj.brand_id)
  38. try:
  39. obj.brand_name = BrandInfo.objects.get(brand_id=obj.brand_id).brand_name
  40. except BrandInfo.DoesNotExist:
  41. obj.brand_name = ''
  42. obj.save()
  43. class BrandInfoAdmin(admin.ModelAdmin):
  44. list_display = ('brand_id', 'brand_name', 'brand_descr', 'brand_logo', 'brand_domain', 'position', 'status', 'created_at', 'updated_at')
  45. def save_model(self, request, obj, form, change):
  46. obj.save()
  47. OperatorInfo.objects.filter(brand_id=obj.brand_id).update(brand_domain=obj.brand_domain)
  48. class ModelInfoAdmin(admin.ModelAdmin):
  49. list_display = ('brand_id', 'brand_name', 'jancode', 'model_id', 'model_uni_name', 'model_name', 'model_full_name', 'model_descr', 'category', 'warehouse', 'image', 'url', 'factory_yuan', 'integral', 'position', 'display', 'status', 'created_at', 'updated_at')
  50. list_filter = ('brand_name', 'category', 'warehouse', 'display', 'status')
  51. readonly_fields = ('brand_name', 'factory_fee')
  52. search_fields = ('brand_id', 'brand_name', 'jancode', 'model_id', 'model_uni_name', 'model_name', 'model_full_name', 'model_descr', 'category', 'warehouse')
  53. def save_model(self, request, obj, form, change):
  54. obj.brand_id = strip(obj.brand_id)
  55. try:
  56. obj.brand_name = BrandInfo.objects.get(brand_id=obj.brand_id).brand_name
  57. except BrandInfo.DoesNotExist:
  58. obj.brand_name = ''
  59. obj.factory_fee = monetary.Yuan2Fen(obj.factory_yuan)
  60. obj.factory_yuan = monetary.Fen2Yuan(obj.factory_fee)
  61. obj.save()
  62. class ModelImageInfoAdmin(admin.ModelAdmin):
  63. list_display = ('model_id', 'model_name', 'image', 'url', 'position', 'status', 'created_at', 'updated_at')
  64. list_filter = ('model_name', 'status')
  65. def save_model(self, request, obj, form, change):
  66. obj.model_id = strip(obj.model_id)
  67. try:
  68. obj.model_name = ModelInfo.objects.get(model_id=obj.model_id).model_name
  69. except BrandInfo.DoesNotExist:
  70. obj.model_name = ''
  71. obj.save()
  72. class DistributorInfoAdmin(admin.ModelAdmin):
  73. list_display = ('brand_id', 'brand_name', 'distributor_id', 'distributor_name', 'distributor_short_name', 'distributor_province_name', 'position', 'status', 'created_at', 'updated_at')
  74. list_filter = ('brand_name', 'distributor_province_name', 'status')
  75. readonly_fields = ('brand_name', 'distributor_province_code')
  76. search_fields = ('brand_id', 'brand_name', 'distributor_name', 'distributor_short_name', 'distributor_descr', 'distributor_province_code', 'distributor_province_name')
  77. def save_model(self, request, obj, form, change):
  78. obj.brand_id = strip(obj.brand_id)
  79. try:
  80. obj.brand_name = BrandInfo.objects.get(brand_id=obj.brand_id).brand_name
  81. except BrandInfo.DoesNotExist:
  82. obj.brand_name = ''
  83. obj.distributor_province_code = ProvinceShortModelMixin.PROVINCE_NAME_CODE_DICT.get(obj.distributor_province_name, '')
  84. obj.save()
  85. class SaleclerkInfoAdmin(admin.ModelAdmin):
  86. list_display = ('brand_id', 'brand_name', 'distributor_id', 'distributor_name', 'clerk_id', 'clerk_name', 'clerk_sex', 'clerk_phone', 'unionid', 'openid', 'integral', 'total_integral', 'user_status', 'test_user', 'status', 'created_at', 'updated_at')
  87. list_filter = ('test_user', 'user_status', 'status')
  88. search_fields = ('brand_id', 'brand_name', 'distributor_id', 'distributor_name', 'clerk_id', 'clerk_name', 'clerk_phone')
  89. # def save_model(self, request, obj, form, change):
  90. # obj.save()
  91. # if not obj.test_user:
  92. # return
  93. # SaleclerkIntegralIncomeExpensesInfo.objects.filter(distributor_id=obj.distributor_id).update(test_user=True)
  94. # SaleclerkSubmitLogInfo.objects.filter(distributor_id=obj.distributor_id).update(test_user=True)
  95. class BrandModelDistributorPriceInfoAdmin(admin.ModelAdmin):
  96. list_display = ('brand_id', 'brand_name', 'model_id', 'model_name', 'distributor_id', 'distributor_name', 'factory_yuan', 'integral', 'status', 'created_at', 'updated_at')
  97. list_filter = ('brand_name', 'model_name', 'distributor_name', 'status')
  98. readonly_fields = ('brand_name', 'model_name', 'distributor_name', 'factory_fee', )
  99. search_fields = ('brand_id', 'brand_name', 'model_id', 'model_name', 'distributor_id', 'distributor_name')
  100. def save_model(self, request, obj, form, change):
  101. obj.brand_id = strip(obj.brand_id)
  102. try:
  103. obj.brand_name = BrandInfo.objects.get(brand_id=obj.brand_id).brand_name
  104. except BrandInfo.DoesNotExist:
  105. obj.brand_name = ''
  106. obj.model_id = strip(obj.model_id)
  107. try:
  108. obj.model_name = ModelInfo.objects.get(model_id=obj.model_id).model_name
  109. except BrandInfo.DoesNotExist:
  110. obj.model_name = ''
  111. obj.distributor_id = strip(obj.distributor_id)
  112. try:
  113. obj.distributor_name = DistributorInfo.objects.get(distributor_id=obj.distributor_id).distributor_name
  114. except BrandInfo.DoesNotExist:
  115. obj.distributor_name = ''
  116. obj.factory_fee = monetary.Yuan2Fen(obj.factory_yuan)
  117. obj.factory_yuan = monetary.Fen2Yuan(obj.factory_fee)
  118. obj.save()
  119. class LatestAppInfoAdmin(admin.ModelAdmin):
  120. list_display = ('latest_adr_version_code', 'latest_adr_version_name', 'latest_adr_app', 'latest_adr_url', 'status', 'created_at', 'updated_at')
  121. list_filter = ('status', )
  122. readonly_fields = ('status', )
  123. def save_model(self, request, obj, form, change):
  124. if not obj.pk and LatestAppInfo.objects.filter(status=True).exists():
  125. return
  126. obj.latest_adr_version_name = strip(obj.latest_adr_version_name)
  127. obj.latest_adr_app = strip(obj.latest_adr_app)
  128. obj.latest_adr_url = strip(obj.latest_adr_url)
  129. obj.save()
  130. class LatestAppScreenInfoAdmin(admin.ModelAdmin):
  131. list_display = ('latest_adr_version_code', 'latest_adr_version_name', 'latest_adr_app', 'latest_adr_url', 'status', 'created_at', 'updated_at')
  132. list_filter = ('status', )
  133. readonly_fields = ('status', )
  134. def save_model(self, request, obj, form, change):
  135. if not obj.pk and LatestAppInfo.objects.filter(status=True).exists():
  136. return
  137. obj.latest_adr_version_name = strip(obj.latest_adr_version_name)
  138. obj.latest_adr_app = strip(obj.latest_adr_app)
  139. obj.latest_adr_url = strip(obj.latest_adr_url)
  140. obj.save()
  141. class ConsumeInfoSubmitLogInfoAdmin(ReadOnlyModelAdmin, admin.ModelAdmin):
  142. list_display = ('user_id', 'phone', 'lat', 'lon', 'serialNo', 'verifyResult', 'test_user', 'status', 'created_at', 'updated_at')
  143. list_filter = ('test_user', 'verifyResult', 'status')
  144. admin.site.register(AdministratorInfo, AdministratorInfoAdmin)
  145. admin.site.register(OperatorInfo, OperatorInfoAdmin)
  146. admin.site.register(BrandInfo, BrandInfoAdmin)
  147. admin.site.register(ModelInfo, ModelInfoAdmin)
  148. # admin.site.register(ModelImageInfo, ModelImageInfoAdmin)
  149. admin.site.register(DistributorInfo, DistributorInfoAdmin)
  150. admin.site.register(SaleclerkInfo, SaleclerkInfoAdmin)
  151. # admin.site.register(BrandModelDistributorPriceInfo, BrandModelDistributorPriceInfoAdmin)
  152. admin.site.register(LatestAppInfo, LatestAppInfoAdmin)
  153. admin.site.register(LatestAppScreenInfo, LatestAppScreenInfoAdmin)
  154. admin.site.register(ConsumeInfoSubmitLogInfo, ConsumeInfoSubmitLogInfoAdmin)