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. You must have **kwargs as your function parameter.
List of optional parameters
url_path:
- for specifing url_path, which will be added after
list-routeoritem-routefrom your configuration
permissions:
- by default
allow all - accepts permission factory
method:
- for REST method
- by default
get - you can use
get,put,deleteorpostwritten with lowercase letters
serializers:
- by default
application/jsonserializer. - accepts dictionary where key is MIME type and value your own serializer
- serializers takes arguments from function as *args.Therefore if you want to return array, you must
wrap it with another array (
return [["a", "b", "c"]])
detail:
- by default
True. Change toFalseif method is class method - determines which route will be used (
list routeif 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
Record class
If you put record_class parameter in your decorated function, it will be filled with record class obtained from config.py
Example
@classmethod
@action(detail=False, url_path="jej")
def test(cls,record_class, **kwargs):
record_uuid = uuid.uuid4()
data = {"title": "The title of the record", "contributors": [{"name": "something"}]}
pid, data = record_minter(record_uuid, data)
record = record_class.create(data=data, id_=record_uuid)
indexer = RecordIndexer()
res = indexer.index(record)
db.session.commit()
return record
Changes
Version 1.0.0 (released 2020-09-15)
- Initial public release.
Metadata
Release files for oarepo-actions 1.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| oarepo-actions-1.0.7.tar.gz | 15.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| oarepo_actions-1.0.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.9 kB
Release files / oarepo-actions-1.0.7.tar.gz
| Download URL | oarepo-actions-1.0.7.tar.gz |
|---|---|
| Size | 15.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f9cee8d92e7d095c9b4a2572aca0f5574dfda58a7e862fdc1fd866bc23d17adc
|
|
BLAKE2b-256 checksum How to use checksums |
f1739c643ce710287249da62458bf240d064a127b517666351dc7d97f8862cc6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2
|
Release files / oarepo_actions-1.0.7-py3-none-any.whl
| Download URL | oarepo_actions-1.0.7-py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
012a534b906ff19784e745f7a284f1f00d60b824f69db006ad7139a573ee47df
|
|
BLAKE2b-256 checksum How to use checksums |
ac1a18568722665dfa708e5a732dd3217e01edaa7c494f7fa314a4d98343bf8c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2
|
Security for oarepo-actions 1.0.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.