Commit 130442fb authored by Michal Čihař's avatar Michal Čihař

Add link URLs to API

This allows to browse most of the API using web browser.
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent f3e5fa14
...@@ -248,6 +248,8 @@ Projects ...@@ -248,6 +248,8 @@ Projects
:>json string slug: project slug :>json string slug: project slug
:>json object source_language: source language object, see :http:get:`/api/languages/(string:language)/` :>json object source_language: source language object, see :http:get:`/api/languages/(string:language)/`
:>json string web: project website :>json string web: project website
:>json string components_list_url: URL to components list, see :http:get:`/api/projects/(string:project)/components/`
:>json string repository_url: URL to repository status, see :http:get:`/api/projects/(string:project)/repository/`
.. seealso:: .. seealso::
...@@ -398,6 +400,9 @@ Components ...@@ -398,6 +400,9 @@ Components
:>json string template: base file for monolingual translations :>json string template: base file for monolingual translations
:>json string new_base: base file for adding new translations :>json string new_base: base file for adding new translations
:>json string vcs: version control system :>json string vcs: version control system
:>json string repository_url: URL to repository status, see :http:get:`/api/components/(string:project)/(string:component)/repository/`
:>json string translations_url: URL to translations list, see :http:get:`/api/components/(string:project)/(string:component)/translations/`
:>json string lock_url: URL to lock statuc, see :http:get:`/api/components/(string:project)/(string:component)/lock/`
.. seealso:: .. seealso::
...@@ -598,6 +603,8 @@ Translations ...@@ -598,6 +603,8 @@ Translations
:>json int translated: number of translated units :>json int translated: number of translated units
:>json float translated_percent: percentage of translated units :>json float translated_percent: percentage of translated units
:>json int translated_words: number of translated words :>json int translated_words: number of translated words
:>json string repository_url: URL to repository status, see :http:get:`/api/translations/(string:project)/(string:component)/(string:language)/repository/`
:>json string file_url: URL to file object, see :http:get:`/api/translations/(string:project)/(string:component)/(string:language)/file/`
.. seealso:: .. seealso::
......
...@@ -79,23 +79,44 @@ class LanguageSerializer(serializers.ModelSerializer): ...@@ -79,23 +79,44 @@ class LanguageSerializer(serializers.ModelSerializer):
class ProjectSerializer(serializers.ModelSerializer): class ProjectSerializer(serializers.ModelSerializer):
web_url = serializers.CharField(source='get_absolute_url', read_only=True) web_url = serializers.CharField(source='get_absolute_url', read_only=True)
source_language = LanguageSerializer(read_only=True) source_language = LanguageSerializer(read_only=True)
components_list_url = serializers.HyperlinkedIdentityField(
view_name='api:project-components',
lookup_field='slug',
)
repository_url = serializers.HyperlinkedIdentityField(
view_name='api:project-repository',
lookup_field='slug',
)
class Meta(object): class Meta(object):
model = Project model = Project
fields = ( fields = (
'name', 'slug', 'web', 'source_language', 'web_url', 'url', 'name', 'slug', 'web', 'source_language', 'web_url', 'url',
'components_list_url', 'repository_url',
) )
extra_kwargs = { extra_kwargs = {
'url': { 'url': {
'view_name': 'api:project-detail', 'view_name': 'api:project-detail',
'lookup_field': 'slug' 'lookup_field': 'slug'
} },
} }
class ComponentSerializer(RemovableSerializer): class ComponentSerializer(RemovableSerializer):
web_url = serializers.CharField(source='get_absolute_url', read_only=True) web_url = serializers.CharField(source='get_absolute_url', read_only=True)
project = ProjectSerializer(read_only=True) project = ProjectSerializer(read_only=True)
repository_url = MultiFieldHyperlinkedIdentityField(
view_name='api:component-repository',
lookup_field=('project__slug', 'slug'),
)
translations_url = MultiFieldHyperlinkedIdentityField(
view_name='api:component-translations',
lookup_field=('project__slug', 'slug'),
)
lock_url = MultiFieldHyperlinkedIdentityField(
view_name='api:component-lock',
lookup_field=('project__slug', 'slug'),
)
serializer_url_field = MultiFieldHyperlinkedIdentityField serializer_url_field = MultiFieldHyperlinkedIdentityField
...@@ -105,6 +126,8 @@ class ComponentSerializer(RemovableSerializer): ...@@ -105,6 +126,8 @@ class ComponentSerializer(RemovableSerializer):
'name', 'slug', 'project', 'vcs', 'repo', 'git_export', 'name', 'slug', 'project', 'vcs', 'repo', 'git_export',
'branch', 'filemask', 'template', 'new_base', 'file_format', 'branch', 'filemask', 'template', 'new_base', 'file_format',
'license', 'license_url', 'web_url', 'url', 'license', 'license_url', 'web_url', 'url',
'repository_url', 'translations_url',
'lock_url',
) )
extra_kwargs = { extra_kwargs = {
'url': { 'url': {
...@@ -145,6 +168,22 @@ class TranslationSerializer(RemovableSerializer): ...@@ -145,6 +168,22 @@ class TranslationSerializer(RemovableSerializer):
last_author = serializers.CharField( last_author = serializers.CharField(
source='get_last_author', read_only=True, source='get_last_author', read_only=True,
) )
repository_url = MultiFieldHyperlinkedIdentityField(
view_name='api:translation-repository',
lookup_field=(
'subproject__project__slug',
'subproject__slug',
'language__code',
),
)
file_url = MultiFieldHyperlinkedIdentityField(
view_name='api:translation-file',
lookup_field=(
'subproject__project__slug',
'subproject__slug',
'language__code',
),
)
serializer_url_field = MultiFieldHyperlinkedIdentityField serializer_url_field = MultiFieldHyperlinkedIdentityField
...@@ -162,6 +201,7 @@ class TranslationSerializer(RemovableSerializer): ...@@ -162,6 +201,7 @@ class TranslationSerializer(RemovableSerializer):
'fuzzy', 'fuzzy_percent', 'fuzzy', 'fuzzy_percent',
'failing_checks_percent', 'failing_checks_percent',
'last_change', 'last_author', 'last_change', 'last_author',
'repository_url', 'file_url',
) )
extra_kwargs = { extra_kwargs = {
'url': { 'url': {
......
...@@ -136,6 +136,7 @@ class WeblateViewSet(viewsets.ReadOnlyModelViewSet): ...@@ -136,6 +136,7 @@ class WeblateViewSet(viewsets.ReadOnlyModelViewSet):
class ProjectViewSet(WeblateViewSet): class ProjectViewSet(WeblateViewSet):
"""Translation projects API. """Translation projects API.
<a href="https://docs.weblate.org/en/latest/api.html#projects">doc</a>
""" """
queryset = Project.objects.none() queryset = Project.objects.none()
serializer_class = ProjectSerializer serializer_class = ProjectSerializer
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment