GithubHelp home page GithubHelp logo

apiqa-storage's Introduction

apiqa-storage

This project aim is to provide user storage backend on minio for all apiqa django projects.

HowToUse

  • Add apiqa-storage to requirements.txt.
# Minio file storage
git+https://github.com/pik-software/apiqa-storage.git#egg=apiqa-storage
  • Add apiqa_storage to INSTALLED_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)
    },
}
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 .

apiqa-storage's People

Contributors

faunris avatar ivan-feofanov avatar jjoskey avatar kar-ni-o avatar paulanti avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.