コード例 #1
0
    def get(self, request):
        code = 404
        payload = {}
        url = settings.MAPSERVER_URL
        organization_slug = request.GET.get('organization_slug', '')
        if organization_slug:
            url += organization_slug

        payload["service"] = "WFS"
        payload["request"] = "GetFeature"
        payload["version"] = "2.0.0"
        payload["outputFormat"] = "geojson"
        typename = request.GET.get('typename', '')
        if typename:
            payload["typename"] = typename

        try:
            response = requests.get(url, params=payload, timeout=60, verify=settings.IDGO_VERIFY_CERTIFICATE)
            data = response.json()
            code = response.status_code
            if code != 200 or not data.get('type', '') == 'FeatureCollection':
                data = "Les données ne sont pas au format geoJSON"
        except Exception as e:
            logger.exception("Les données sont inaccessibles %s", e)
            data = "Les données sont inaccessibles"
        finally:
            return Response(data=data, status=code)
コード例 #2
0
 def filter_queryset(self, queryset):
     """
     Surchargeant ListModelMixin
     """
     geom = self.request.query_params.get('geom')
     status = self.request.query_params.get('status')
     feature_type_slug = self.request.query_params.get('feature_type_slug')
     title = self.request.query_params.get('title')
     feature_id = self.request.query_params.get('feature_id')
     exclude_feature_id = self.request.query_params.get(
         'exclude_feature_id')
     if geom:
         try:
             queryset = queryset.filter(
                 geom__intersects=Polygon.from_bbox(geom.split(',')))
         except (GEOSException, ValueError):
             logger.exception("Api FeatureSearch geom error")
     if status:
         queryset = queryset.filter(status__icontains=status)
     if feature_type_slug:
         queryset = queryset.filter(
             feature_type__slug__icontains=feature_type_slug)
     if title:
         queryset = queryset.filter(title__icontains=title)
     if feature_id:
         queryset = queryset.filter(feature_id=feature_id)
     if exclude_feature_id:
         queryset = queryset.exclude(feature_id=exclude_feature_id)
     return queryset
コード例 #3
0
 def get(self, kanban_id):
     """ Return all issues info for given kanban board """
     kanban_finder = KanbanFinder()
     logger.info(f"Fetching kanban directory with id {kanban_id}")
     kanban_directory, kanban_check = kanban_finder.find_kanban_dir_with_id(
         kanban_id=kanban_id, kanbans_directory=config.kanbans_directory)
     logger.info(f"Kanban directory {kanban_directory}")
     if kanban_check:
         issue_finder = IssueFinder()
         try:
             logger.info(
                 f"Fetching all issues for kanban with id {kanban_id}")
             all_issues_info_list = issue_finder.return_all_issues_info_for_kanban(
                 kanbans_directory=config.kanbans_directory,
                 kanban_id=kanban_id)
             response = jsonify(all_issues_info_list)
             response.headers.add("Access-Control-Allow-Origin", "*")
             return response
         except Exception as e:
             logger.error("Unable to fetch issues!")
             logger.exception(e)
             return {"response": "Unable to fetch issues"}, 500
     else:
         logger.warning(
             f"Unable to fetch issues! Kanban with id {kanban_id} not found"
         )
         return {"response": "Kanban id not found"}, 400
コード例 #4
0
 def put(self, kanban_id, issue_id):
     request.get_json(force=True)
     if api.payload is None or api.payload == {}:
         return {"response": "Unable to decode payload"}, 400
     if (api.payload["stage"].replace(" ", "") == ""
             or api.payload["stage"] == "string"):
         return {
             "response": "Stage cannot be null or whitespaces only"
         }, 400
     elif api.payload["stage"] not in [stage.value for stage in Stages]:
         return {
             "response":
             "Stage cannot be anything other than todo, done or doing"
         }, 400
     issue_stage_hand = IssueStageHandler()
     logger.info(f"Changing issue with id {issue_id} current stage")
     try:
         issue_stage_hand.change_stage(
             kanbans_directory=config.kanbans_directory,
             kanban_id=kanban_id,
             issue_id=issue_id,
             stage_to_assign=api.payload["stage"],
         )
         return {}, 204
     except AttributeError:
         logger.error(
             f"Issue is not set to any stage! Check issue config xml")
         return {"response": "Issue is not set to any stage"}, 500
     except FileNotFoundError:
         logger.warning("Issue couldn't be found")
         return {"response": "Issue id not found"}, 400
     except Exception as e:
         logger.error("Couldn't update issue stage!")
         logger.exception(e)
         return {"response": "Unable to update issue stage"}, 500
コード例 #5
0
 def delete(self, kanban_id, issue_id):
     """ Deletes issue for given kanban """
     kanban_finder = KanbanFinder()
     logger.info(f"Fetching kanban directory with id {kanban_id}")
     kanban_directory, kanban_check = kanban_finder.find_kanban_dir_with_id(
         kanban_id=kanban_id, kanbans_directory=config.kanbans_directory)
     logger.info(f"Kanban directory {kanban_directory}")
     if kanban_check:
         try:
             issue_deleter = IssueDeleter()
             issue_deleter.delete_issue_for_kanban(
                 kanbans_directory=config.kanbans_directory,
                 kanban_id=kanban_id,
                 issue_id=issue_id,
             )
         except FileNotFoundError as fe:
             logger.warning(
                 f"Unable to update issues! Issue with id {issue_id} not found"
             )
             logger.exception(fe)
             return {"response": "Issue id not found"}, 400
         except Exception as e:
             logger.error("Couldn't update issue")
             logger.exception(e)
             return {"response": "Couldn't update issue"}, 500
         return 204
     else:
         logger.warning(
             f"Unable to fetch issues! Kanban with id {kanban_id} not found"
         )
         return {"response": "Kanban id not found"}, 400
コード例 #6
0
 def get_project_url(self, obj):
     url = ''
     if obj.project_slug:
         try:
             project = Project.objects.get(slug=obj.project_slug)
             url = project.get_absolute_url()
         except Exception:
             logger.exception('No related project found')
     return url
コード例 #7
0
 def get_related_feature(self, obj):
     res = {}
     if obj.feature_id:
         try:
             feature = Feature.objects.get(feature_id=obj.feature_id)
             res = {
                 'feature_id': str(feature.feature_id),
                 'title': str(feature.title),
                 'feature_url': feature.get_view_url()
             }
         except Exception:
             logger.exception('No related feature found')
     return res
コード例 #8
0
 def get_related_comment(self, obj):
     res = {}
     if obj.object_type == 'comment':
         try:
             comment = Comment.objects.get(id=obj.comment_id)
             res = {
                 'comment': comment.comment,
                 'attachments': [
                     {'url': att.attachment_file.url, 'title': att.title} for att in comment.attachment_set.all()
                 ]
             }
         except Exception:
             logger.exception('No related comment found')
     return res
コード例 #9
0
 def get_feature_to(self, obj):
     res = {}
     if obj.feature_to:
         try:
             feature = obj.feature_to
             res = {
                 'feature_id': str(feature.feature_id),
                 'title': str(feature.title),
                 'feature_url': feature.get_view_url(),
                 'created_on':
                 feature.created_on.strftime("%d/%m/%Y %H:%M"),
                 'creator': feature.display_creator,
             }
         except Exception:
             logger.exception('No related feature found')
     return res
コード例 #10
0
    def get(self, request):
        code = 404
        url = settings.IDGO_URL
        user = request.query_params.get('user')
        if user:
            url += user

        try:
            response = requests.get(url, timeout=60, auth=(settings.IDGO_LOGIN, settings.IDGO_PASSWORD), verify=settings.IDGO_VERIFY_CERTIFICATE)
            data = response.json()
            code = response.status_code
        except Exception as e:
            logger.exception("Les données sont inaccessibles %s", e)
            data = "Les données sont inaccessibles"
        finally:
            return Response(data=data, status=code)
コード例 #11
0
    def post(self, kanban_id):
        request.get_json(force=True)
        if api.payload is None or api.payload == {}:
            return {"response": "Unable to decode payload"}, 400

        try:
            if (api.payload["name"].replace(" ", "") == ""
                    or api.payload["creator"].replace(" ", "") == ""):
                return {
                    "response":
                    "Name/creator cannot be null or whitespaces only"
                }, 400
        except KeyError as ke:
            logger.exception(ke)
            return {"response": "Name/description is missing"}, 400

        logger.info("Creating issue xml config")
        issue_creator = IssueCreator()

        try:
            logger.info("Creating issue directory if needed")
            issue_creator.create_issue_folder(
                kanbans_directory=config.kanbans_directory,
                kanban_id=kanban_id)
        except FileNotFoundError as fe:
            logger.error(f"Unable to create issue directory! "
                         f"Kanban with id {kanban_id} doesn't exist")
            logger.exception(fe)
            return {"response": "Kanban id not found"}, 400
        except Exception as e:
            logger.error("Unable to create issues directory!")
            logger.exception(e)
            return {"response": "Unable to create issues directory!"}, 500

        try:
            logger.info("Creating new issue")
            issue_creator.create_new_issue_config(
                kanbans_directory=config.kanbans_directory,
                kanban_id=kanban_id,
                issue_description=api.payload["description"],
                issue_name=api.payload["name"],
                creator=api.payload["creator"],
            )
            return {
                "response":
                f"Issue with name {api.payload['name']} for kanban with id {kanban_id} created!"
            }, 201
        except FileExistsError as fe:
            logger.warning("Issue already exists!")
            return {
                "response": "Unable to create new issue!",
                "exception": str(fe),
            }, 500
        except Exception as e:
            logger.error("Unable to create issue!")
            logger.exception(e)
            return {"response": "Unable to create new issue!"}, 500
コード例 #12
0
    def get(self):
        """Returns all kanban boards with info"""
        kanban_finder = KanbanFinder()
        logger.info("Fetching all kanbans info")
        try:
            all_kanbans_info_list = kanban_finder.return_all_kanabans_info(
                kanbans_directory=config.kanbans_directory)
            print(all_kanbans_info_list)
            response = jsonify(all_kanbans_info_list)
            print(response)
            response.headers.add("Access-Control-Allow-Origin", "*")
        except Exception as e:
            logger.error("Coulnd't fetch kanbans")
            logger.exception(e)
            return {"response": f"Kanbans couldn't be fetched! {e}"}, 500

        return response
コード例 #13
0
 def delete(self, kanban_id):
     """ Delete kanban board with given id """
     logger.info(f"Deleting kanban with id {kanban_id}")
     try:
         kanban_deleter = KanbanDeleter()
         kanban_deleter.delete_kanban(
             kanbans_directory=config.kanbans_directory,
             kanban_id=kanban_id)
         return {"response": "Kanban deleted"}, 204
     except FileNotFoundError:
         logger.warning(f"Kanban with id {kanban_id} not found")
         return {"response": "Kanban id not found"}, 400
     except Exception as e:
         logger.error("Unable to delte kanban")
         logger.exception(e)
         return {
             "response": "Unable to delte kanban",
             "exception": str(e)
         }, 500
コード例 #14
0
 def get(self, kanban_id, issue_id):
     kanban_finder = KanbanFinder()
     logger.info(f"Fetching kanban directory with id {kanban_id}")
     kanban_directory, kanban_check = kanban_finder.find_kanban_dir_with_id(
         kanban_id=kanban_id, kanbans_directory=config.kanbans_directory)
     logger.info(f"Kanban directory {kanban_directory}")
     if kanban_check:
         issue_finder = IssueFinder()
         issues_directory = issue_finder.return_issues_directory_for_kanban(
             kanbans_directory=config.kanbans_directory,
             kanban_id=kanban_id)
         issue_check = issue_finder.check_if_issue_extists(
             issues_directory=issues_directory, issue_id=issue_id)
         if issue_check:
             try:
                 logger.info(
                     f"Fetching issues with id {issue_id} for kanban with id {kanban_id}"
                 )
                 issue_info_list = issue_finder.return_issue_info_for_kanban(
                     kanbans_directory=config.kanbans_directory,
                     kanban_id=kanban_id,
                     issue_id=issue_id,
                 )
                 response = jsonify(issue_info_list)
                 response.headers.add("Access-Control-Allow-Origin", "*")
                 return response
             except Exception as e:
                 logger.error("Unable to fetch issues!")
                 logger.exception(e)
                 return {"response": "Unable to fetch issues"}, 500
         else:
             logger.warning(
                 f"Unable to fetch issues! Issue with id {issue_id} not found"
             )
             return {"response": "Issue id not found"}, 400
     else:
         logger.warning(
             f"Unable to fetch issues! Kanban with id {kanban_id} not found"
         )
         return {"response": "Kanban id not found"}, 400
コード例 #15
0
    def put(self, kanban_id):
        """Updates kanban board with given id"""
        kanban_finder = KanbanFinder()
        logger.info(f"Updating kanban with id {kanban_id}")
        kanban_directory, kanban_found = kanban_finder.find_kanban_dir_with_id(
            kanban_id=kanban_id, kanbans_directory=config.kanbans_directory)
        response = dict()
        if kanban_found:
            config_file_dir = os.path.join(kanban_directory, "config.xml")
            logger.info(config_file_dir)

            request.get_json(force=True)
            if api.payload is None or api.payload == {}:
                return {"response": "Unable to decode payload"}, 400

            try:
                if api.payload["name"].replace(" ", "") == "":
                    return {
                        "response": "Name cannot be null or whitespaces only"
                    }, 400
                elif api.payload["name"] != "string":
                    update_xml_attribute(config_file_dir, "name",
                                         api.payload["name"])
                    response[
                        "response_name"] = f"Updated with {api.payload['name']}"
                if api.payload["description"] != "string":
                    update_xml_attribute(config_file_dir, "description",
                                         api.payload["description"])
                    response[
                        "response_desc"] = f"Updated with {api.payload['description']}"
            except KeyError as ke:
                logger.error("Key not matching model used!")
                logger.exception(ke)
                return {"response": "Wrong key! Use given model"}, 400

            return response, 204

        else:
            logger.warning(f"Kanban with id {kanban_id} not found!")
            return {"response": "Kanban id not found"}, 404
コード例 #16
0
    def post(self):
        """Create new kanban"""
        kanban_creator = KanbanCreator()
        logger.info("Creating new kanban")
        request.get_json(force=True)
        print(api.payload)
        if api.payload is None or api.payload == {}:
            return {"response": "Unable to decode payload"}, 400

        try:
            desc = api.payload["description"]
            name = api.payload["name"]
        except KeyError as ke:
            logger.error("Name or description not present in body!")
            logger.exception(ke)
            return {
                "response": "Name or description not present in body!"
            }, 400

        if api.payload["name"].replace(" ", "") == "":
            return {"response": "Name cannot be null or whitespaces only"}, 400
        try:
            new_kanban_dir, new_kanban_id = kanban_creator.create_new_kanban_folder(
                kanbans_directory=config.kanbans_directory)
        except FileExistsError:
            logger.error("Kanban already exists!")
            return {"response": "Unable to create! Kanban already exists"}, 500
        except Exception as e:
            logger.error("Couldn't create kanban!")
            logger.exception(e)
            return {
                "response": "Unable to create",
                "exception": str(e),
            }, 500
        try:
            logger.info("Creating config xml for new kanban")
            config_tree = kanban_creator.create_xml_tree_for_kanban_config(
                kanban_name=api.payload["name"],
                kanban_id=new_kanban_id,
                description=api.payload["description"],
            )
            kanban_creator.create_new_kanban_config(
                kanbans_directory=config.kanbans_directory,
                kanban_id=new_kanban_id,
                new_kanban_directory=new_kanban_dir,
                config_xml_tree=config_tree,
            )
        except Exception as e:
            logger.error("Couldn't create new kanban config! Deleting kanban")
            logger.exception(e)
            os.rmdir(new_kanban_dir)
            return {
                "response":
                "Failed while creating config.xml file, deleting kanban.",
                "exception": str(e),
            }, 500

        return {
            "response": f"New kanban board with id {new_kanban_id} created"
        }, 201
コード例 #17
0
 def get(self, kanban_id, issue_id):
     """ Check on which stage issue is """
     issue_stage_hand = IssueStageHandler()
     logger.info(f"Checking issue with id {issue_id} current stage")
     try:
         stage = issue_stage_hand.check_stage(
             kanbans_directory=config.kanbans_directory,
             kanban_id=kanban_id,
             issue_id=issue_id,
         )
         response = jsonify(stage)
         response.headers.add("Access-Control-Allow-Origin", "*")
         return response
     except AttributeError:
         logger.error(
             f"Issue is not set to any stage! Check issue config xml")
         return {"response": "Issue is not set to any stage"}, 500
     except FileNotFoundError:
         logger.warning("Issue couldn't be found")
         return {"response": "Issue id not found"}, 400
     except Exception as e:
         logger.error("Couldn't check issue stage!")
         logger.exception(e)
         return {"response": "Couldn't check issue stage"}, 500
コード例 #18
0
    def put(self, kanban_id, issue_id):
        """ Updates specific issue with given attributes """
        kanban_finder = KanbanFinder()
        logger.info(f"Fetching kanban directory with id {kanban_id}")
        kanban_directory, kanban_check = kanban_finder.find_kanban_dir_with_id(
            kanban_id=kanban_id, kanbans_directory=config.kanbans_directory)
        logger.info(f"Kanban directory {kanban_directory}")
        if kanban_check:
            request.get_json(force=True)
            if api.payload is None or api.payload == {}:
                return {"response": "Unable to decode payload"}, 400

            issue_finder = IssueFinder()
            issues_directory = issue_finder.return_issues_directory_for_kanban(
                kanbans_directory=config.kanbans_directory,
                kanban_id=kanban_id)
            issue_check = issue_finder.check_if_issue_extists(
                issues_directory=issues_directory, issue_id=issue_id)
            if issue_check:
                issue_updater = IssueUpdater()
                try:
                    if api.payload["description"] != "string":
                        issue_updater.update_issue(
                            issues_directory,
                            issue_id,
                            "description",
                            api.payload["description"],
                        )
                    if api.payload["creator"].replace(" ", "") == "":
                        return {
                            "response": "Issue creator cannot be null!"
                        }, 400
                    elif api.payload["creator"] != "string":
                        issue_updater.update_issue(
                            issues_directory,
                            issue_id,
                            "creator",
                            api.payload["creator"],
                        )
                    if api.payload["name"].replace(" ", "") == "":
                        return {"response": "Issue name cannot be null!"}, 400
                    elif api.payload["name"] != "string":
                        issue_updater.update_issue(issues_directory, issue_id,
                                                   "name", api.payload["name"])
                except KeyError as ke:
                    logger.error("Key not matching model used!")
                    logger.exception(ke)
                    return {"response": "Wrong key! Use given model"}, 500
                except Exception as e:
                    logger.error("Couldn't update issue")
                    logger.exception(e)
                    return {"response": "Couldn't update issue"}, 500

                return {}, 204
            else:
                logger.warning(
                    f"Unable to update issues! Issue with id {issue_id} not found"
                )
                return {"response": "Issue id not found"}, 400
        else:
            logger.warning(
                f"Unable to fetch issues! Kanban with id {kanban_id} not found"
            )
            return {"response": "Kanban id not found"}, 400