예제 #1
0
 def response(self):
     context = {
         'start':str(self.start),
         'end':str(self.end),
     }
     for widget in self.widgets:
         context[widget.name] = str(widget.value(self.start, self.end))
     return json_response(context)
예제 #2
0
def random_string(request):
    count = request.GET.get('count', 1)
    try:
        max_length = int(request.GET.get('max_length', None))
    except:
        max_length = None
    ul = {}
    for c in range(count):
        s = unique_string()
        if max_length and len(s) > max_length:
            s = s[:max_length]
        ul[c] = s
    return json_response(ul)
예제 #3
0
    def response(self, queryset, jsonTemplatePath = None, *args):
        queryset = self.filter(queryset)

        #count how many records match the final criteria
        iTotalRecords = iTotalDisplayRecords = queryset.count()

        queryset = self.sub_queryset(queryset, False)
        # required echo response
        sEcho = self._get_int('sEcho',0)
        if jsonTemplatePath:
            #prepare the JSON with the response, consider using : from django.template.defaultfilters import escapejs
            jstonString = render_to_string(jsonTemplatePath, locals())
            response = HttpResponse(jstonString, mimetype="application/javascript")
        else:
            aaData = self.rows(queryset)
            response_dict = {}
            response_dict.update({'aaData':aaData})
            response_dict.update({'sEcho': sEcho, 'iTotalRecords': iTotalRecords, 'iTotalDisplayRecords':iTotalDisplayRecords, 'sColumns':self.sColumns})
            response =  json_response(response_dict)
        add_never_cache_headers(response)
        return response