django-filesify


Namedjango-filesify JSON
Version 0.1 PyPI version JSON
download
home_pagehttps://github.com/lazybird/django-filesify/
SummaryA Django reusable app to create physical files from database text field.
upload_time2023-10-03 14:22:54
maintainer
docs_urlNone
author
requires_python
license
keywords filesify django files container upload configuration volatile storage
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Django Filesify
===============

Django Filesify helps generate a physical files from a text content stored in
database and accessible from Django admin.
The file content can be a plaintext or an encrypted field.

Requirements
------------

-  Python 3.6+
-  Django 3.1+
-  Optional : django-mirage-field
-  Optional : Pip 22+


.. _filesify-usage:

Usage
-----

Extend ``Filesify`` class in your Django model and define your
custom fields:


.. _filesify-usage-plain-text:

For plaintext content
~~~~~~~~~~~~~~~~~~~~~

::

  from filesify.models import Filesify

  class MyConfigModel(Filesify):

      class Meta:
          verbose_name = "Some config file"
          verbose_name_plural = "Some config files"

.. _filesify-usage-encrypted:

For encrypted content
~~~~~~~~~~~~~~~~~~~~~

If your file content is sensitive information, you could decide to
encrypt it. This will be transparent to you, as the the ``file_content``
field provided by ``django-filesify`` will be encrypted on model save
and decrypted before displaying it on the admin.

For encrypted content, ``django-mirage-field`` is required.

You could install ``django-mirage-field`` like this :

::

  pip install django-mirage-fields

Extend CryptoFilesify:

::

  from filesify.models import CryptoFilesify

  class MyConfigModel(CryptoFilesify):

      class Meta:
          verbose_name = "Some config file"
          verbose_name_plural = "Some config files"



.. _filesify-model:

About the abstract model
------------------------

.. _filesify-model-fields:

Model Fields
~~~~~~~~~~~~

The model class provide the following fields:

-  ``file_path``: The path of the file to generate.
-  ``file_content``: The text file content - either plain text or
   encrypted, depending on the mixin used.
-  ``comment``: A TextField for optional comments about the file.


.. _filesify-model-file-generation:

File generation
~~~~~~~~~~~~~~~

The mixin class generates a file with the content provided in the
``file_content`` field. The file generation will be trigger on the
save() method, that means it's done automatically when creating or
updating your model instances.

::

   # This create 'example.txt' containing 'Hello, World!'
   obj = MyConfigModel()
   obj.file_path = "/tmp/example.txt"
   obj.file_content = "Hello, World!"
   obj.save()

   # Equivalent to:
   obj = MyConfigModel(file_path="/tmp/example.txt", file_content="Hello, World!")

   # The file generation can be triggered manually like this:
   obj.create_file()  


.. _filesify-model-file-removeal:

File removeal
~~~~~~~~~~~~~
When an Filesify object is delete, the files on disk will be deleted as well. This is done
by overriding the model ``delete()`` method.



.. _filesify-admin:

Filesify Admin
--------------


Django Filesify provide a admin class that can be used this way :


::

  from django.contrib import admin
  from my_app.models import MyConfigModel
  from filesify.admin import FilesifyAdmin

  @admin.register(MyConfigModel)
  class MyConfigModelAdmin(FilesifyAdmin):
      pass


  # Or using the alternate way:

  class MyConfigModel(FilesifyAdmin):
      pass

  admin.site.register(MyConfigModel, MyConfigModel)





The admin class comes with a custom action to delete selected objects and their associated files on disk.


Single file instance
--------------------

Sometimes, your project only require one single file instance.
In these cases, Django Filesify can be used in conjunction with
`Django Solo <https://github.com/lazybird/django-solo>`__,
a third-party app that helps dealing with singleton database model.

To achieve this, install Django Solo and use it together with Filesify
in your models and your admin classes.


**Singleton models:**

::

  from django.db import models
  from django_solo.models import SingletonModel
  from filesify.models import Filesify

  class MyConfigModel(SingletonModel, Filesify):
      class Meta:
          verbose_name = "Some Config File"
          verbose_name_plural = "Some Config File"


**Singleton admin:**

::

  from django.contrib import admin
  from django_solo.admin import SingletonModelAdmin
  from filesify.admin import FilesifyAdmin

  from my_app.models import MyConfigModel

  @admin.register(MyConfigModel)
  class MyConfigModelAdmin(SingletonModelAdmin, FilesifyAdmin):
      pass


Filesify on post migrate signal
-------------------------------

Django Filesify provides a mixin class that can be used to create files automatically
after running database migrations.


Usage
~~~~~

::

  from django.apps import AppConfig

  from filesify.mixins import FilesifyPostMigrateMixin


  class MyAppConfig(FilesifyPostMigrateMixin, AppConfig):
      default_auto_field = "django.db.models.BigAutoField"
      name = "my_app"


This will discover all models extended from Filesify abstract model and
will create the corresponding files.

.. _filesify-mixin-limit_to_models:

Limit to models
~~~~~~~~~~~~~~~

If you want to limit the list of models to be looked at, you could
define a list of dotted path models with the
`filesify_limit_to_models` attribute.
If `filesify_limit_to_models`` is None, it calls the management command
with no arguments, considering all models.

::
  
  class MyAppConfig(FilesifyPostMigrateMixin, AppConfig):
      default_auto_field = "django.db.models.BigAutoField"
      name = "my_app"
      filesify_limit_to_models = ["my_app.MyConfigModel"]


Filesify base mixin
--------------------

If you are looking for a mode generic way to generate files from models
that are extended from the Filesify class, you could use the
`filesify.mixins.FilesifyBaseMixin` class.

::

  from my_app.filesify import SomeGenericClass

  something = SomeGenericClass()
  something.filesify_limit_to_models = ['my_app.MyConfigModel1', 'my_app.MyConfigModel2']
  something.create_files()


Notice how you can optionally limit the models that the file creation should look at.


Contribute to Django Filesify
-----------------------------

If you already have a working environnement with django running, you could install
django-filesify in "editable" mode in that receiving project.

Get the package source code somewhere outside your project folders, in this example,
will will use the parent folder.

::

  cd you/working/django/project/

  git clone https://github.com/lazybird/django-filesify.git ../django-filesify/

  or

  git clone git@github.com:lazybird/django-filesify.git ../django-filesify/


Now the code inside ``../django-filesify/`` is where you'll make changes.

You can install the package in then "editable" mode in you working project.
Here we assume you are in you project's virtual environnement.

::

  pip uninstall django-filesify  # just in case you have it already...
  pip install --editable ../django-filesify/



Run tests :

::

  python ../django-filesify/filesify/tests/runtests.py


  pytest ../django-filesify/filesify/tests/tests.py --ds=filesify.tests.settings

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/lazybird/django-filesify/",
    "name": "django-filesify",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "filesify django files container upload configuration volatile storage",
    "author": "",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/6d/cc/bbae9469a8050f286925ee47b0dbe08a69735159d8ce394339e29d8e1f1a/django-filesify-0.1.tar.gz",
    "platform": null,
    "description": "Django Filesify\n===============\n\nDjango Filesify helps generate a physical files from a text content stored in\ndatabase and accessible from Django admin.\nThe file content can be a plaintext or an encrypted field.\n\nRequirements\n------------\n\n-  Python 3.6+\n-  Django 3.1+\n-  Optional : django-mirage-field\n-  Optional : Pip 22+\n\n\n.. _filesify-usage:\n\nUsage\n-----\n\nExtend ``Filesify`` class in your Django model and define your\ncustom fields:\n\n\n.. _filesify-usage-plain-text:\n\nFor plaintext content\n~~~~~~~~~~~~~~~~~~~~~\n\n::\n\n  from filesify.models import Filesify\n\n  class MyConfigModel(Filesify):\n\n      class Meta:\n          verbose_name = \"Some config file\"\n          verbose_name_plural = \"Some config files\"\n\n.. _filesify-usage-encrypted:\n\nFor encrypted content\n~~~~~~~~~~~~~~~~~~~~~\n\nIf your file content is sensitive information, you could decide to\nencrypt it. This will be transparent to you, as the the ``file_content``\nfield provided by ``django-filesify`` will be encrypted on model save\nand decrypted before displaying it on the admin.\n\nFor encrypted content, ``django-mirage-field`` is required.\n\nYou could install ``django-mirage-field`` like this :\n\n::\n\n  pip install django-mirage-fields\n\nExtend CryptoFilesify:\n\n::\n\n  from filesify.models import CryptoFilesify\n\n  class MyConfigModel(CryptoFilesify):\n\n      class Meta:\n          verbose_name = \"Some config file\"\n          verbose_name_plural = \"Some config files\"\n\n\n\n.. _filesify-model:\n\nAbout the abstract model\n------------------------\n\n.. _filesify-model-fields:\n\nModel Fields\n~~~~~~~~~~~~\n\nThe model class provide the following fields:\n\n-  ``file_path``: The path of the file to generate.\n-  ``file_content``: The text file content - either plain text or\n   encrypted, depending on the mixin used.\n-  ``comment``: A TextField for optional comments about the file.\n\n\n.. _filesify-model-file-generation:\n\nFile generation\n~~~~~~~~~~~~~~~\n\nThe mixin class generates a file with the content provided in the\n``file_content`` field. The file generation will be trigger on the\nsave() method, that means it's done automatically when creating or\nupdating your model instances.\n\n::\n\n   # This create 'example.txt' containing 'Hello, World!'\n   obj = MyConfigModel()\n   obj.file_path = \"/tmp/example.txt\"\n   obj.file_content = \"Hello, World!\"\n   obj.save()\n\n   # Equivalent to:\n   obj = MyConfigModel(file_path=\"/tmp/example.txt\", file_content=\"Hello, World!\")\n\n   # The file generation can be triggered manually like this:\n   obj.create_file()  \n\n\n.. _filesify-model-file-removeal:\n\nFile removeal\n~~~~~~~~~~~~~\nWhen an Filesify object is delete, the files on disk will be deleted as well. This is done\nby overriding the model ``delete()`` method.\n\n\n\n.. _filesify-admin:\n\nFilesify Admin\n--------------\n\n\nDjango Filesify provide a admin class that can be used this way :\n\n\n::\n\n  from django.contrib import admin\n  from my_app.models import MyConfigModel\n  from filesify.admin import FilesifyAdmin\n\n  @admin.register(MyConfigModel)\n  class MyConfigModelAdmin(FilesifyAdmin):\n      pass\n\n\n  # Or using the alternate way:\n\n  class MyConfigModel(FilesifyAdmin):\n      pass\n\n  admin.site.register(MyConfigModel, MyConfigModel)\n\n\n\n\n\nThe admin class comes with a custom action to delete selected objects and their associated files on disk.\n\n\nSingle file instance\n--------------------\n\nSometimes, your project only require one single file instance.\nIn these cases, Django Filesify can be used in conjunction with\n`Django Solo <https://github.com/lazybird/django-solo>`__,\na third-party app that helps dealing with singleton database model.\n\nTo achieve this, install Django Solo and use it together with Filesify\nin your models and your admin classes.\n\n\n**Singleton models:**\n\n::\n\n  from django.db import models\n  from django_solo.models import SingletonModel\n  from filesify.models import Filesify\n\n  class MyConfigModel(SingletonModel, Filesify):\n      class Meta:\n          verbose_name = \"Some Config File\"\n          verbose_name_plural = \"Some Config File\"\n\n\n**Singleton admin:**\n\n::\n\n  from django.contrib import admin\n  from django_solo.admin import SingletonModelAdmin\n  from filesify.admin import FilesifyAdmin\n\n  from my_app.models import MyConfigModel\n\n  @admin.register(MyConfigModel)\n  class MyConfigModelAdmin(SingletonModelAdmin, FilesifyAdmin):\n      pass\n\n\nFilesify on post migrate signal\n-------------------------------\n\nDjango Filesify provides a mixin class that can be used to create files automatically\nafter running database migrations.\n\n\nUsage\n~~~~~\n\n::\n\n  from django.apps import AppConfig\n\n  from filesify.mixins import FilesifyPostMigrateMixin\n\n\n  class MyAppConfig(FilesifyPostMigrateMixin, AppConfig):\n      default_auto_field = \"django.db.models.BigAutoField\"\n      name = \"my_app\"\n\n\nThis will discover all models extended from Filesify abstract model and\nwill create the corresponding files.\n\n.. _filesify-mixin-limit_to_models:\n\nLimit to models\n~~~~~~~~~~~~~~~\n\nIf you want to limit the list of models to be looked at, you could\ndefine a list of dotted path models with the\n`filesify_limit_to_models` attribute.\nIf `filesify_limit_to_models`` is None, it calls the management command\nwith no arguments, considering all models.\n\n::\n  \n  class MyAppConfig(FilesifyPostMigrateMixin, AppConfig):\n      default_auto_field = \"django.db.models.BigAutoField\"\n      name = \"my_app\"\n      filesify_limit_to_models = [\"my_app.MyConfigModel\"]\n\n\nFilesify base mixin\n--------------------\n\nIf you are looking for a mode generic way to generate files from models\nthat are extended from the Filesify class, you could use the\n`filesify.mixins.FilesifyBaseMixin` class.\n\n::\n\n  from my_app.filesify import SomeGenericClass\n\n  something = SomeGenericClass()\n  something.filesify_limit_to_models = ['my_app.MyConfigModel1', 'my_app.MyConfigModel2']\n  something.create_files()\n\n\nNotice how you can optionally limit the models that the file creation should look at.\n\n\nContribute to Django Filesify\n-----------------------------\n\nIf you already have a working environnement with django running, you could install\ndjango-filesify in \"editable\" mode in that receiving project.\n\nGet the package source code somewhere outside your project folders, in this example,\nwill will use the parent folder.\n\n::\n\n  cd you/working/django/project/\n\n  git clone https://github.com/lazybird/django-filesify.git ../django-filesify/\n\n  or\n\n  git clone git@github.com:lazybird/django-filesify.git ../django-filesify/\n\n\nNow the code inside ``../django-filesify/`` is where you'll make changes.\n\nYou can install the package in then \"editable\" mode in you working project.\nHere we assume you are in you project's virtual environnement.\n\n::\n\n  pip uninstall django-filesify  # just in case you have it already...\n  pip install --editable ../django-filesify/\n\n\n\nRun tests :\n\n::\n\n  python ../django-filesify/filesify/tests/runtests.py\n\n\n  pytest ../django-filesify/filesify/tests/tests.py --ds=filesify.tests.settings\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A Django reusable app to create physical files from database text field.",
    "version": "0.1",
    "project_urls": {
        "Homepage": "https://github.com/lazybird/django-filesify/"
    },
    "split_keywords": [
        "filesify",
        "django",
        "files",
        "container",
        "upload",
        "configuration",
        "volatile",
        "storage"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "13feffa4d5b549835b9e2e393af415f5fcce54eebc819100c622b807738aa0f4",
                "md5": "515ad6028c050901f73d3ab1e8a789b9",
                "sha256": "5257eddf258a8eb56dd9075643abd4226b73dacfe69fd33ac5c20cf01baf18ae"
            },
            "downloads": -1,
            "filename": "django_filesify-0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "515ad6028c050901f73d3ab1e8a789b9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 19140,
            "upload_time": "2023-10-03T14:22:52",
            "upload_time_iso_8601": "2023-10-03T14:22:52.656172Z",
            "url": "https://files.pythonhosted.org/packages/13/fe/ffa4d5b549835b9e2e393af415f5fcce54eebc819100c622b807738aa0f4/django_filesify-0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6dccbbae9469a8050f286925ee47b0dbe08a69735159d8ce394339e29d8e1f1a",
                "md5": "f25219d752980fdab486f583e380d29d",
                "sha256": "322009209d0248949da7655d69a8f70afea8afbb1e62a712e250ed86dd8fa0c7"
            },
            "downloads": -1,
            "filename": "django-filesify-0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "f25219d752980fdab486f583e380d29d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 12192,
            "upload_time": "2023-10-03T14:22:54",
            "upload_time_iso_8601": "2023-10-03T14:22:54.518961Z",
            "url": "https://files.pythonhosted.org/packages/6d/cc/bbae9469a8050f286925ee47b0dbe08a69735159d8ce394339e29d8e1f1a/django-filesify-0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-03 14:22:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lazybird",
    "github_project": "django-filesify",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "django-filesify"
}
        
Elapsed time: 0.12683s