From 15a8c820ea08ad8ff6fcb53fdd14ce6df2f2b4a1 Mon Sep 17 00:00:00 2001 From: "Leonides T. Saguisag, Jr" Date: Fri, 24 Jan 2020 23:51:21 -0800 Subject: [PATCH] Break out the 'projects' property into 'all_projects', 'active_projects' and 'closed_projects'. --- memoq/server.py | 46 +++++++++++++++++++++++++++++++++++++--------- setup.py | 2 +- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/memoq/server.py b/memoq/server.py index 9f164f6..d24c85f 100644 --- a/memoq/server.py +++ b/memoq/server.py @@ -4,6 +4,7 @@ This code is released under the MIT License. """ from collections.abc import Mapping +from datetime import datetime, timezone from .webservice import MemoQLightResourceService, MemoQLiveDocsService, MemoQTBService, MemoQTMService, \ MemoQSecurityService, MemoQServerProjectService @@ -73,6 +74,7 @@ def __init__(self, base_url: str): :param base_url: Base URL for the memoQ server. For example, 'http://localhost:8080' """ self.base_url = base_url + self._all_projects = None self._api_endpoints = {} self._light_resources = None @@ -146,6 +148,30 @@ def _tm_service(self): self._api_endpoints[tm_service_key] = MemoQTMService(self.base_url) return self._api_endpoints[tm_service_key] + @property + def active_projects(self) -> list: + """ + Method for retrieving the list of active projects on the memoQ server. + + :returns: A list of active projects on the memoQ server. + """ + return [proj + for proj in self.all_projects + if proj.TimeClosed.replace(tzinfo=timezone.utc) > datetime.now(timezone.utc)] + + @property + def all_projects(self) -> list: + """ + Method for retrieving the list of all projects (both active and closed) on the memoQ server. + + :returns: A list of all projects (both active and closed) on the memoQ server. + """ + # https://docs.memoq.com/current/api-docs/wsapi/api/serverprojectservice/MemoQServices.ServerProjectListFilter.html#MemoQServices_SP_ServerProjectListFilter_TimeClosed + if self._all_projects is None: + self._all_projects = self._server_project_service.ListProjects( + {'TimeClosed': datetime(year=1900, month=1, day=1)}) + return self._all_projects + @property def api_version(self) -> str: """ @@ -155,6 +181,17 @@ def api_version(self) -> str: """ return self._server_project_service.GetApiVersion() + @property + def closed_projects(self) -> list: + """ + Method for retrieving the list of closed projects on the memoQ server. + + :returns: A list of closed projects on the memoQ server. + """ + return [proj + for proj in self.all_projects + if proj.TimeClosed.replace(tzinfo=timezone.utc) < datetime.now(timezone.utc)] + @property def corpora(self) -> list: """ @@ -184,15 +221,6 @@ def light_resources(self) -> LightResources: self._light_resources = LightResources(self._light_resource_service) return self._light_resources - @property - def projects(self) -> list: - """ - Method for retrieving the list of projects on the memoQ server. - - :returns: A list of projects on the memoQ server. - """ - return self._server_project_service.ListProjects() - @property def tbs(self) -> list: """ diff --git a/setup.py b/setup.py index 7559ab3..15edaff 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ long_description = f.read() setup(name='pymemoq', - version='0.2.dev3', + version='0.2.dev6', description='Python module to facilitate accessing the memoQ API.', long_description=long_description, long_description_content_type='text/x-rst',