Esempio n. 1
0
 def post(self, request, *args, **kwargs):
     lookup = self.get_lookup(kwargs)
     if lookup is None:
         return self.lookup_not_found
     form = lookup.get_form_class()(request.POST)
     context = {'form': form, }
     if form.is_valid():
         new_instance = lookup.save_model(form)
         context = {'valid': True, 'instance_id': new_instance.pk}
         return render_to_json_response(context)
     else:
         return render_to_response(self.get_template_name(lookup), context, context_instance=RequestContext(request))
Esempio n. 2
0
 def get(self, request):
     self.request = request
     request_get_copy = self.request.GET.copy()
     request_option = request_get_copy.get("request", None)
     if request_option:
         request_get_copy.pop("request")
         self.parameters = request_get_copy
         method = self.get_method(request_option)
         if method is not None:
             try:
                 context = method()
             except Exception as e:
                 return self.server_error
         else:
             return self.method_not_found
     else:
         return self.method_not_found
     return render_to_json_response(context)
Esempio n. 3
0
 def get(self, request):
     context = None
     lookup_name = request.GET.get('lookup', None)
     querystring = request.GET.get('query', None)
     form_input_value = request.GET.get('form_input_value', None)
     if lookup_name is not None:
         lookup = [l for l in REGISTERED_LOOKUPS if l.__name__ == lookup_name][0]
         if querystring is not None:
             context = []
             queryset = lookup.get_filtered_queryset(querystring)
             for instance in queryset:
                 context.append({'id': instance.pk,
                                 'description': lookup.display(instance)})
         elif form_input_value is not None:
             instance = lookup.get_object(form_input_value)
             if instance is not None:
                 display = lookup.display(instance)
             else:
                 display = ''
             context = {'description': display}
     return render_to_json_response(context)