def share(request, dashboard_id): dashboard = get_object_or_404(Dashboard, id=dashboard_id, account=request.user.account) shared_dashboard = SharedDashboard(dashboard=dashboard, created_by=request.user, valid_until=timezone.now() + timedelta(days=10)) shared_url = shared_dashboard.generate_url(request) shared_dashboard.save() return HttpResponse(json.dumps(dict(url=shared_url, id=shared_dashboard.id)), 'application/json')
def prepare_email_globale(schedule): schedule_visualizations = GlobaleScheduleVisualization.objects.filter(schedule=schedule).order_by('position') jobs = [] for schedule_visualization in schedule_visualizations: visualization = schedule_visualization.visualization err = None try: job = Job.objects.filter(completed_at__isnull=False, query__visualization=visualization, cached_until__gte=timezone.now()).order_by('-start_at')[:1].get() if job.query_checksum != job.query.checksum: err, job = execute_query(schedule.created_by, visualization) except Job.DoesNotExist: err, job = execute_query(schedule.created_by, visualization) if not err: rows, schema = job.get_rows() header = rows.pop(0) num_indexes = [i for i, v in enumerate(schema) if v.get('type') in ['FLOAT', 'INTEGER']] integer_indexes = [i for i, v in enumerate(schema) if v.get('type') in ['INTEGER']] totals = None if schedule_visualization.show_sum: totals = [reduce(lambda x,y: x + y, list(map(lambda x: x[i], rows)), 0) if v.get('type') in ['FLOAT', 'INTEGER'] else None for i, v in enumerate(schema)] jobs.append(dict(visualization=visualization, job=job, rows=rows, absolute_url=settings.MAIN_HOST + reverse('visualizations_show', kwargs=dict(visualization_id=visualization.id)), schema=schema, num_indexes=num_indexes, integer_indexes=integer_indexes, header=header, schedule=schedule_visualization, totals=totals,)) if schedule.linked_dashboard: if schedule.anonymous_link: shared_dashboard = SharedDashboard(dashboard=schedule.linked_dashboard, created_by=schedule.created_by, valid_until=timezone.now() + timedelta(days=2)) shared_dashboard.save() dashbaord_url = settings.MAIN_HOST + shared_dashboard.generate_path() else: dashbaord_url = settings.MAIN_HOST + reverse('dashboards_play', kwargs=dict(dashboard_slug=schedule.linked_dashboard.slug)) else: dashbaord_url = None body = transform(loader.render_to_string('emails/visualization_globale.html', dict(jobs=jobs, schedule=schedule, absolute_url=settings.MAIN_HOST + reverse('visualizations_show', kwargs=dict(visualization_id=visualization.id)), dashbaord_url=dashbaord_url,))) return body
def prepare_email_globale(schedule): schedule_visualizations = GlobaleScheduleVisualization.objects.filter( schedule=schedule).order_by('position') jobs = [] for schedule_visualization in schedule_visualizations: visualization = schedule_visualization.visualization err = None try: job = Job.objects.filter( completed_at__isnull=False, query__visualization=visualization, cached_until__gte=timezone.now()).order_by( '-start_at')[:1].get() if job.query_checksum != job.query.checksum: err, job = execute_query(schedule.created_by, visualization) except Job.DoesNotExist: err, job = execute_query(schedule.created_by, visualization) if not err: rows, schema = job.get_rows() header = rows.pop(0) num_indexes = [ i for i, v in enumerate(schema) if v.get('type') in ['FLOAT', 'INTEGER'] ] integer_indexes = [ i for i, v in enumerate(schema) if v.get('type') in ['INTEGER'] ] totals = None if schedule_visualization.show_sum: totals = [ reduce(lambda x, y: x + y, list(map(lambda x: x[i], rows)), 0) if v.get('type') in ['FLOAT', 'INTEGER'] else None for i, v in enumerate(schema) ] jobs.append( dict( visualization=visualization, job=job, rows=rows, absolute_url=settings.MAIN_HOST + reverse('visualizations_show', kwargs=dict(visualization_id=visualization.id)), schema=schema, num_indexes=num_indexes, integer_indexes=integer_indexes, header=header, schedule=schedule_visualization, totals=totals, )) if schedule.linked_dashboard: if schedule.anonymous_link: shared_dashboard = SharedDashboard( dashboard=schedule.linked_dashboard, created_by=schedule.created_by, valid_until=timezone.now() + timedelta(days=2)) shared_dashboard.save() dashbaord_url = settings.MAIN_HOST + shared_dashboard.generate_path( ) else: dashbaord_url = settings.MAIN_HOST + reverse( 'dashboards_play', kwargs=dict(dashboard_slug=schedule.linked_dashboard.slug)) else: dashbaord_url = None body = transform( loader.render_to_string( 'emails/visualization_globale.html', dict( jobs=jobs, schedule=schedule, absolute_url=settings.MAIN_HOST + reverse('visualizations_show', kwargs=dict(visualization_id=visualization.id)), dashbaord_url=dashbaord_url, ))) return body