Exemplo n.º 1
0
            def do_edit(request, template, **kwargs):
                template_inst = get_object_or_404(
                    ReportTemplate, slug=template['slug']
                )
                last_run = template_inst.last_run
                f = ReportTemplateForm({
                    "name": template['name'],
                    "start_date": start_date,
                    "frequency": template['frequency'],
                    "layout": template['layout'],
                    "description": template['description'],
                    "graph": graph.id,
                    "is_disabled": template['is_disabled']},
                    instance=template_inst)
                if not f.is_valid():
                    template["errors"] = f.errors
                    new_template = None
                else:
                    new_template = f.save()
                    for old in new_template.email_to.all():
                        if old.username not in template["collabs"]:
                            new_template.email_to.remove(old)
                    new_template.last_run = last_run
                    new_template.save()

                return new_template
Exemplo n.º 2
0
            def do_edit(request, template, **kwargs):
                template_inst = get_object_or_404(ReportTemplate,
                                                  slug=template['slug'])
                last_run = template_inst.last_run
                f = ReportTemplateForm(
                    {
                        "name": template['name'],
                        "start_date": start_date,
                        "frequency": template['frequency'],
                        "layout": template['layout'],
                        "description": template['description'],
                        "graph": graph.id,
                        "is_disabled": template['is_disabled']
                    },
                    instance=template_inst)
                if not f.is_valid():
                    template["errors"] = f.errors
                    new_template = None
                else:
                    new_template = f.save()
                    for old in new_template.email_to.all():
                        if old.username not in template["collabs"]:
                            new_template.email_to.remove(old)
                    new_template.last_run = last_run
                    new_template.save()

                return new_template
Exemplo n.º 3
0
 def do_new(request, template, **kwargs):
     f = ReportTemplateForm({"name": template['name'],
                             "start_date": start_date,
                             "frequency": template['frequency'],
                             "layout": template['layout'],
                             "description": template['description'],
                             "is_disabled": template["is_disabled"],
                             "graph": graph.id})
     if not f.is_valid():
         template["errors"] = f.errors
         new_template = None
     else:
         new_template = f.save()
     return new_template
Exemplo n.º 4
0
 def do_new(request, template, **kwargs):
     f = ReportTemplateForm({
         "name": template['name'],
         "start_date": start_date,
         "frequency": template['frequency'],
         "layout": template['layout'],
         "description": template['description'],
         "is_disabled": template["is_disabled"],
         "graph": graph.id
     })
     if not f.is_valid():
         template["errors"] = f.errors
         new_template = None
     else:
         new_template = f.save()
     return new_template
Exemplo n.º 5
0
def builder_endpoint(request, graph_slug):
    graph = get_object_or_404(Graph, slug=graph_slug)
    template = {}
    if request.method == "POST":
        template = json.loads(request.body)['template']
        date = template['date'].split("/")
        time = template['time'].split(":")
        try:
            start_date = datetime.datetime(int(date[2]),
                                           int(date[0]),
                                           int(date[1]),
                                           int(time[0]),
                                           int(time[1]))
        except (ValueError, IndexError):
            start_date = ""
        if template.get('slug', ''):
            template_inst = get_object_or_404(
                ReportTemplate, slug=template['slug']
            )
            last_run = template_inst.last_run
            f = ReportTemplateForm({"name": template['name'],
                                    "start_date": start_date,
                                    "frequency": template['frequency'],
                                    "layout": template['layout'],
                                    "description": template['description'],
                                    "graph": graph.id}, instance=template_inst)
            if not f.is_valid():
                template["errors"] = f.errors
            else:
                new_template = f.save()
                for old in new_template.email_to.all():
                    if old.username not in template["collabs"]:
                        new_template.email_to.remove(old)
                new_template.last_run = last_run
                new_template.save()
        else:
            f = ReportTemplateForm({"name": template['name'],
                                    "start_date": start_date,
                                    "frequency": template['frequency'],
                                    "layout": template['layout'],
                                    "description": template['description'],
                                    "graph": graph.id})
            if not f.is_valid():
                template["errors"] = f.errors
            else:
                new_template = f.save()
        if not template.get("errors", ""):
            for collab in template["collabs"]:
                collab = User.objects.get(username=collab["id"])
                new_template.email_to.add(collab)
            query_set = set()
            for row in template['layout']['layout']:
                query_set.update(set(cell['displayQuery'] for cell in row))

            queries = set(query for query in new_template.queries.all())
            query_ids = set(query.id for query in queries)
            for query in queries:
                if query.id not in query_set:
                    new_template.queries.remove(query)
            for disp_query in query_set:
                if disp_query and disp_query not in query_ids:
                    query = get_object_or_404(Query, id=disp_query)
                    new_template.queries.add(query)
            new_template.save()
    return HttpResponse(json.dumps(template), content_type='application/json')