Esempio n. 1
0
 def get(self, request, namespace, report_slug):
     report = get_object_or_404(Report,
                                namespace=namespace,
                                slug=report_slug)
     form = CopyReportForm(report)
     return render_to_response('ajax_form.html', {'form': form},
                               context_instance=RequestContext(request))
Esempio n. 2
0
    def post(self, request, namespace, report_slug):
        report = get_object_or_404(Report,
                                   namespace=namespace,
                                   slug=report_slug)
        form = CopyReportForm(report, request.POST)
        response = {}
        if form.is_valid():
            try:
                shutil.copyfile(report.filepath, form.filepath())
                # update the title of the new report
                self.update_title(report, form)

                response['redirect'] = reverse('report-editor',
                                               args=(form.namespace,
                                                     form.slug))

                return Response(json.dumps(response))
            except IOError:
                rm_file(form.filepath())
                msg = ('Error copying file from %s to %s' %
                       (report.filepath, form.filepath()))
                template = """<li id="message_ajax"><a href="#" onclick="$('#message_ajax').fadeOut(); return false;"><small>clear</small></a> %s</li>'"""
                response['messages'] = template % msg
                return Response(json.dumps(response))
            except Exception, e:
                rm_file(form.filepath())
                msg = ('Error copying report file %s: %s' %
                       (report.filepath, str(e)))
                template = """<li id="message_ajax"><a href="#" onclick="$('#message_ajax').fadeOut(); return false;"><small>clear</small></a> %s</li>'"""
                response['messages'] = template % msg
                return Response(json.dumps(response))
Esempio n. 3
0
 def get(self, request, namespace, report_slug):
     report = get_object_or_404(Report, namespace=namespace,
                                slug=report_slug)
     form = ReportEditorForm(report.filepath)
     copyform = CopyReportForm(report)
     return render_to_response('edit.html',
                               {'report': report,
                                'form': form,
                                'ajaxform': copyform,
                                'gitavail': self._git_repo()},
                               context_instance=RequestContext(request))
Esempio n. 4
0
    def post(self, request, namespace, report_slug):
        report = get_object_or_404(Report, namespace=namespace,
                                   slug=report_slug)
        form = CopyReportForm(report, request.POST)
        response = {}
        if form.is_valid():
            try:
                shutil.copyfile(report.filepath, form.filepath())
                # update the title of the new report
                self.update_title(report, form)

                response['redirect'] = reverse('report-editor',
                                               args=(form.namespace,
                                                     form.slug))

                return Response(json.dumps(response))
            except IOError:
                rm_file(form.filepath())
                msg = ('Error copying file from %s to %s' % (report.filepath,
                                                             form.filepath()))
                template = """<li id="message_ajax"><a href="#" onclick="$('#message_ajax').fadeOut(); return false;"><small>clear</small></a> %s</li>'"""
                response['messages'] = template % msg
                return Response(json.dumps(response))
            except Exception, e:
                rm_file(form.filepath())
                msg = ('Error copying report file %s: %s' % (report.filepath,
                                                             str(e)))
                template = """<li id="message_ajax"><a href="#" onclick="$('#message_ajax').fadeOut(); return false;"><small>clear</small></a> %s</li>'"""
                response['messages'] = template % msg
                return Response(json.dumps(response))
Esempio n. 5
0
    def post(self, request, namespace, report_slug):
        report = get_object_or_404(Report, namespace=namespace,
                                   slug=report_slug)
        form = ReportEditorForm(report.filepath, request.POST)
        if form.is_valid():
            form.save()
            msg = 'Report %s saved.' % report.filepath
        else:
            msg = 'Problem saving report ... review content.'

        messages.add_message(request._request, messages.INFO, msg)
        copyform = CopyReportForm(report)
        return render_to_response('edit.html',
                                  {'report': report,
                                   'form': form,
                                   'ajaxform': copyform,
                                   'gitavail': self._git_repo()},
                                  context_instance=RequestContext(request))