newmediamonitoring/polls/views/group.py

34 lines
1.0 KiB
Python

from django.shortcuts import render
from django.http import HttpResponse, JsonResponse
from django.views.decorators.csrf import csrf_exempt
import datetime
from polls.decorators import polls_login_required
from django.core.exceptions import ObjectDoesNotExist
from dashboard.models import Group
def room(request):
return render(request, 'polls/chat_text.html')
@csrf_exempt
@polls_login_required
def groups(request):
if request.method == 'POST':
return HttpResponse(status=405)
id = request.user.id
category = request.GET.get('category', '0')
if not category:
return JsonResponse({'status': 'error', 'message': '参数错误'})
groups = Group.objects.filter(status='1',classify=category)
results = []
for o in groups:
result = dict()
result['id'] = str(o.id)
result['name'] = o.name
result['image'] = request.build_absolute_uri(o.image.url)
results.append(result)
return JsonResponse({'status': 'success', 'message': results}, safe=False)