Example #1
0
 def get_message(self, sender, instance, **kwargs):
     """ unfortunately the design of tastypie makes it hard to use it to just serialize objects
         if you do much with the request in your resource this will break
     """
     if isinstance(self.resource, basestring):
         self.resource = smartimport(self.resource)
     resource = self.resource()
     # is this the least disruptive way to to this?
     def get_obj(**kwargs):
         return instance
     self.resource.get_obj = get_obj
     # if anything tries to use this it will likely fail
     req = HttpRequest()
     bundle = resource.build_bundle(obj=instance)
     bundle = resource.full_dehydrate(bundle)
     # TODO: should we even support this? it seems likely to be request specific
     bundle = resource.alter_detail_data_to_serialize(req, bundle)
     return resource.serialize(req, bundle, 'application/json')
Example #2
0
 def test_imports_package(self):
     """ smart import will import a package """
     importable = smartimport('parker.tests.importable')
     import parker.tests.importable
     assert importable == parker.tests.importable
Example #3
0
 def test_imports_inner(self):
     """ smart import will import something at the top level of a package """
     Foo = smartimport('parker.tests.importable.Foo')
     import parker.tests.importable
     assert Foo == parker.tests.importable.Foo
Example #4
0
 def test_imports_inner2(self):
     """ smart import will import something deep inside a package """
     bar = smartimport('parker.tests.importable.foo.bar')
     import parker.tests.importable
     assert bar == parker.tests.importable.foo.bar
Example #5
0
""" TODO this should only be a temporary place to make sure the libary is built """

from django.conf import settings
from parker.library import parker_lib
from parker.util import smartimport



if getattr(settings, 'PARKER_AUTODISCOVER', True):
    for app in settings.INSTALLED_APPS:
        try:
            __import__(app + ".carriers")
        except ImportError:
            # TODO we probably need to be more specific than just import err
            # we only want to skip when the module doesn't exit
            pass
else:
    for carrier in settings.PARKER_CARRIERS:
        parker_lib.register(smartimport(carrier))