feat: update login api
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from apps.user.models import Institution
|
||||
from apps.user.auth import TRIAL_INSTITUTION_NAME, TRIAL_INSTITUTION_CODE
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = '初始化预留试用机构「北大医学部(实验室)试用」'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
inst, created = Institution.objects.get_or_create(
|
||||
code=TRIAL_INSTITUTION_CODE,
|
||||
defaults={'name': TRIAL_INSTITUTION_NAME, 'type': 'hospital'},
|
||||
)
|
||||
|
||||
if created:
|
||||
self.stdout.write(self.style.SUCCESS(
|
||||
f'[创建] 试用机构: {inst.code} / {inst.name}'
|
||||
))
|
||||
elif inst.name != TRIAL_INSTITUTION_NAME:
|
||||
old_name = inst.name
|
||||
inst.name = TRIAL_INSTITUTION_NAME
|
||||
inst.save(update_fields=['name'])
|
||||
self.stdout.write(self.style.WARNING(
|
||||
f'[更新] 试用机构名称: {old_name} -> {inst.name}'
|
||||
))
|
||||
else:
|
||||
self.stdout.write(self.style.WARNING(
|
||||
f'[已存在] 试用机构: {inst.code} / {inst.name}'
|
||||
))
|
||||
Reference in New Issue
Block a user