drf-forms / drf-schema-adapter

Making using Django with frontend libraries and frameworks DRYer
http://drf-schema-adapter.readthedocs.io/en/latest/
MIT License
157 stars 40 forks source link

Is export_app pretty much only for Ember guys? #36

Closed joshuajonah closed 6 years ago

joshuajonah commented 6 years ago

Traceback:

File "/home/joshua/Development/nctools/env/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner
  41.             response = get_response(request)

File "/home/joshua/Development/nctools/env/lib/python3.5/site-packages/django/core/handlers/base.py" in _legacy_get_response
  249.             response = self._get_response(request)

File "/home/joshua/Development/nctools/env/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "/home/joshua/Development/nctools/env/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/joshua/Development/nctools/env/lib/python3.5/site-packages/django/views/generic/base.py" in view
  68.             return self.dispatch(request, *args, **kwargs)

File "/home/joshua/Development/nctools/env/lib/python3.5/site-packages/django/views/generic/base.py" in dispatch
  88.         return handler(request, *args, **kwargs)

File "/home/joshua/Development/nctools/env/lib/python3.5/site-packages/django/views/generic/base.py" in get
  156.         return self.render_to_response(context)

File "/home/joshua/Development/nctools/env/lib/python3.5/site-packages/django/views/generic/base.py" in render_to_response
  130.             template=self.get_template_names(),

File "/home/joshua/Development/nctools/env/lib/python3.5/site-packages/export_app/views.py" in get_template_names
  14.         return [self.adapter_class.dynamic_template_name]

Exception Type: AttributeError at /models/address.js
Exception Value: type object 'MetadataAdapter' has no attribute 'dynamic_template_name'

So I decided maybe I'll just copy that dynamic_template_name into the BaseAdapater and that worked!.... But then I looked at the export and yep, all ember branded:

define('addresses/models/crm/address',
    ['exports', 'ember-data/model', 'ember-data/attr', 'ember-data/relationships'],
    function (exports, _emberDataModel, _emberDataAttr, _emberDataRelationships) {
  exports['default'] = _emberDataModel['default'].extend({

      name: (0, _emberDataAttr['default'])(),

      street_address: (0, _emberDataAttr['default'])(),

      street_address_cont: (0, _emberDataAttr['default'])(),

      city: (0, _emberDataAttr['default'])(),

      zip_code: (0, _emberDataAttr['default'])(),

      lat: (0, _emberDataAttr['default'])(),

      lng: (0, _emberDataAttr['default'])(),

      __str__: (0, _emberDataAttr['default'])(),

      state_or_province: (0, _emberDataRelationships['None'])('location/region', {async: true, inverse: 'address_state'}),

      on_store_locator: (0, _emberDataRelationships['None'])('sites/site', {async: true, inverse: null}),

  });
});

Then I looked at the template and figured I guess i could just copy it and format it the way I like. Is this normal? or is there a bug with the MetadataAdapter?

nanuxbe commented 6 years ago

It's not only for guys ;-)

But, as explained in the docs, the dynamic export only works with Ember so far http://drf-schema-adapter.readthedocs.io/en/latest/export_app/#usage The reason for this is that Ember comes built in with an "on-the-fly" model registration, other libraries don't.

There are most likely ways to do that with react, vue or angular using require. If you build your own template that works with any of the main-stream frontends (ie: angular, react, vue), PR's are welcome. You'll probably have to use/extend the adapter that is pre-configured for use with that frontend instead of using BaseAdapter too.