href="/Kodo/kodo/pulls"> 合并请求 0 提交历史 181 版本发布 0

暂无描述

admin.py 2.8KB

    # -*- coding: utf-8 -*- from curtail_uuid import CurtailUUID from django.contrib import admin from django.contrib.auth.hashers import make_password from account.models import (LensmanIncomeExpensesInfo, LensmanInfo, LensmanLoginLogInfo, UserIncomeExpensesInfo, UserInfo, UserLoginLogInfo) class LensmanInfoAdmin(admin.ModelAdmin): readonly_fields = ('lensman_id', 'encryption', ) list_display = ('lensman_id', 'username', 'name', 'sex', 'phone', 'location', 'proportion', 'status', 'created_at', 'updated_at') search_fields = ('name', 'phone', 'location') list_filter = ('sex', 'status') def save_model(self, request, obj, form, change): if not obj.lensman_id: user_id = CurtailUUID.uuid(UserInfo, 'user_id') obj.lensman_id = user_id fields = { 'name': obj.name, 'sex': obj.sex, 'phone': obj.phone, 'location': obj.location, 'user_status': obj.status, } user, created = UserInfo.objects.get_or_create(user_id=obj.lensman_id, user_from=UserInfo.LENSMAN_USER, defaults=fields) if not created: for key, value in fields.iteritems(): setattr(user, key, value) user.save() if obj.password: obj.encryption = make_password(obj.password, None, 'pbkdf2_sha256') obj.password = None obj.save() class LensmanLoginLogInfoAdmin(admin.ModelAdmin): list_display = ('lensman_id', 'login_ip', 'login_result', 'status', 'created_at', 'updated_at') class LensmanIncomeExpensesInfoAdmin(admin.ModelAdmin): list_display = ('lensman_id', 'photo_id', 'type', 'amount', 'balance', 'remark', 'status', 'created_at', 'updated_at') list_filter = ('type', 'status') class UserInfoAdmin(admin.ModelAdmin): readonly_fields = ('user_id', ) list_display = ('user_id', 'user_from', 'username', 'wx_uid', 'name', 'sex', 'nickname', 'phone', 'location', 'user_status', 'status', 'created_at', 'updated_at') search_fields = ('name', 'phone', 'location') list_filter = ('user_from', 'sex', 'user_status', 'status') class UserLoginLogInfoAdmin(admin.ModelAdmin): list_display = ('user_id', 'login_ip', 'login_result', 'status', 'created_at', 'updated_at') class UserIncomeExpensesInfoAdmin(admin.ModelAdmin): list_display = ('user_id', 'photo_id', 'type', 'amount', 'balance', 'remark', 'status', 'created_at', 'updated_at') list_filter = ('type', 'status') admin.site.register(LensmanInfo, LensmanInfoAdmin) admin.site.register(LensmanLoginLogInfo, LensmanLoginLogInfoAdmin) admin.site.register(LensmanIncomeExpensesInfo, LensmanIncomeExpensesInfoAdmin) admin.site.register(UserInfo, UserInfoAdmin) admin.site.register(UserLoginLogInfo, UserLoginLogInfoAdmin) admin.site.register(UserIncomeExpensesInfo, UserIncomeExpensesInfoAdmin)
kodo - Gogs: Go Git Service

Нет описания

models.py 2.9KB

    # -*- coding: utf-8 -*- from django.conf import settings from django.db import models from django.utils.translation import ugettext_lazy as _ from django_models_ext import BaseModelMixin, SexModelMixin from shortuuidfield import ShortUUIDField class ScreenAdminInfo(BaseModelMixin): ACTIVATED = 1 DISABLED = 2 DELETED = 3 USER_STATUS_TUPLE = ( (ACTIVATED, u'已激活'), (DISABLED, u'已禁用'), (DELETED, u'已删除'), ) admin_id = ShortUUIDField(_(u'admin_id'), max_length=32, blank=True, null=True, help_text=u'大屏管理员唯一标识', db_index=True, unique=True) unionid = models.CharField(_(u'unionid'), max_length=32, blank=True, null=True, help_text=u'微信 Union ID', db_index=True) openid = models.CharField(_(u'openid'), max_length=32, blank=True, null=True, help_text=u'微信 Open ID', db_index=True) name = models.CharField(_(u'name'), max_length=8, blank=True, null=True, help_text=u'用户姓名') sex = models.IntegerField(_(u'sex'), choices=SexModelMixin.SEX_TUPLE, default=SexModelMixin.UNKNOWN, help_text=u'用户性别') nickname = models.CharField(_(u'nickname'), max_length=255, blank=True, null=True, help_text=u'用户昵称') avatar = models.CharField(_(u'avatar'), max_length=255, blank=True, null=True, help_text=u'用户头像') phone = models.CharField(_(u'phone'), max_length=11, blank=True, null=True, help_text=u'用户电话', db_index=True) country = models.CharField(_(u'country'), max_length=16, blank=True, null=True, help_text=u'用户国家') province = models.CharField(_(u'province'), max_length=16, blank=True, null=True, help_text=u'用户省份') city = models.CharField(_(u'city'), max_length=16, blank=True, null=True, help_text=u'用户城市') location = models.CharField(_(u'location'), max_length=255, blank=True, null=True, help_text=u'用户地址') brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True) brand_name = models.CharField(_(u'brand_name'), max_length=255, blank=True, null=True, help_text=u'品牌名称') user_status = models.IntegerField(_(u'user_status'), choices=USER_STATUS_TUPLE, default=ACTIVATED, help_text=u'管理员状态', db_index=True) class Meta: verbose_name = _(u'ScreenAdminInfo') verbose_name_plural = _(u'ScreenAdminInfo') unique_together = ( ('brand_id', 'unionid', 'openid'), ) def __unicode__(self): return '%d' % self.pk @property def final_avatar(self): return self.avatar and self.avatar.replace(settings.QINIU_FILE_URL_BEFORE, settings.QINIU_FILE_URL_AFTER).replace(settings.QINIU_FILE_URL_BEFORE2, settings.QINIU_FILE_URL_AFTER) @property def data(self): return { 'admin_id': self.admin_id, 'nickname': self.nickname, 'avatar': self.final_avatar, }