newmediamonitoring/polls/views/group.py

30 lines
873 B
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
groups = Group.objects.filter(status='1')
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)