예제 #1
0
    def update_files_in_db(self):
        files = os.listdir(GlobalConstants.filesPath)
        original_company_id = admin.company_id  # to restore original company id on db
        admin.company_id = sample_organiztion_id  # using sample organization as default company id
        updated_files = []
        for file in files:
            if os.path.isdir(os.path.join(GlobalConstants.filesPath, file)):
                continue
            filename, extension = os.path.splitext(file)
            if filename[:2] == "~$":  # these are temp excel files created by ms excel
                os.remove(os.path.join(GlobalConstants.filesPath, file))
                continue
            try:
                id_ = UUID(filename)  # if file name is uuid that means this might already has entry in db
                db_row = db.session.query(models.File).filter_by(id=filename).first()
                if not db_row:  # if row is not found then create a new File object with this file
                    db_row = self.create_new(file, extension)
                if db_row.processed:  # if file is already processed these means we haven't moved it in archived
                    logger.info(f"{file} is already processed! Skipping it")
                    self.move_processed_file(file)
            except ValueError:  # we get value error when filename is not uuid, so update that file in db & rename it
                updated_files.append(self.create_new(file, extension))

        admin.company_id = original_company_id
        self.update_unprocessed_rows()  # fill unprocessed data in unprocessed_rows
        return updated_files
예제 #2
0
파일: routes.py 프로젝트: Athos1972/PoLZy
def notifications():
    user = auth.current_user()
    toast = db.session.query(ToastNotifications).filter_by(
        seen_at=None).filter_by(user_id=user.id).filter_by(
            company_id=user.company_id).first()
    if toast:
        if toast.type == "badge":
            badge = db.session.query(GamificationBadge).filter_by(
                id=toast.message).first()
            if badge:
                messenger.announce_badge(badge=badge, duration=5000)
            else:
                logger.info(f"Badge id {str(toast.message)} not found.")
        else:
            msg = json.dumps({
                'text': toast.message,
                'autoHideDuration': toast.duration,
                'variant': toast.type,
                'anchorOrigin': {
                    'horizontal': toast.horizontal,
                    'vertical': toast.vertical,
                }
            })
            messenger.announce(f'data: {msg}\n\n')
        toast.set_seen()
        return Response(response=f"New Notifications found", status=200)
    return Response(response=f"No Notification", status=200)
예제 #3
0
    def _get_default_data(self):
        stage = 'pqa'
        output_dir = ''
        offline = False
        try:
            config = configparser.ConfigParser()
            # pathlib.Path resolves issue of lowercase path stored in __file__ which was creating issue in configparser
            config.read(self.setting_file)
            default = config["Default"]
        except Exception as ex:
            logger.critical(f"Exception while reading config file: {ex}")
            return offline, output_dir, stage

        stage = default.get("stage", stage)

        unchecked_path = default.get("PDFOutput")
        try:
            if unchecked_path:
                Path(unchecked_path).mkdir(parents=True, exist_ok=True)
                output_dir = unchecked_path
        except Exception as ex:
            output_dir = ''
            logger.info(f"Error during Path creation: {ex}")

        if default.get("offline", "").lower().strip() == "true":
            offline = True
        return offline, output_dir, stage
예제 #4
0
 def check_processable(cls,
                       data: dict,
                       filename: str,
                       original_filename=""):
     """
     This is an important method which should be override in inherited class. Please define the logic here to
     see if the data or filename has any hint which leads to believe that the data should be processed by this class.
     Please refer the logic below for further knowledge.
     :param data:
     :param filename:
     :param original_filename:
     :return:
     """
     # we try to find flags here which can determine if this class can process targetted data
     for key in data.keys(
     ):  # trying to see if data has as particular thing which only belongs to current antrag
         if key.lower().strip() == "product" or key.lower().strip(
         ) == "produkt":
             if data[key].lower() == "rs" or data[key].lower(
             ) == "rechtschutz":
                 logger.info(f"{cls.__class__.__name__} will process data")
                 return True
     if "rs_" in filename.lower() or "rechtschutz" in filename.lower(
     ):  # else try to determine it with classname
         return True
     elif "rs_" in original_filename.lower(
     ) or "rechtschutz" in original_filename.lower():
         return True
     logger.info("No class found to process data")
     return False
예제 #5
0
 def getInstance():
     """
     Method to get the singleton instance into any calling class/form
     """
     if not ConfigurationProvider.__instance__:
         logger.info("ConfigurationProvider instance created")
         ConfigurationProvider()
     logger.debug("returning existing ConfigurationProvider")
     return ConfigurationProvider.__instance__
예제 #6
0
 def translate(self, word, language=None):
     if not language:
         language = self.default_language
     language = language.lower()
     if language == "en":
         return word
     translations = self.data.get(word)
     if translations:
         result = translations.get(language)
     else:
         result = word
         logger.info(f'Translation of "{word}" for language "{language}" not found!')
     return result
예제 #7
0
 def __init__(self, setting_file=Path(os.path.abspath(__file__)).parent.parent.joinpath("run_setting.ini")):
     logger.info("Executing __init__ in ConfigurationProvider")
     self.configsRead = {}
     self.badConfigs = {}
     # pathToConfig can and should be overwritten if needed otherwise:
     self.pathToConfig = Path(os.getcwd()).joinpath("Configurations")
     self.basePath = Path(os.getcwd())
     self.setting_file = setting_file
     if not self.pathToConfig.exists():
         self.pathToConfig = Path(os.path.abspath(__file__)).parent.parent.joinpath("Configurations")
         self.basePath = Path(os.path.abspath(__file__)).parent.parent
     result = self.__checkAndReadConfigurations("default")
     if not result:
         logger.critical("Default configuration was not found. Aborting.")
         raise NotImplementedError("Default configuration not found. Aborting.")
     self.language = "en"  # default fallback language is english
     self.offline, self.PDFOutput, self.defaultStage = self._get_default_data()
예제 #8
0
    def __checkIfEmptyValue(
            inValue) -> bool:  # Will return true if empty, flase if not empty.
        if not inValue:
            return True
        if isinstance(inValue, str):
            if len(inValue.strip()) > 0:
                return False
            return True
        if isinstance(inValue, (int, float)):
            return False
        if isinstance(inValue, (list, dict)):
            return len(inValue) == 0
        if isinstance(inValue, FieldVisibilityTypes):
            return False

        logger.info(
            f"not sure how to handle this field value {inValue}, it's type {type(inValue)}. Will parse to FE"
        )
        return True
예제 #9
0
파일: Antrag.py 프로젝트: Athos1972/PoLZy
    def updateFieldValues(self, updateValues):
        """
        Frontend (or anything) sends new values for fields of antrag instance.
        If the values are really new/changed, we execute follow up processes.
        :param updateValues: dict of {<field>:<value>}
        :return: Nothing
        """
        logger.info(
            f'New Values (most probably from Frontend):\n{updateValues}')

        if not self.status:  # return if status is empty  # take a look sir
            return

        if AntragsStatus.getStatusNumberFromText(
                self.status) >= AntragsStatus.getStatusNumberFromText(
                    AntragsStatus.s800_sent):
            self.announceMessage(
                "Antrag bereits gesendet. Leider keine Änderug mehr möglich.")
            return

        self._updateFieldValues(updateValues)
예제 #10
0
파일: Activity.py 프로젝트: Athos1972/PoLZy
    def _saveXMLorJSONResultAsPrettyPrinted(self,
                                            resultToPrint,
                                            operation: str = None):
        """
        Used for debugging when we want to save requests/responses from XML or JSON to files.
        :param resultToPrint:
        :param operation:
        :return:
        """
        if not LogLevelUpdater().saveJson:
            return

        if not operation:
            operation = self.__class__.__name__

        try:
            lFileNameResult = f"{self.configurationProvider.basePath}/JsonFilesDelete/{self.polizze.polizzenNummer}_" \
                              f"{operation}_" \
                              f"{datetime.now().strftime(GlobalConstants.dateFormatLong)}_reply.json"
        except Exception:
            if hasattr(self, "antrag"):
                lFileNameResult = f"{self.configurationProvider.basePath}/JsonFilesDelete/" \
                                  f"Antrag_{self.antrag.sapClient}_" \
                                  f"{self.antrag.productName.replace('/', '_')}_" \
                                  f"{operation}_{datetime.now().strftime(GlobalConstants.dateFormatLong)}_reply.json"
            else:
                lFileNameResult = f"{self.configurationProvider.basePath}/JsonFilesDelete/" \
                                  f"UnknownRootObject_" \
                                  f"{operation}_{datetime.now().strftime(GlobalConstants.dateFormatLong)}_reply.json"

        if isinstance(resultToPrint, dict):
            try:
                with open(lFileNameResult, "w") as resultFile:
                    json.dump(resultToPrint, fp=resultFile, indent=4)
                logger.debug(f"File written: {lFileNameResult}")
                return
            except Exception as e:
                logger.critical(f"Fehler beim JSON-Dump {e}")
                return

        if not resultToPrint:
            logger.info(
                "Should have printed result of call, but there was nothing in it."
            )
            return

        try:
            lDOMString = xml.dom.minidom.parseString(resultToPrint)
            with open(lFileNameResult, "w") as resultFile:
                resultFile.write(lDOMString.toprettyxml())
            logger.debug(f"File written: {lFileNameResult}")
            return
        except Exception as e:
            logger.debug(
                f"Error during XML-Dump: {e}, will fallback to text dump.")

        # If we can't write it as XML nor JSON, maybe we can save a text at least:
        try:
            with open(lFileNameResult, "w") as resultFile:
                resultFile.write(str(resultToPrint))
            logger.debug(f"File written {lFileNameResult}")
        except Exception as e:
            logger.critical(
                f"Error {e} during writing of interface file. Filename was {lFileNameResult}. "
                f"resultToPrint was {resultToPrint}. Error as ")