Esempio n. 1
0
    def checkAppAccess(self, args):
        # get app code
        if type(args) is unicode:
            appCode = args
        else:
            if len(args) == 0:
                raise RuntimeError('Cant find app code in dashboard')
            appCode = args[0]

        # get user and db session
        user = self.get_current_user()
        session = self.getDBSession()

        # get app
        app = session.query(App).filter(App.code == appCode).first()
        if app is None:
            raise RuntimeError('Cant find app by code ' + appCode)

        self.currentAppCode = app.code

        # check access
        ruleService = RuleService(session)
        if not ruleService.isAllow(user.userId, app.appId):
            raise RuntimeError('Access denied')

        return app
Esempio n. 2
0
    def get(self, *args, **kwargs):
        # get app code
        if len(args) == 0:
            raise RuntimeError("Cant find app code in dashboard")
        appCode = args[0]

        user = self.get_current_user()

        # get app
        app = self.dbSession.query(App).filter(App.code == appCode).first()
        if app is None:
            raise RuntimeError("Cant find app by code " + appCode)

        # check access
        ruleService = RuleService(self.dbSession)
        if not ruleService.isAllow(user.userId, app.appId):
            raise RuntimeError("Access denied")

        workerId = self.get_argument("jobId")

        worker = self.getWorker(workerId)
        service = WorkerService(self.application.getResultPath(), worker)

        if worker.status != Worker.STATUS_SUCCESS:
            self.renderJSON({"redirect": "status/" + str(workerId)})
            return

        # configuration name services
        task = service.getTask()

        startDates = []
        endDates = []
        for i in task.items:
            taskItem = task.items[i]
            startDates.append(taskItem.start)
            endDates.append(taskItem.end)

        minStartDate = min(startDates)
        maxEndDate = max(endDates)

        appService = AppService(self.application.getAppConfigPath())
        appConfig = appService.getNewAppConfig(app.code)
        nameService = NameConstructor(appConfig, task)

        try:
            data = service.getResultData()["data"]["result"]
            if len(data.items()) == 0:
                self.render("dashboard/result_no_data.jinja2", {"app": app})
                return
            # chart data
            chartService = ChartConstructor(data, nameService, task)
            tableService = TableConstructor(data, nameService, task)
        except IOError as ioerr:
            self.render(
                "dashboard/result.jinja2", {"errors": [u"Ошибка чтения результатов выполнения работы"], "app": app}
            )
        else:
            html = self.render(
                "dashboard/result.jinja2",
                {
                    "app": app,
                    "data": data,
                    "tablesdata": tableService.getData(),
                    "nameService": nameService,
                    "chartService": chartService,
                    "name": worker.name,
                    "interval": task.interval,
                    "tagCloud": chartService.getTagCloud(),
                    "workerId": workerId,
                },
                _return=True,
            )

            self.renderJSON(
                {
                    "html": html,
                    "vars": {
                        "chartdata": chartService.getResult(),
                        "interval": task.interval,
                        "minStartDate": time.mktime(minStartDate.timetuple()),
                        "maxEndDate": time.mktime(maxEndDate.timetuple()),
                        "taskId": workerId,
                    },
                }
            )