Commit 3a8239cb authored by Michal Čihař's avatar Michal Čihař

Add read only views for components

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 335fc235
......@@ -20,12 +20,22 @@
from rest_framework import serializers
from weblate.trans.models import Project
from weblate.trans.models import Project, SubProject
class ProjectSerializer(serializers.ModelSerializer):
class Meta(object):
model = Project
fields = (
'id', 'name', 'slug', 'web', 'source_language'
'id', 'name', 'slug', 'web', 'source_language',
)
class ComponentSerializer(serializers.ModelSerializer):
class Meta(object):
model = SubProject
fields = (
'id', 'name', 'slug', 'project', 'vcs', 'repo', 'git_export',
'branch', 'filemask', 'template', 'file_format', 'license',
'license_url',
)
......@@ -23,11 +23,12 @@ from __future__ import unicode_literals
from django.conf.urls import url, include
from rest_framework import routers, serializers, viewsets
from weblate.api.views import ProjectViewSet
from weblate.api.views import ProjectViewSet, ComponentViewSet
# Routers provide an easy way of automatically determining the URL conf.
router = routers.DefaultRouter()
router.register(r'projects', ProjectViewSet)
router.register(r'components', ComponentViewSet)
# Wire up our API using automatic URL routing.
......
......@@ -20,16 +20,30 @@
from rest_framework import viewsets
from weblate.api.serializers import ProjectSerializer
from weblate.trans.models import Project
from weblate.api.serializers import ProjectSerializer, ComponentSerializer
from weblate.trans.models import Project, SubProject
class ProjectViewSet(viewsets.ReadOnlyModelViewSet):
"""
ViewSet for viewing projects.
"""Translation projects API.
"""
queryset = Project.objects.none()
serializer_class = ProjectSerializer
def get_queryset(self):
return Project.objects.all_acl(self.request.user)
class ComponentViewSet(viewsets.ReadOnlyModelViewSet):
"""Translation components API.
"""
queryset = SubProject.objects.none()
serializer_class = ComponentSerializer
def get_queryset(self):
acl_projects, filtered = Project.objects.get_acl_status(
self.request.user
)
if filtered:
return SubProject.objects.filter(project__in=acl_projects)
return SubProject.objects.all()
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