mirror of
https://gitlab.com/bramw/baserow.git
synced 2025-04-04 13:15:24 +00:00
made some final text and doc changes
This commit is contained in:
parent
274576fb4f
commit
95df5e7b75
7 changed files with 31 additions and 8 deletions
backend/src/baserow
api/v0
core
|
@ -43,7 +43,8 @@ class ApplicationsView(APIView):
|
|||
@transaction.atomic
|
||||
@validate_body(ApplicationCreateSerializer)
|
||||
def post(self, request, data, group_id):
|
||||
"""Creates a new group for a user."""
|
||||
"""Creates a new application for a user."""
|
||||
|
||||
group_user = self.load_group(request, group_id)
|
||||
application = self.core_handler.create_application(
|
||||
request.user, group_user.group, data['type'], name=data['name'])
|
||||
|
@ -61,7 +62,8 @@ class ApplicationView(APIView):
|
|||
UserNotIngroupError: ERROR_USER_NOT_IN_GROUP
|
||||
})
|
||||
def patch(self, request, data, application_id):
|
||||
"""Updates the application if it belongs to a user."""
|
||||
"""Updates the application if the user belongs to the group."""
|
||||
|
||||
application = get_object_or_404(
|
||||
Application.objects.select_related('group').select_for_update(),
|
||||
pk=application_id
|
||||
|
@ -77,6 +79,7 @@ class ApplicationView(APIView):
|
|||
})
|
||||
def delete(self, request, application_id):
|
||||
"""Deletes an existing application if the user belongs to the group."""
|
||||
|
||||
application = get_object_or_404(
|
||||
Application.objects.select_related('group'),
|
||||
pk=application_id
|
||||
|
|
|
@ -66,7 +66,7 @@ def validate_body(serializer_class):
|
|||
"""
|
||||
This decorator can validate the request body using a serializer. If the body is
|
||||
valid it will add the data to the kwargs. If not it will raise an APIException with
|
||||
structured details what is wrong.
|
||||
structured details about what is wrong.
|
||||
|
||||
Example:
|
||||
class LoginSerializer(serializers.Serializer):
|
||||
|
|
|
@ -18,6 +18,7 @@ class GroupsView(APIView):
|
|||
|
||||
def get(self, request):
|
||||
"""Responds with a list of groups where the users takes part in."""
|
||||
|
||||
groups = GroupUser.objects.filter(user=request.user).select_related('group')
|
||||
serializer = GroupUserSerializer(groups, many=True)
|
||||
return Response(serializer.data)
|
||||
|
@ -26,6 +27,7 @@ class GroupsView(APIView):
|
|||
@validate_body(GroupSerializer)
|
||||
def post(self, request, data):
|
||||
"""Creates a new group for a user."""
|
||||
|
||||
group_user = self.core_handler.create_group(request.user, name=data['name'])
|
||||
return Response(GroupUserSerializer(group_user).data)
|
||||
|
||||
|
@ -38,6 +40,7 @@ class GroupView(APIView):
|
|||
@validate_body(GroupSerializer)
|
||||
def patch(self, request, data, group_id):
|
||||
"""Updates the group if it belongs to a user."""
|
||||
|
||||
group_user = get_object_or_404(
|
||||
GroupUser.objects.select_for_update(),
|
||||
group_id=group_id,
|
||||
|
@ -52,6 +55,7 @@ class GroupView(APIView):
|
|||
@transaction.atomic
|
||||
def delete(self, request, group_id):
|
||||
"""Deletes an existing group if it belongs to a user."""
|
||||
|
||||
group_user = get_object_or_404(GroupUser, group_id=group_id, user=request.user)
|
||||
self.core_handler.delete_group(request.user, group_user.group)
|
||||
return Response(status=204)
|
||||
|
@ -64,5 +68,6 @@ class GroupOrderView(APIView):
|
|||
@validate_body(OrderGroupsSerializer)
|
||||
def post(self, request, data):
|
||||
"""Updates to order of some groups for a user."""
|
||||
|
||||
self.core_handler.order_groups(request.user, data['groups'])
|
||||
return Response(status=204)
|
||||
|
|
|
@ -28,6 +28,7 @@ class UserView(APIView):
|
|||
@validate_body(RegisterSerializer)
|
||||
def post(self, request, data):
|
||||
"""Registers a new user."""
|
||||
|
||||
user = self.user_handler.create_user(name=data['name'], email=data['email'],
|
||||
password=data['password'])
|
||||
|
||||
|
|
|
@ -7,8 +7,9 @@ class Application(object):
|
|||
"""
|
||||
This abstract class represents a custom application that can be added to the
|
||||
application registry. It must be extended so customisation can be done. Each
|
||||
application will have his own model that must extend the Application, this is needed
|
||||
to that the user can set custom settings per application instance he has created.
|
||||
application will have his own model that must extend the Application model, this is
|
||||
needed so that the user can set custom settings per application instance he has
|
||||
created.
|
||||
|
||||
Example:
|
||||
from baserow.core.models import Application as ApplicationModel
|
||||
|
@ -59,6 +60,7 @@ class Application(object):
|
|||
:return: A list containing the urls.
|
||||
:rtype: list
|
||||
"""
|
||||
|
||||
return []
|
||||
|
||||
|
||||
|
@ -113,6 +115,7 @@ class ApplicationRegistry(object):
|
|||
:return: A list of available types.
|
||||
:rtype: List
|
||||
"""
|
||||
|
||||
return list(self.registry.keys())
|
||||
|
||||
def register(self, application):
|
||||
|
@ -133,6 +136,14 @@ class ApplicationRegistry(object):
|
|||
self.registry[application.type] = application
|
||||
|
||||
def unregister(self, value):
|
||||
"""
|
||||
Removes a registered application from the registry. An application instance or
|
||||
type name can be provided as value.
|
||||
|
||||
:param value: The application instance or type name.
|
||||
:type value: Application or str
|
||||
"""
|
||||
|
||||
if isinstance(value, Application):
|
||||
for type, application in self.registry.items():
|
||||
if application == value:
|
||||
|
@ -152,6 +163,7 @@ class ApplicationRegistry(object):
|
|||
:return: The api urls of the registered applications.
|
||||
:rtype: list
|
||||
"""
|
||||
|
||||
api_urls = []
|
||||
for application in self.registry.values():
|
||||
api_urls += application.get_api_urls()
|
||||
|
|
|
@ -14,6 +14,7 @@ class OrderableMixin:
|
|||
:param field:
|
||||
:return:
|
||||
"""
|
||||
|
||||
return queryset.aggregate(
|
||||
models.Max(field)
|
||||
).get(f'{field}__max', 0) or 0
|
||||
|
|
|
@ -22,6 +22,7 @@ class Group(models.Model):
|
|||
|
||||
def has_user(self, user):
|
||||
"""Returns true is the user belongs to the group."""
|
||||
|
||||
return self.users.filter(id=user.id).exists()
|
||||
|
||||
def __str__(self):
|
||||
|
@ -64,9 +65,8 @@ class Application(OrderableMixin, models.Model):
|
|||
|
||||
@cached_property
|
||||
def specific(self):
|
||||
"""
|
||||
Return this page in its most specific subclassed form.
|
||||
"""
|
||||
"""Return this page in its most specific subclassed form."""
|
||||
|
||||
content_type = ContentType.objects.get_for_id(self.content_type_id)
|
||||
model_class = self.specific_class
|
||||
if model_class is None:
|
||||
|
@ -82,6 +82,7 @@ class Application(OrderableMixin, models.Model):
|
|||
Return the class that this application would be if instantiated in its
|
||||
most specific form
|
||||
"""
|
||||
|
||||
content_type = ContentType.objects.get_for_id(self.content_type_id)
|
||||
return content_type.model_class()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue