61 lines
1.9 KiB
Python
61 lines
1.9 KiB
Python
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)
|
|
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, 'cities': organization.cities, 'district': organization.district}}, safe=False)
|