Sparq-Holding-Inc / pulpo-forms-django

Django app for dynamic forms
Apache License 2.0
48 stars 9 forks source link

Django 1.10 uncompatibility #3

Open ad-m opened 7 years ago

ad-m commented 7 years ago
$ python manage.py runserver
Unhandled exception in thread started by <function wrapper at 0x7f6d676a5e60>
Traceback (most recent call last):
  File "/tmp/tmp.YhlpebqLfC/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/tmp/tmp.YhlpebqLfC/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 113, in inner_run
    autoreload.raise_last_exception()
  File "/tmp/tmp.YhlpebqLfC/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
    six.reraise(*_exception)
  File "/tmp/tmp.YhlpebqLfC/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/tmp/tmp.YhlpebqLfC/local/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/tmp/tmp.YhlpebqLfC/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/tmp/tmp.YhlpebqLfC/local/lib/python2.7/site-packages/django/apps/config.py", line 199, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/tmp/tmp.YhlpebqLfC/local/lib/python2.7/site-packages/pulpo_forms/models.py", line 13, in <module>
    from pulpo_forms.fields import JSONField, STATUS, DRAFT, PUBLISHED, EXPIRED
  File "/tmp/tmp.YhlpebqLfC/local/lib/python2.7/site-packages/pulpo_forms/fields.py", line 23, in <module>
    class JSONField(models.TextField):
  File "/tmp/tmp.YhlpebqLfC/local/lib/python2.7/site-packages/pulpo_forms/fields.py", line 29, in JSONField
    __metaclass__ = models.SubfieldBase
AttributeError: 'module' object has no attribute 'SubfieldBase'

Fresh installation. No changes. Settings as in documentation. No errors on 'django<1.10'.

bcaessens commented 6 years ago

Ran into the same issues. These were the changes that got it to run:

In fields.py, remove the metaclass = models.SubFielddBase. Deprecated since 1.9, removed in django 1.10. Add a function below to_python like this:

def from_db_value(self,value,expression,connection,context):
        if value is None:
            return value
        try:
            if isinstance(value, str):
                return json.loads(value)
        except ValueError:
            pass

        return ""

Mind you, I am not sure that this will work in all calls to the db yet, but at least it gets you up and running.

In views.py on the line from django.conf.urls remove patterns, this was deprecated in 1.9. Keep urls. Then, convert your urlpattern definition into a list or tuple, as per the django docs. Finally, everywhere in this file where the view is called by a string name, replace it by calling the object from the imported pulpo_form views. E.g.

url(r'^main/(?P<order>(id|owner|title|creation_date))/(?P<ad>(asc|dsc))/$', 'ordered_forms', name="main_sort") should become:

url(r'^main/(?P<order>(id|owner|title|creation_date))/(?P<ad>(asc|dsc))/$', views.ordered_forms, name="main_sort")

This helps for me. Cheers.