sort service docs items
This commit is contained in:
		
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@ -28,20 +28,27 @@ def _normalize_type(service_type):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class Services(object):
 | 
					class Services(object):
 | 
				
			||||||
    """Encapsulation of the OTC Services data
 | 
					    """Encapsulation of the OTC Services data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(self):
 | 
					    def __init__(self):
 | 
				
			||||||
        self._service_data = BUILTIN_DATA
 | 
					        self._service_data = BUILTIN_DATA
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _sort_data(self):
 | 
					    def _sort_data(self):
 | 
				
			||||||
 | 
					        # Sort every doc item by key
 | 
				
			||||||
 | 
					        sorted_docs = []
 | 
				
			||||||
 | 
					        for doc in self._service_data['documents']:
 | 
				
			||||||
 | 
					            sorted_docs.append(dict(sorted(
 | 
				
			||||||
 | 
					                doc.items(),
 | 
				
			||||||
 | 
					                key=lambda kv: kv[0]
 | 
				
			||||||
 | 
					            )))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # sort docs list by <service_type>_<title>
 | 
				
			||||||
        self._service_data['documents'] = sorted(
 | 
					        self._service_data['documents'] = sorted(
 | 
				
			||||||
            self._service_data['documents'],
 | 
					            sorted_docs,
 | 
				
			||||||
            key=lambda x: f"{x.get('service_type')}{x.get('title')}"
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
        self._service_data['documents'] = sorted(
 | 
					 | 
				
			||||||
            self._service_data['documents'],
 | 
					 | 
				
			||||||
            key=lambda x: f"{x.get('service_type')}{x.get('title')}"
 | 
					            key=lambda x: f"{x.get('service_type')}{x.get('title')}"
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					        # sort services by <service_type>_<service_title>
 | 
				
			||||||
        self._service_data['services'] = sorted(
 | 
					        self._service_data['services'] = sorted(
 | 
				
			||||||
            self._service_data['services'],
 | 
					            self._service_data['services'],
 | 
				
			||||||
            key=lambda x: f"{x.get('service_type')}{x.get('service_title')}"
 | 
					            key=lambda x: f"{x.get('service_type')}{x.get('service_title')}"
 | 
				
			||||||
@ -74,6 +81,7 @@ class Services(object):
 | 
				
			|||||||
    @property
 | 
					    @property
 | 
				
			||||||
    def service_categories(self):
 | 
					    def service_categories(self):
 | 
				
			||||||
        """List services categories
 | 
					        """List services categories
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        res = []
 | 
					        res = []
 | 
				
			||||||
        for cat in self._service_data["service_categories"]:
 | 
					        for cat in self._service_data["service_categories"]:
 | 
				
			||||||
@ -82,6 +90,7 @@ class Services(object):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def services_by_category(self, category):
 | 
					    def services_by_category(self, category):
 | 
				
			||||||
        """List services matching category
 | 
					        """List services matching category
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        res = []
 | 
					        res = []
 | 
				
			||||||
        for srv in self.all_services:
 | 
					        for srv in self.all_services:
 | 
				
			||||||
@ -154,6 +163,7 @@ class Services(object):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def all_docs_full(self, environment):
 | 
					    def all_docs_full(self, environment):
 | 
				
			||||||
        """Return list or documents with full service data
 | 
					        """Return list or documents with full service data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        services = self.service_dict
 | 
					        services = self.service_dict
 | 
				
			||||||
        for doc in self.all_docs:
 | 
					        for doc in self.all_docs:
 | 
				
			||||||
@ -177,7 +187,6 @@ class Services(object):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        doc_struct = dict()
 | 
					        doc_struct = dict()
 | 
				
			||||||
        services = self.service_dict
 | 
					 | 
				
			||||||
        for srv in self.all_services:
 | 
					        for srv in self.all_services:
 | 
				
			||||||
            doc_struct.setdefault(srv["service_category"], [])
 | 
					            doc_struct.setdefault(srv["service_category"], [])
 | 
				
			||||||
            srv_res = dict(
 | 
					            srv_res = dict(
 | 
				
			||||||
@ -187,7 +196,10 @@ class Services(object):
 | 
				
			|||||||
            )
 | 
					            )
 | 
				
			||||||
            if "repositories" in srv and environment:
 | 
					            if "repositories" in srv and environment:
 | 
				
			||||||
                for repo in srv["repositories"]:
 | 
					                for repo in srv["repositories"]:
 | 
				
			||||||
                    if "environment" in repo and repo["environment"] == environment:
 | 
					                    if (
 | 
				
			||||||
 | 
					                        "environment" in repo
 | 
				
			||||||
 | 
					                        and repo["environment"] == environment
 | 
				
			||||||
 | 
					                    ):
 | 
				
			||||||
                        srv_res["repository"] = repo["repo"]
 | 
					                        srv_res["repository"] = repo["repo"]
 | 
				
			||||||
            for doc in self.all_docs:
 | 
					            for doc in self.all_docs:
 | 
				
			||||||
                if (
 | 
					                if (
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user