danielquinn / django-encrypted-filefield

Encrypt uploaded files, store them wherever you like and stream them back unencrypted
GNU General Public License v3.0
65 stars 23 forks source link

AttributeError: type object 'FieldFile' has no attribute '_get_url' #4

Closed beardo01 closed 7 years ago

beardo01 commented 7 years ago

Hey there,

I've tried running this on Python 3.6 and Django 1.11 and am getting an error where the DetailView is failing because of the error in the title.

Edit: In fact, even the demo isn't working. I'm guessing it's something related to the newer Django version?

Edit 2: It turns out that _get_url was removed from django.db.models.fields.files.FieldFile in 1.11. I've changed your EncryptionMixin class on line 27 of fields.py:

From:

class EncryptionMixin(object):

    def save(self, name, content, save=True):
        return FieldFile.save(
            self,
            name,
            EncryptedFile(content),
            save=save
        )
    save.alters_data = True

    def _get_url(self):
        return reverse(FETCH_URL_NAME, kwargs={
            "path": FieldFile._get_url(self)
        })
    url = property(_get_url)

To:

class EncryptionMixin(object):

    def save(self, name, content, save=True):
        return FieldFile.save(
            self,
            name,
            EncryptedFile(content),
            save=save
        )
    save.alters_data = True

    def _get_url(self):
        return reverse(FETCH_URL_NAME, kwargs={
            "path": super(EncrpytionMixin, self).url
        })
    url = property(_get_url)

It seems to be working.

beardo01 commented 7 years ago

See potential fix in my original comment. I'll close the issue for now and let you test/integrate this.