api for ajax requests
This commit is contained in:
parent
462cba2416
commit
a9775bdd73
@ -9,14 +9,8 @@
|
|||||||
:copyright: 2011 by the OpenSlides team, see AUTHORS.
|
:copyright: 2011 by the OpenSlides team, see AUTHORS.
|
||||||
:license: GNU GPL, see LICENSE for more details.
|
:license: GNU GPL, see LICENSE for more details.
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
import json
|
|
||||||
except ImportError:
|
|
||||||
import simplejson as json
|
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from django.http import HttpResponse
|
|
||||||
from django.shortcuts import render_to_response, redirect
|
from django.shortcuts import render_to_response, redirect
|
||||||
from django.template import RequestContext
|
from django.template import RequestContext
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
@ -33,7 +27,7 @@ from openslides.poll.models import Poll
|
|||||||
from openslides.system.api import config_set, config_get
|
from openslides.system.api import config_set, config_get
|
||||||
from openslides.utils.template import render_block_to_string
|
from openslides.utils.template import render_block_to_string
|
||||||
from openslides.utils.utils import template, permission_required, \
|
from openslides.utils.utils import template, permission_required, \
|
||||||
del_confirm_form
|
del_confirm_form, ajax_request
|
||||||
from openslides.utils.pdf import print_agenda
|
from openslides.utils.pdf import print_agenda
|
||||||
from poll.models import Poll, Option
|
from poll.models import Poll, Option
|
||||||
|
|
||||||
@ -85,7 +79,7 @@ def beamer(request):
|
|||||||
jsondata = {'content': content,
|
jsondata = {'content': content,
|
||||||
'title': data['title'],
|
'title': data['title'],
|
||||||
'time': datetime.now().strftime('%H:%M')}
|
'time': datetime.now().strftime('%H:%M')}
|
||||||
return HttpResponse(json.dumps(jsondata))
|
return ajax_request(jsondata)
|
||||||
else:
|
else:
|
||||||
return render_to_response(template,
|
return render_to_response(template,
|
||||||
data,
|
data,
|
||||||
@ -163,8 +157,7 @@ def set_active(request, item_id, summary=False):
|
|||||||
except Item.DoesNotExist:
|
except Item.DoesNotExist:
|
||||||
messages.error(request, _('Item ID %d does not exist.') % int(item_id))
|
messages.error(request, _('Item ID %d does not exist.') % int(item_id))
|
||||||
if request.is_ajax():
|
if request.is_ajax():
|
||||||
jsondata = {'active': item_id}
|
return ajax_request({'active': item_id})
|
||||||
return HttpResponse(json.dumps(jsondata))
|
|
||||||
|
|
||||||
return redirect(reverse('item_overview'))
|
return redirect(reverse('item_overview'))
|
||||||
|
|
||||||
@ -179,14 +172,15 @@ def set_closed(request, item_id, closed=True):
|
|||||||
item.set_closed(closed)
|
item.set_closed(closed)
|
||||||
except Item.DoesNotExist:
|
except Item.DoesNotExist:
|
||||||
messages.error(request, _('Item ID %d does not exist.') % int(item_id))
|
messages.error(request, _('Item ID %d does not exist.') % int(item_id))
|
||||||
|
|
||||||
if request.is_ajax():
|
if request.is_ajax():
|
||||||
if closed:
|
if closed:
|
||||||
link = reverse('item_open', args=[item.id])
|
link = reverse('item_open', args=[item.id])
|
||||||
else:
|
else:
|
||||||
link = reverse('item_close', args=[item.id])
|
link = reverse('item_close', args=[item.id])
|
||||||
jsondata = {'closed': closed,
|
|
||||||
'link': link}
|
return ajax_request({'closed': closed,
|
||||||
return HttpResponse(json.dumps(jsondata))
|
'link': link})
|
||||||
return redirect(reverse('item_overview'))
|
return redirect(reverse('item_overview'))
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,9 +10,14 @@
|
|||||||
:license: GNU GPL, see LICENSE for more details.
|
:license: GNU GPL, see LICENSE for more details.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
import json
|
||||||
|
except ImportError:
|
||||||
|
import simplejson as json
|
||||||
|
|
||||||
from django.shortcuts import render_to_response, redirect
|
from django.shortcuts import render_to_response, redirect
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.http import HttpResponseForbidden
|
from django.http import HttpResponse, HttpResponseForbidden
|
||||||
from django.template import RequestContext
|
from django.template import RequestContext
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.core.context_processors import csrf
|
from django.core.context_processors import csrf
|
||||||
@ -71,3 +76,10 @@ def delete_default_permissions():
|
|||||||
for p in Permission.objects.all():
|
for p in Permission.objects.all():
|
||||||
if p.codename.startswith('add') or p.codename.startswith('delete') or p.codename.startswith('change'):
|
if p.codename.startswith('add') or p.codename.startswith('delete') or p.codename.startswith('change'):
|
||||||
p.delete()
|
p.delete()
|
||||||
|
|
||||||
|
def ajax_request(data):
|
||||||
|
"""
|
||||||
|
generates a HTTPResponse-Object with json-Data for a
|
||||||
|
ajax response
|
||||||
|
"""
|
||||||
|
return HttpResponse(json.dumps(data))
|
||||||
|
Loading…
Reference in New Issue
Block a user