def _download_on_button_id(self, button_id, destination): """ Download a file. Returns the path to file or None if nothing was downloaded """ # mainlog.debug("_download_on_button_id() : button_id={}".format(button_id)) doc_id = self.button_data[button_id] # if os.path.isabs(full_path_client): # # The file was uploaded during this GUI session. Therefore we # # still know where we picked it from (FIXME unless someone has # # removed it...) # # return full_path_client # else: progress_bar = make_progress(_("Downloading"), 100) def progress_tracker(percent): progress_bar.setValue(int(percent)) try: path = download_document(doc_id, progress_tracker, destination) return path except Exception as exc: progress_bar.close() showErrorBox(_( "There was a problem while downloading the file from the server" ), ex=exc, object_name="file_upload_error") return None progress_bar.close()
def _add_file(self, full_path_client: str, document_category_id=None): mainlog.debug( "document widget _add_file categ={}".format(document_category_id)) if self._test_file_access(full_path_client): progress_bar = make_progress(_("Uploading"), 100) def progress_tracker(percent): progress_bar.setValue(int(percent)) try: doc_id = upload_document(full_path_client, progress_tracker) except Exception as exc: progress_bar.close() showErrorBox(_( "There was a problem while uploading the file to the server" ), ex=exc, object_name="file_upload_error") return d = self.documents_service.find_by_id(doc_id) doc = Document() doc.document_id = d.document_id doc.file_size = d.file_size doc.description = d.description doc.filename = d.filename doc.server_location = d.server_location doc.upload_date = d.upload_date if document_category_id: doc.document_category_id = document_category_id self.model.append_objects([doc])
def _add_file(self, full_path_client): """ Adds a file to the templates. First it is uploaded and then it is added to the list of files. """ if self._test_file_access(full_path_client): progress_bar = make_progress(_("Uploading"), 100) def progress_tracker(percent): progress_bar.setValue(int(percent)) try: doc_id = upload_template(full_path_client, progress_tracker, 0) except Exception as exc: progress_bar.close() showErrorBox(_( "There was a problem while uploading the file {} to the server" ).format(os.path.basename(full_path_client)), ex=exc, object_name="file_upload_error") return self.refresh_templates_list()
def _replace_file(self, full_path_client, document): if self._test_file_access(full_path_client): progress_bar = make_progress(_("Replacing"), 100) def progress_tracker(percent): progress_bar.setValue(int(percent)) try: doc_id = upload_template(full_path_client, progress_tracker, document.document_id) self.refresh_templates_list() except Exception as exc: progress_bar.close() showErrorBox(_( "There was a problem while uploading the file to the server" ), ex=exc, object_name="file_upload_error") return
def _export_to_excel(self): workbook = openpyxl.Workbook() sheet = workbook.active progress = make_progress(_("Collecting data..."), sum([len(x) - 1 for x in self.indicators])) row = 1 for ind in self._indicators_run(self.indicators): chart = ind.chart data = ind.chart.original_data #print(chart.x_legends[serie_ndx]) sheet.cell(row=row, column=1, value=chart.title) sheet.cell(row=row, column=1).font = Font(bold=True) row += 1 for col in range(len(chart.x_legends)): sheet.cell(row=row, column=2 + col, value=chart.x_legends[col]) row += 1 for serie_ndx in range(len(data)): sheet.cell(row=row, column=1, value=chart.legends[serie_ndx]) for col in range(len(data[serie_ndx])): sheet.cell(row=row, column=2 + col, value=data[serie_ndx][col]) row += 1 row += 2 # Space between kpi's progress.setValue(progress.value() + 1) name = make_temp_file('indicators_', 'xlsx') workbook.save(name) open_xlsx(name)
def refresh_action(self): # Reimplements parent method ! self.remote_indicators_service.clear_caches() mainlog.debug("Refreshing {}".format(self.month_chooser.base_date)) # begin, end = month_period_as_date(self.month_chooser.base_date) begin, end = month_before(self.month_chooser.base_date, self.MONTHS_PERIOD - 1), self.month_chooser.base_date progress = make_progress(_("Collecting data..."), sum([len(x) - 1 for x in self.indicators])) mainlog.debug("Indicator run = {}".format( self._indicators_run(self.indicators))) for ind in self._indicators_run(self.indicators): ind._gather_data(begin, end) progress.setValue(progress.value() + 1) ind.repaint() for sf in self._sub_frames: if sf.original_title(): sf.set_title(sf.original_title().replace( "%MONTH%", date_to_my(self.month_chooser.base_date, full=True)))