feat: update medical training case and auth modules
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from rest_framework_simplejwt.tokens import RefreshToken
|
||||
|
||||
from config.exceptions import AppError
|
||||
|
||||
ALLOWED_ROLE_TYPES = ('student', 'doctor', 'teacher')
|
||||
|
||||
|
||||
@@ -9,17 +11,42 @@ def get_tokens_for_user(user):
|
||||
|
||||
|
||||
def build_user_response(user):
|
||||
inst = user.institution if user.institution_id else None
|
||||
return {
|
||||
'id': user.id,
|
||||
'username': user.username,
|
||||
'phone': user.phone,
|
||||
'real_name': user.real_name,
|
||||
'role_type': user.role_type,
|
||||
'institution': user.institution.name if user.institution_id else None,
|
||||
'institution_code': inst.code if inst else None,
|
||||
'institution_name': inst.name if inst else None,
|
||||
'department': user.department.name if user.department_id else None,
|
||||
}
|
||||
|
||||
|
||||
def resolve_or_create_institution(code, name):
|
||||
"""按机构编码查找,不存在则自动创建。
|
||||
|
||||
Args:
|
||||
code: 机构编码(必填,唯一标识)
|
||||
name: 机构名称(必填,创建时使用)
|
||||
Returns:
|
||||
Institution 实例
|
||||
"""
|
||||
from apps.user.models import Institution
|
||||
|
||||
if not code:
|
||||
raise AppError('USER_INSTITUTION_CODE_REQUIRED', '机构编码不能为空')
|
||||
if not name:
|
||||
raise AppError('USER_INSTITUTION_REQUIRED', '机构名称不能为空')
|
||||
|
||||
institution, _ = Institution.objects.get_or_create(
|
||||
code=code,
|
||||
defaults={'name': name, 'type': 'hospital'},
|
||||
)
|
||||
return institution
|
||||
|
||||
|
||||
def get_client_ip(request):
|
||||
xff = request.META.get('HTTP_X_FORWARDED_FOR')
|
||||
if xff:
|
||||
|
||||
Reference in New Issue
Block a user