Apiqa user storage backend for django projects
Project description
apiqa-storage
This project aim is to provide user storage backend on minio for all apiqa django projects.
HowToUse
- Add
apiqa-storage
torequirements.txt
.
# Minio file storage
git+https://github.com/pik-software/apiqa-storage.git#egg=apiqa-storage
- Add
apiqa_storage
toINSTALLED_APPS
in settings file.
INSTALLED_APPS = [
'django.contrib.admin',
...,
'apiqa_storage'
]
- Add mixin
ModelWithAttachmentsMixin
to any model. Make and run migrations.
from apiqa_storage.models import ModelWithAttachmentsMixin
class UserFile(ModelWithAttachmentsMixin, ...):
...
- Add serializer mixin at the beginning and add
attachments
,attachment_ids
to fields.
from apiqa_storage.serializers import AttachmentsSerializerMixin
class ModelWithAttachmentsSerializer(AttachmentsSerializerMixin, ...):
...
class Meta:
...
fields = (..., 'attachments', 'attachment_ids')
- Add download and upload file urls to urlpatterns.
from django.urls import path, include
urlpatterns = [
path('attachments/', include('apiqa_storage.urls')),
]
- Or add staff download file url to urlpatterns.
from django.urls import path, include
urlpatterns = [ # noqa
path('attachments/', include('apiqa_storage.staff_urls')),
]
- Add clean files task to celery beat config.
from celery.schedules import crontab
beat_schedule = {
# apiqa-storage clean files
'purge_attachments': {
'task': 'apiqa_storage.tasks.purge_attachments',
'schedule': crontab(hour=5)
},
}
- Add required minio settings. Create bucket on minio! django minio storage usage
MINIO_STORAGE_ENDPOINT = 'minio:9000'
MINIO_STORAGE_ACCESS_KEY = ...
MINIO_STORAGE_SECRET_KEY = ...
MINIO_STORAGE_BUCKET_NAME = 'local-static'
-
Other settings
- MINIO_STORAGE_MAX_FILE_SIZE: File size limit for upload, humanfriendly value. See https://humanfriendly.readthedocs.io/en/latest/readme.html#a-note-about-size-units. Default 100M
- MINIO_STORAGE_MAX_FILE_NAME_LEN: File name length limit. Use for database char limit. Default 100
- MINIO_STORAGE_MAX_FILES_COUNT: Limit of files in one object. For example 5 files in ticket. None - is unlimited. Default None
- MINIO_STORAGE_USE_HTTPS: Use https for connect to minio. Default False
- MINIO_STORAGE_CLEAN_PERIOD: Delete files without related objects after N days. Default 30
-
Run test
pip install -r requirements.txt
pip install -r requirements.dev.txt
docker-compose up
pytest --cov .
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
apiqa-storage-2.6.tar.gz
(11.8 kB
view details)
Built Distribution
File details
Details for the file apiqa-storage-2.6.tar.gz
.
File metadata
- Download URL: apiqa-storage-2.6.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcbc8912d9bdc435c549a678a3e388d8b966a17ee92f76165a83da87f5d83171 |
|
MD5 | 9b06bb6419df3321cca76de7d84e7877 |
|
BLAKE2b-256 | fa2efc82d85e6c7b2bcb53808d741004efed56f55819f17dfef8c15478e94f91 |
File details
Details for the file apiqa_storage-2.6-py3-none-any.whl
.
File metadata
- Download URL: apiqa_storage-2.6-py3-none-any.whl
- Upload date:
- Size: 16.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d37c0700d938beb3be53450ea8b9b57b8ab5b931088572c9b468dae7721a66d3 |
|
MD5 | 3016429aea579ad78b053e1bbceac633 |
|
BLAKE2b-256 | 0e077f5e23a29b77b500b00ea4f2c4811a0362d6f1081d8d379a73da7e122013 |