2020-09-23 09:47:05 +00:00
|
|
|
from django.shortcuts import render
|
|
|
|
from dashboard.models import Organization
|
|
|
|
from django.http import JsonResponse
|
|
|
|
|
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
|
from polls.decorators import polls_login_required
|
|
|
|
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
@polls_login_required
|
|
|
|
def organizations(request):
|
|
|
|
category = request.GET.get('category', '1')
|
|
|
|
code = request.GET.get('code')
|
|
|
|
print(category, code)
|
|
|
|
if category == '1':
|
|
|
|
organizations = Organization.objects.exclude(
|
|
|
|
province=''
|
|
|
|
).filter(
|
|
|
|
cities='',
|
|
|
|
district=''
|
|
|
|
)
|
|
|
|
elif category == '2':
|
|
|
|
organizations = Organization.objects.exclude(
|
|
|
|
province=''
|
|
|
|
).filter(
|
|
|
|
cities=code,
|
|
|
|
district=''
|
|
|
|
)
|
|
|
|
elif category == '3':
|
|
|
|
organizations = Organization.objects.exclude(
|
|
|
|
province='',
|
|
|
|
cities='',
|
|
|
|
).filter(
|
|
|
|
district=code
|
|
|
|
)
|
|
|
|
results = []
|
|
|
|
for o in organizations:
|
|
|
|
result = dict()
|
|
|
|
result['id'] = o.id
|
|
|
|
result['name'] = o.name
|
|
|
|
result['province'] = o.province
|
|
|
|
result['cities'] = o.cities
|
|
|
|
result['district'] = o.district
|
|
|
|
results.append(result)
|
2020-10-04 15:09:07 +00:00
|
|
|
return JsonResponse({'status': 'success', 'message': results}, safe=False)
|
|
|
|
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
@polls_login_required
|
|
|
|
def organization_level(request):
|
|
|
|
profile = request.user.userprofile_set.first()
|
|
|
|
if not profile:
|
|
|
|
return JsonResponse({'status': 'error', 'message': '账户错误'})
|
|
|
|
organization = profile.organization
|
|
|
|
if not organization:
|
|
|
|
return JsonResponse({'status': 'error', 'message': '机构错误'})
|
|
|
|
level = organization.level.level
|
|
|
|
if not level:
|
|
|
|
return JsonResponse({'status': 'error', 'message': '权限错误'})
|
|
|
|
return JsonResponse({'status': 'success', 'message': {'level': level, 'organization_id': organization.id}}, safe=False)
|