def home(request): template = 'index.html' model_entries_graph_meta = {'timedelta': 'DAILY', 'Model': RequestLog} model_entries_graph_data = get_model_entries_graph_data( model_entries_graph_meta) attribute_value_frequency_meta_1 = { 'Model': RequestLog, 'model_attribute': 'request_method', } attribute_value_frequency_meta_2 = { 'Model': RequestLog, 'model_attribute': 'http_host', } attribute_value_frequency_meta_3 = { 'Model': RequestLog, 'model_attribute': 'query_string', } attribute_value_frequency_attrs = [ 'request_method', 'http_host', 'query_string' ] attribute_value_frequency_graph_data_1 = get_attribute_value_frequency_graph_data( attribute_value_frequency_meta_1) attribute_value_frequency_graph_data_2 = get_attribute_value_frequency_graph_data( attribute_value_frequency_meta_2) attribute_value_frequency_graph_data_3 = get_attribute_value_frequency_graph_data( attribute_value_frequency_meta_3) attribute_value_frequency_containers = [] for attr in attribute_value_frequency_attrs: attribute_value_frequency_containers.append({ 'container_class': '{0}-attribute-value-frequency-graph-container'.format(attr), 'id': '{0}-attribute-value-frequency-id'.format(attr) }) ctx = { 'model_entries_graph_data': model_entries_graph_data, 'attribute_value_frequency_graph_data_1': attribute_value_frequency_graph_data_1, 'attribute_value_frequency_graph_data_2': attribute_value_frequency_graph_data_2, 'attribute_value_frequency_graph_data_3': attribute_value_frequency_graph_data_3, 'attribute_value_frequency_containers': attribute_value_frequency_containers } ctx = RequestContext(request, ctx) return render_to_response(template, RequestContext(request, ctx))
def home(request): template = 'index.html' model_entries_graph_meta = { 'timedelta': 'DAILY', 'Model': RequestLog } model_entries_graph_data = get_model_entries_graph_data(model_entries_graph_meta) attribute_value_frequency_meta_1 = { 'Model': RequestLog, 'model_attribute': 'request_method', } attribute_value_frequency_meta_2 = { 'Model': RequestLog, 'model_attribute': 'http_host', } attribute_value_frequency_meta_3 = { 'Model': RequestLog, 'model_attribute': 'query_string', } attribute_value_frequency_attrs = [ 'request_method', 'http_host', 'query_string' ] attribute_value_frequency_graph_data_1 = get_attribute_value_frequency_graph_data( attribute_value_frequency_meta_1) attribute_value_frequency_graph_data_2 = get_attribute_value_frequency_graph_data( attribute_value_frequency_meta_2) attribute_value_frequency_graph_data_3 = get_attribute_value_frequency_graph_data( attribute_value_frequency_meta_3) attribute_value_frequency_containers = [] for attr in attribute_value_frequency_attrs: attribute_value_frequency_containers.append({ 'container_class': '{0}-attribute-value-frequency-graph-container'.format(attr), 'id': '{0}-attribute-value-frequency-id'.format(attr) }) ctx = { 'model_entries_graph_data': model_entries_graph_data, 'attribute_value_frequency_graph_data_1': attribute_value_frequency_graph_data_1, 'attribute_value_frequency_graph_data_2': attribute_value_frequency_graph_data_2, 'attribute_value_frequency_graph_data_3': attribute_value_frequency_graph_data_3, 'attribute_value_frequency_containers': attribute_value_frequency_containers } ctx = RequestContext(request, ctx) return render_to_response(template, RequestContext(request, ctx))
def analytics_view(self, request, applabel): """View to render graph for a registered model """ template = 'index.html' graph_meta = { 'Model': self.model } start_datetime = getattr(self, 'start_datetime') if start_datetime: graph_meta['start_datetime'] = self.start_datetime end_datetime = getattr(self, 'end_datetime') if end_datetime: graph_meta['end_datetime'] = self.end_datetime if start_datetime is None and end_datetime is None: graph_meta['start_datetime'] = datetime.now() - timedelta(weeks=self.weeks) graph_meta['time_delta'] = self.time_delta is_attribute = getattr(self, 'is_attribute') if is_attribute and self.model_attribute: graph_meta['model_attribute'] = self.model_attribute graph_data = get_attribute_value_frequency_graph_data( graph_meta) else: graph_data = get_model_entries_graph_data( graph_meta) ctx = {'title': self.get_graph_title()} is_graph = graph_data.pop('graph', None) if is_graph: graph_type = self.graph_type ctx.update({ 'graph_data': graph_data, 'graph_type': graph_type, }) else: template = 'empty_state.html' ctx = RequestContext(request, ctx) return render_to_response(template, ctx)
def analytics_view(self, request, applabel): """View to render graph for a registered model """ template = 'index.html' graph_meta = {'Model': self.model} start_datetime = getattr(self, 'start_datetime') if start_datetime: graph_meta['start_datetime'] = self.start_datetime end_datetime = getattr(self, 'end_datetime') if end_datetime: graph_meta['end_datetime'] = self.end_datetime if start_datetime is None and end_datetime is None: graph_meta['start_datetime'] = datetime.now() - timedelta( weeks=self.weeks) graph_meta['time_delta'] = self.time_delta is_attribute = getattr(self, 'is_attribute') if is_attribute and self.model_attribute: graph_meta['model_attribute'] = self.model_attribute graph_data = get_attribute_value_frequency_graph_data(graph_meta) else: graph_data = get_model_entries_graph_data(graph_meta) ctx = {'title': self.get_graph_title()} is_graph = graph_data.pop('graph', None) if is_graph: graph_type = self.graph_type ctx.update({ 'graph_data': graph_data, 'graph_type': graph_type, }) else: template = 'empty_state.html' ctx = RequestContext(request, ctx) return render_to_response(template, ctx)