Invenio digital library framework.
Project description
OARepo-actions
Instalation
pip install oarepo-actions
Usage
The library provides functionality for adding functions into your data models with supported REST methods, which are GET, POST, PUT and DELETE. It will create URL rule for your method, and use default or defined serializers, permissions and url path.
Decorate your method with @action()
decorator and add optional parameters.
List of optional parameters
url_path:
- for specifing url_path, which will be added after
list-route
oritem-route
from your configuration
permissions:
- by default
allow all
- accepts permission factory
method:
- for REST method
- by default
get
- you can use
get
,put
,delete
orpost
written with lowercase letters
serializers:
- by default
application/json
serializer. - accepts dictionary where key is MIME type and value your own serializer
detail:
- by default
True
. Change toFalse
if method is class method - determines which route will be used (
list route
if detail is False)
Examples
class SampleRecord(Record):
@action()
def test_a(self, **kwargs):
return {"title": self["title"]}
@classmethod
@action(detail=False, url_path="send_email")
def test_b(cls, **kwargs):
return {"title": self["title"]}
@classmethod
@action(detail=False, permissions=permission_factory)
def test_c(cls, **kwargs):
return {"title": self["title"]}
@classmethod
@action(detail=False, url_path="test/<int:param>", permissions=permission_factory)
def test_d(cls, param = None, **kwargs):
print("jej")
return Response(status=200)
@classmethod
@action(detail=False, permissions = permission_factory, serializers = {'text/html': make_response})
def test_e(cls, **kwargs):
return '<h1>xx</h1>'
@classmethod
@action(detail=False, url_path='test',permissions=allow_all, method='post')
def test_f(cls, param=None, **kwargs):
return {param: "yy"}
- url_a =
server
/records/1/test_a - url_b =
server
/records/send_email - url_c =
server
/records/test_c - url_d =
server
/records/test/42 - url_e =
server
/records/test_e - url_f =
server
/records/test- post method
Changes
Version 1.0.0 (released 2020-09-15)
- Initial public release.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
oarepo-actions-1.0.4.tar.gz
(13.1 kB
view hashes)
Built Distribution
Close
Hashes for oarepo_actions-1.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 287904d1f411357b5d97b44acc072ce67f5f0a12320f4105b5d11fd4b553a7f6 |
|
MD5 | 49b6b426d6927e21a439de54c08a5a76 |
|
BLAKE2b-256 | df71bc4a8d8ff0c6fdc650b47bf58e93ebb2037734f3baad0556078a00b6eba4 |