コード例 #1
0
ファイル: views.py プロジェクト: rrx/flyscript-portal
    def put(self, request, *args, **kwargs):
        DeviceFormSet = modelformset_factory(Device,
                                             form=DeviceListForm,
                                             extra=0)
        formset = DeviceFormSet(request.DATA)

        if formset.is_valid():
            formset.save()
            DeviceManager.clear()
            profile = UserProfile.objects.get(user=request.user)
            if not profile.profile_seen:
                # only redirect if first login
                return HttpResponseRedirect(
                    reverse('preferences') + '?next=/report')
            elif '/devices' not in request.META['HTTP_REFERER']:
                return HttpResponseRedirect(request.META['HTTP_REFERER'])
            else:
                return HttpResponseRedirect(reverse('device-list'))

        else:
            data = {'formset': formset}
            return Response(data, template_name='device_list.html')
コード例 #2
0
ファイル: reload.py プロジェクト: HackLinux/flyscript-portal
    def handle(self, *args, **options):
        self.stdout.write('Reloading report objects ... ')

        management.call_command('clean_pyc', path=settings.PROJECT_ROOT)
        management.call_command('syncdb', interactive=False)

        self.importer = Importer(buf=self.stdout)

        if options['report_id']:
            # single report
            report_id = options['report_id']
            pk = int(report_id)
            report = Report.objects.get(pk=pk)

            management.call_command('clean',
                                    applications=False,
                                    report_id=report_id,
                                    clear_cache=False,
                                    clear_logs=False)

            DeviceManager.clear()
            self.import_module(report.sourcefile)

        elif options['report_name']:
            name = options['report_name']
            try:
                report = Report.objects.get(sourcefile__endswith=name)
                report_id = report.id

                management.call_command('clean',
                                        applications=False,
                                        report_id=report_id,
                                        clear_cache=False,
                                        clear_logs=False)
                self.import_module(report.sourcefile)
            except ObjectDoesNotExist:
                self.import_module(name)

            DeviceManager.clear()

        elif options['namespace']:
            reports = Report.objects.filter(namespace=options['namespace'])

            self.capture_enabled(reports)

            for report in reports:
                management.call_command('clean',
                                        applications=False,
                                        report_id=report.id,
                                        clear_cache=False,
                                        clear_logs=False)
                self.import_module(report.sourcefile)

            self.apply_enabled()

        else:
            self.capture_enabled()

            # clear all data
            management.call_command('clean',
                                    applications=True,
                                    report_id=None,
                                    clear_cache=True,
                                    clear_logs=False)

            # start with fresh device instances
            DeviceManager.clear()

            report_dir = os.path.join(settings.PROJECT_ROOT,
                                      options['report_dir'] or 'config')

            self.importer.import_directory(report_dir, report_name=None)

            for plugin in plugins.enabled():
                if plugin.reports:
                    #from IPython import embed; embed()
                    plugin.load_reports()

            self.apply_enabled()
コード例 #3
0
    def handle(self, *args, **options):
        self.stdout.write('Reloading report objects ... ')

        management.call_command('clean_pyc', path=settings.PROJECT_ROOT)
        management.call_command('syncdb', interactive=False)

        self.importer = Importer(buf=self.stdout)

        if options['report_id']:
            # single report
            report_id = options['report_id']
            pk = int(report_id)
            report = Report.objects.get(pk=pk)

            management.call_command('clean',
                                    applications=False,
                                    report_id=report_id,
                                    clear_cache=False,
                                    clear_logs=False)

            DeviceManager.clear()
            self.import_module(report.sourcefile)

        elif options['report_name']:
            name = options['report_name']
            try:
                report = Report.objects.get(sourcefile__endswith=name)
                report_id = report.id

                management.call_command('clean',
                                        applications=False,
                                        report_id=report_id,
                                        clear_cache=False,
                                        clear_logs=False)
                self.import_module(report.sourcefile)
            except ObjectDoesNotExist:
                self.import_module(name)

            DeviceManager.clear()

        elif options['namespace']:
            reports = Report.objects.filter(namespace=options['namespace'])

            for report in reports:
                management.call_command('clean',
                                        applications=False,
                                        report_id=report.id,
                                        clear_cache=False,
                                        clear_logs=False)
                self.import_module(report.sourcefile)

        else:
            # clear all data
            management.call_command('clean',
                                    applications=True,
                                    report_id=None,
                                    clear_cache=True,
                                    clear_logs=False)

            # start with fresh device instances
            DeviceManager.clear()

            report_dir = os.path.join(settings.PROJECT_ROOT,
                                      options['report_dir'] or 'config')

            self.importer.import_directory(report_dir, report_name=None)

            for plugin in plugins.enabled():
                if plugin.reports:
                    #from IPython import embed; embed()
                    plugin.load_reports()