Example #1
0
    def permit_details(self, request, bag_id):
        response = DecosJoinRequest().get_permits_by_bag_id(bag_id)
        serializer = DecosPermitSerializer(data=response, many=True)

        if serializer.is_valid():
            return Response(serializer.data)
        return Response(serializer.initial_data)
    def permit_details(self, request, bag_id, dt=None):
        if not dt:
            dt = datetime.today()
        response = DecosJoinRequest().get_decos_entry_by_bag_id(bag_id, dt)
        serializer = DecosPermitSerializer(data=response, many=True)

        if serializer.is_valid():
            return Response(serializer.data)
        return Response(serializer.initial_data)
Example #3
0
    def get_permits_by_bag_id(self, bag_id):
        response_decos_obj = self.get_decos_object_with_bag_id(bag_id)
        permits = []

        if response_decos_obj:
            response_decos_folder = self._get_decos_folder(response_decos_obj)

            if response_decos_folder:
                for folder in response_decos_folder["content"]:
                    serializer = DecosJoinFolderFieldsResponseSerializer(
                        data=folder["fields"])

                    if serializer.is_valid():
                        ser_data = {
                            "permit_granted":
                            self._check_if_permit_is_valid(folder["fields"]),
                            "processed":
                            folder["fields"]["dfunction"],
                            "date_from":
                            datetime.strptime(
                                folder["fields"]["date6"].split("T")[0],
                                "%Y-%m-%d").date(),
                        }
                        parent_key = folder["fields"]["parentKey"]

                        if "date7" in folder["fields"]:
                            ser_data["date_to"] = datetime.strptime(
                                folder["fields"]["date7"].split("T")[0],
                                "%Y-%m-%d").date()

                        if parent_key == settings.DECOS_JOIN_BANDB_ID:
                            ser_data[
                                "permit_type"] = DecosPermitSerializer.PERMIT_B_AND_B
                        elif parent_key == settings.DECOS_JOIN_VAKANTIEVERHUUR_ID:
                            ser_data[
                                "permit_type"] = DecosPermitSerializer.PERMIT_VV
                        else:
                            ser_data[
                                "permit_type"] = DecosPermitSerializer.PERMIT_UNKNOWN

                        permit_serializer = DecosPermitSerializer(
                            data=ser_data)
                        if permit_serializer.is_valid():
                            permits.append(permit_serializer.data)
                        else:
                            p_data = permit_serializer.data
                            print(p_data)
                            logger.error("permit_data is not valid")

                    else:
                        raw_data = folder["fields"]
                        ser_errors = serializer.errors
                        print(raw_data, ser_errors)
                        logger.error("serializer is not valid")
        return permits
    def get_decos_entry_by_bag_id(self, bag_id, dt):
        """ Get simple view of the important permits"""

        response = {}

        decos_join_conf_object = DecosJoinConf()
        decos_join_conf_object.set_default_expression(
            settings.DECOS_JOIN_DEFAULT_PERMIT_VALID_EXPRESSION)
        decos_join_conf_object.set_default_initial_data(
            settings.DECOS_JOIN_DEFAULT_PERMIT_VALID_INITIAL_DATA)
        decos_join_conf_object.set_default_field_mapping(
            settings.DECOS_JOIN_DEFAULT_FIELD_MAPPING)

        decos_join_conf_object.add_conf(
            settings.DECOS_JOIN_DEFAULT_PERMIT_VALID_CONF)
        decos_join_conf_object.add_conf(get_decos_join_constance_conf())

        permits = [{
            "permit_granted": "UNKNOWN",
            "permit_type": v.get(DecosJoinConf.PERMIT_TYPE),
        } for v in decos_join_conf_object]

        vakantieverhuur_meldigen = VakantieverhuurMeldingen(
            **{
                "melding_id": settings.DECOS_JOIN_VAKANTIEVERHUUR_MELDINGEN_ID,
                "afmelding_id":
                settings.DECOS_JOIN_VAKANTIEVERHUUR_AFMELDINGEN_ID,
            })

        response_decos_obj = self.get_decos_object_with_bag_id(bag_id)

        if response_decos_obj:
            response_decos_folder = self._get_decos_folder(response_decos_obj)
            if response_decos_folder:

                # vakantieverhuur meldingen
                vakantieverhuur_meldigen.add_raw_data(
                    response_decos_folder["content"])

                # permits
                for folder in response_decos_folder["content"]:

                    parent_key = folder.get("fields", {}).get("parentKey")
                    if parent_key in decos_join_conf_object.get_book_keys():
                        data = {}
                        conf = decos_join_conf_object.get_conf_by_book_key(
                            parent_key)
                        data.update({
                            "permit_granted":
                            decos_join_conf_object.expression_is_valid(
                                folder["fields"], conf, dt),
                            "permit_type":
                            conf.get(DecosJoinConf.PERMIT_TYPE),
                            "raw_data":
                            folder["fields"],
                            "details":
                            decos_join_conf_object.map_data_on_conf_keys(
                                folder["fields"], conf),
                        })
                        permit_serializer = DecosPermitSerializer(data=data)
                        if permit_serializer.is_valid():
                            for d in permits:
                                if d.get("permit_type") == conf.get(
                                        DecosJoinConf.PERMIT_TYPE):
                                    d.update(permit_serializer.data)
                    else:
                        logger.error(
                            "DECOS JOIN parent key not found in config")
                        logger.info("book key: %s" % parent_key)
                        logger.info("permit name: %s" %
                                    folder.get("fields", {}).get("text45"))
                        logger.info("permit result: %s" %
                                    folder.get("fields", {}).get("dfunction"))
                        logger.info("Config keys: %s" %
                                    decos_join_conf_object.get_book_keys())

        response.update({
            "permits":
            permits,
            "vakantieverhuur_meldingen":
            vakantieverhuur_meldigen.get_set_by_year(datetime.today().year,
                                                     datetime.today()),
        })

        return response