def get_placeholder_data_view(self, request, object_id): """ Return the placeholder data as dictionary. This is used in the client for the "copy" functionality. """ language = 'en' #request.POST['language'] with translation.override( language ): # Use generic solution here, don't assume django-parler is used now. obj = self.get_object(request, object_id) if obj is None: json = {'success': False, 'error': 'Page not found'} status = 404 elif not self.has_change_permission(request, obj): json = {'success': False, 'error': 'No access to page'} status = 403 else: # Fetch the forms that would be displayed, # return the data as serialized form data. status = 200 json = { 'success': True, 'object_id': object_id, 'language_code': language, 'formset_forms': self._get_object_formset_data(request, obj), } return JsonResponse(json, status=status)
def get_layout_view(self, request, id): """ Return the metadata about a layout """ try: layout = PageLayout.objects.get(pk=id) except PageLayout.DoesNotExist: json = {'success': False, 'error': 'Layout not found'} status = 404 else: template = layout.get_template() placeholders = get_template_placeholder_data(template) status = 200 json = { 'id': layout.id, 'key': layout.key, 'title': layout.title, 'placeholders': [p.as_dict() for p in placeholders], } return JsonResponse(json, status=status)
def iiif_image_api_info(request, identifier_param): """ Image Information endpoint for IIIF Image API 2.1, see http://iiif.io/api/image/2.1/#image-information """ # TODO Add support for 'application/ld+json' response when requested accept_header = request.environ.get('HTTP_ACCEPT') if accept_header == 'application/ld+json': return HttpResponseNotImplemented( "JSON-LD response is not yet supported") ik_image, __ = _get_image_or_404(identifier_param) info = { "@context": "http://iiif.io/api/image/2/context.json", "@id": request.get_full_path(), "@type": "iiif:Image", "protocol": "http://iiif.io/api/image", "width": ik_image.width, "height": ik_image.height, } # TODO Return more complete info.json response per spec if ik_image.license: info['license'] = [ik_image.license] attribution_value = u' '.join([ u"Credit: %s." % ik_image.credit if ik_image.credit else '', u"Provided by: %s." % ik_image.source if ik_image.source else '', ]).strip() if attribution_value: info['attribution'] = [{ "@value": attribution_value, "@language": "en", }] # TODO Send header "Access-Control-Allow-Origin: *" per spec? return JsonResponse(info)