25 lines
727 B
Python
25 lines
727 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 polls.models import Notice
|
|
|
|
@csrf_exempt
|
|
@polls_login_required
|
|
def notices(request):
|
|
if request.method == 'POST':
|
|
return HttpResponse(status=405)
|
|
id = request.user.id
|
|
notices = Notice.objects.filter(
|
|
is_read=False)[:10]
|
|
results = []
|
|
for o in notices:
|
|
result = dict()
|
|
result['id'] = o.id
|
|
result['content'] = o.title
|
|
result['added'] = o.added.strftime("%Y-%m-%d %H:%M:%S")
|
|
results.append(result)
|
|
return JsonResponse(results, safe=False)
|