def logstuff(reqlog, template, rendargs, nolog=None, listing=None): """ Logs the response in the database if logging is enabled """ if logEnabled(): if nolog is None: nolog = [] reslog = ResponseLog.create(request=reqlog, template=template) reslog.save() args = [] for key in rendargs: if key not in nolog and not isinstance(rendargs[key],(forms.Form,forms.formsets.BaseFormSet)): try: # check if an object is a list or tuple (but not string) # http://stackoverflow.com/questions/1835018/python-check-if-an-object-is-a-list-or-tuple-but-not-string assert not isinstance(rendargs.get(key), basestring) args = args + [ResponseArgument(response=reslog, name=key, value=handleFunnyCharacters(v)[:1024]) for v in rendargs.get(key) if not isinstance(v,(forms.Form,forms.formsets.BaseFormSet))] except (TypeError, AssertionError): # not iterable v = str(rendargs.get(key)) args = args + [ResponseArgument(response=reslog, name=key, value=handleFunnyCharacters(v)[:1024])] ResponseArgument.objects.bulk_create(args) if listing: recordList(reslog, listing)
def recordRequest(request): """ Logs the request in the database """ if logEnabled(): data = getDataFromRequest(request) reqlog = RequestLog.create(request) reqlog.save() args = [] for a in data.keys(): args = args + [RequestArgument(request=reqlog, name=a, value=handleFunnyCharacters(v)) for v in data.getlist(a) if v.strip() != ''] RequestArgument.objects.bulk_create(args) return reqlog else: return None