def response_view(request, responseid, template): response = get_object_or_404(Response, id=responseid) mlt = None records = None errors = [] if (request.user.is_authenticated() and request.user.has_perm('analytics.can_view_dashboard')): mlt = ResponseDocType.from_obj(response).mlt().execute() records = [ (u'Response records', Record.objects.records(response)), ] jobs = GengoJob.objects.filter( object_id=response.id, content_type=ContentType.objects.get_for_model(response) ) for job in jobs: records.append( (u'Gengo job record {0}'.format(job.id), job.records) ) # We don't pass the response directly to the template and instead # do some data tweaks here to make it more palatable for viewing. return render(request, template, { 'errors': errors, 'response': response, 'mlt': mlt, 'records': records, })
def response_view(request, responseid, template): response = get_object_or_404(Response, id=responseid) mlt = None records = None errors = [] if (request.user.is_authenticated() and request.user.has_perm('analytics.can_view_dashboard')): mlt = ResponseDocType.from_obj(response).mlt().execute() records = [ (u'Response records', Record.objects.records(response)), ] jobs = GengoJob.objects.filter( object_id=response.id, content_type=ContentType.objects.get_for_model(response)) for job in jobs: records.append( (u'Gengo job record {0}'.format(job.id), job.records)) # We don't pass the response directly to the template and instead # do some data tweaks here to make it more palatable for viewing. return render(request, template, { 'errors': errors, 'response': response, 'mlt': mlt, 'records': records, })
def timezone_view(request): """Admin view showing times and timezones in data.""" # Note: This is an admin page that gets used once in a blue moon. # As such, I'm taking some liberties (hand-indexing the response, # time.sleep, etc) that I would never take if it was used more # often or was viewable by users. If these two assumptions ever # change, then this should be rewritten. from fjord.feedback.models import ( Response, ResponseDocType, ResponseDocTypeManager ) from fjord.feedback.tests import ResponseFactory from fjord.search.index import get_es, get_index_name server_time = datetime.now() # Create a new response. resp = ResponseFactory() resp_time = resp.created # Index the response by hand so we know it gets to # Elasticsearch. Otherwise it gets done by celery and we don't # know how long that'll take. doc = ResponseDocType.extract_doc(resp) ResponseDocTypeManager.bulk_index(docs=[doc]) # Fetch the response from the db. resp = Response.objects.get(id=resp.id) resp2_time = resp.created # Refresh and sleep 5 seconds as a hand-wavey way to make sure # that Elasticsearch has had time to refresh the index. get_es().indices.refresh(get_index_name()) time.sleep(5) s = ResponseDocTypeManager.search().filter('term', id=resp.id).execute() es_time = s[0].created # Delete the test response which also deletes it in the index. resp.delete() return render(request, 'admin/timezone_view.html', { 'server_time': server_time, 'resp_time': resp_time, 'resp2_time': resp2_time, 'es_time': es_time })