Giter Club home page Giter Club logo

django-proxy-storage's Introduction

Django-proxy-storage

Provides simple subclass of django storage that proxies every operation to original storage and saves meta information about files to database.

Full documentation for project is available at http://chibisov.github.io/django-proxy-storage/docs

Build Status PyPI

Requirements

  • Tested for python 2.7 and 3.5 versions
  • Tested for Django 1.8 and 1.9 versions

Installation

$ pip install django-proxy-storage

Running tests

Unittest of this package requires docker. That's why for Mac OS X you have to install vagrant and only then run tests in VM.

$ cd tests_app
$ vagrant up
$ vagrant ssh
$ cd /vagrant/

Running the tests:

$ sudo make prepare_for_tests
$ tox -- tests_app

Running test for exact environment:

$ tox -e py27-django18 -- tests_app

Recreate envs before running tests:

$ tox --recreate -- tests_app

Pass custom arguments:

$ tox -- tests_app --verbosity=3

Run with pdb support:

$ tox -- tests_app --processes=0 --nocapture

Run exact TestCase:

$ tox -- tests_app.tests.unit.meta_backends.orm.tests:ORMMetaBackendTest

Run tests from exact module:

$ tox -- tests_app.tests.unit.meta_backends.tests

Documentation

Build docs:

$ make build_docs

Automatically build docs by watching changes:

$ pip install watchdog
$ make watch_docs

django-proxy-storage's People

Contributors

chibisov avatar sysradium avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

django-proxy-storage's Issues

Bug in open(path) if upload_dir don`t set

Example:

class TestFile(models.Model):
    name = models.CharField(max_length=255, default=get_random_string)
    file = ProxyStorageFileField(storage=storage)

We have ProxyStorageFileField without upload_to. In this case we can`t find uploaded file =/

I use this test function for serving files:

def serve_from_storage(request, path):
    try:
        file = storage.open(utils.clean_path(path))
    except Exception:
        raise Http404()
    else:
        return HttpResponse(file, content_type=guess_type(path)[0])


urlpatterns = patterns(
    '',
    url(r'^media/(?P<path>.+)', serve_from_storage),
)

LICENSE

Would you mind clarifying the licensing please.

"BSD" can refer to BSD-2-Clause or BSD-3-Clause.

It is really helpful to have a LICENSE file in the repository - without that it is unclear , and the license text usually refers to a Copyright line which is contained in that file, and is custom for each project.

Storage must provide a url() method

  File "/Users/pahaz/__data__/venv/lib/python3.5/site-packages/django/db/models/fields/files.py", line 69, in _get_url
    return self.storage.url(self.name)
  File "/Users/pahaz/__data__/venv/lib/python3.5/site-packages/django/core/files/storage.py", line 150, in url
    raise NotImplementedError('subclasses of Storage must provide a url() method')
NotImplementedError: subclasses of Storage must provide a url() method

Django 2.0.3

Здравствуйте.

Попытался использовать в связке с вышеозначенной версией django. Использовал ORMMetaBackend, основываясь на примере Authorization

# storages.py
from django.core.files.storage import FileSystemStorage
from proxy_storage.storages.base import ProxyStorageBase
from proxy_storage.meta_backends.orm import ORMMetaBackend
from proxy_storage.meta_backends.orm import ProxyStorageModelBase, ContentObjectFieldMixin
from django.utils.deconstruct import deconstructible


class ProxyStorageModel(ContentObjectFieldMixin, ProxyStorageModelBase):
    pass


orm_meta_backend = ORMMetaBackend(model=ProxyStorageModel)



@deconstructible
class FileSystemProxyStorage(ProxyStorageBase):
    meta_backend = orm_meta_backend
    original_storage = FileSystemStorage(location='/files/download/')

Мне пришлось добавить декоратор @deconstructible иначе проект вообще не запускался (в примере Authorization этого декоратора нет)
Поле в модели:

letter = ProxyStorageFileField(
        _('Основание'),
        validators=[
            FileExtensionValidator(allowed_extensions=['pdf']),
            FileMimeTypeValidator(allowed_mime_types=['application/pdf']),
        ],
        blank=True,
        storage=FileSystemProxyStorage(),
    )

При сохранении модели вылазит ошибка следующего содержания:

Traceback (most recent call last):
File "\venv\lib\site-packages\django\core\handlers\exception.py", line 35, in inner response = get_response(request) File "\venv\lib\site-packages\django\core\handlers\base.py", line 128, in _get_response
response = self.process_exception_by_middleware(e, request)
File "\venv\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/mso\mso_users\views.py", line 26, in registration
mso_user.save()
File "\venv\lib\site-packages\django\contrib\auth\base_user.py", line 73, in save super().save(*args, **kwargs) File "\venv\lib\site-packages\django\db\models\base.py", line 729, in save
force_update=force_update, update_fields=update_fields)
File "\venv\lib\site-packages\django\db\models\base.py", line 759, in save_base updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields) File "\venv\lib\site-packages\django\db\models\base.py", line 842, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "\venv\lib\site-packages\django\db\models\base.py", line 880, in _do_insert using=using, raw=raw) File "\venv\lib\site-packages\django\db\models\manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "\venv\lib\site-packages\django\db\models\query.py", line 1125, in _insert return query.get_compiler(using=using).execute_sql(return_id) File "\venv\lib\site-packages\django\db\models\sql\compiler.py", line 1282, in execute_sql
for sql, params in self.as_sql():
File "\venv\lib\site-packages\django\db\models\sql\compiler.py", line 1235, in as_sql for obj in self.query.objs File "\venv\lib\site-packages\django\db\models\sql\compiler.py", line 1235, in
for obj in self.query.objs
File "\venv\lib\site-packages\django\db\models\sql\compiler.py", line 1234, in <listcomp> [self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields] File "\venv\lib\site-packages\django\db\models\sql\compiler.py", line 1184, in pre_save_val
return field.pre_save(obj, add=True)
File "\venv\lib\site-packages\django\db\models\fields\files.py", line 287, in pre_save file.save(file.name, file.file, save=False) File "\venv\lib\site-packages\django\db\models\fields\files.py", line 87, in save
self.name = self.storage.save(name, content, max_length=self.field.max_length)
TypeError: save() got an unexpected keyword argument 'max_length'

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.