Skip to content

Commit

Permalink
Allowing project_slug to be passed in (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
delaine-eb authored Jun 11, 2019
1 parent 2198aad commit 039db60
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/shuttle/transifex.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ def create_or_update_resource(self, slug, locale, name, content,

return resource

def resource_statistics(self, slug, locale):
def resource_statistics(self, slug, locale, project_slug=None):

try:
stats = statistics.Statistics.get(
project_slug=self.get_project_slug(locale),
project_slug=project_slug or self.get_project_slug(locale),
resource_slug=slug,
)
except NotFoundError:
Expand All @@ -141,12 +141,12 @@ def delete_resource(self, slug, locale):
if resource:
resource.delete()

def translation_exists(self, slug, lang):
def translation_exists(self, slug, lang, project_slug=None):
"""Return True if the translation exists for this slug."""

try:
return translations.Translation.get(
project_slug=self.get_project_slug(lang),
project_slug=project_slug or self.get_project_slug(lang),
slug=slug,
lang=lang,
)
Expand All @@ -156,19 +156,19 @@ def translation_exists(self, slug, lang):

return False

def list_resources(self, lang):
def list_resources(self, lang, project_slug=None):
"""Return a sequence of resources for a given lang.
Each Resource is a dict containing the slug, name, i18n_type,
source_language_code and the category.
"""

project_slug = project_slug or self.get_project_slug(lang)
return registry.registry.http_handler.get(
'/api/2/project/%s/resources/' % (
self.get_project_slug(lang),)
project_slug,)
)

def resources(self, lang, slug):
def resources(self, lang, slug, project_slug=None):
"""Generate a list of Resources in the Project.
Yields dicts from the Tx API, with keys including the slug,
Expand All @@ -177,7 +177,7 @@ def resources(self, lang, slug):
"""

resource = resources.Resource.get(
project_slug=self.get_project_slug(lang),
project_slug=project_slug or self.get_project_slug(lang),
slug=slug,
)

Expand All @@ -198,6 +198,3 @@ def resource_exists(self, slug, locale, project_slug=None):
pass

return None

## def completed_translations(self, slug):
## """Generate (lang, translation) tuples for the given resource slug."""

0 comments on commit 039db60

Please sign in to comment.