コード例 #1
0
def get_serializer_class(model_name=None, serializer_type='default'):
    """
    Returns a serializer
    model_name: The model eg 'User' or 'Project'
    serializer_type: The serializer eg 'preview' or 'manage'
    """

    model = get_model_class(model_name)

    if serializer_type == 'manage':
        try:
            serializer_name = model._meta.manage_serializer
        except AttributeError:
            serializer_name = model.Meta.manage_serializer
    elif serializer_type == 'preview':
        try:
            serializer_name = model._meta.preview_serializer
        except AttributeError:
            serializer_name = model.Meta.preview_serializer
    elif serializer_type == 'default':
        try:
            serializer_name = model._meta.default_serializer
        except AttributeError:
            serializer_name = model.Meta.default_serializer
    else:
        raise ImproperlyConfigured(
            "Unknown serializer type '{0}'".format(serializer_type))

    serializer_model = import_class(serializer_name)

    if serializer_model is None:
        raise ImproperlyConfigured(
            "serializer_name refers to model '{0}' that has not been "
            "installed".format(model_name))

    return serializer_model
コード例 #2
0
ファイル: test_api.py プロジェクト: maykinmedia/bluebottle
from bluebottle.test.factory_models.orders import OrderFactory
from bluebottle.test.factory_models.donations import DonationFactory
from bluebottle.utils.model_dispatcher import get_order_model, get_model_class
from bluebottle.test.factory_models.fundraisers import FundraiserFactory
from bluebottle.test.utils import InitProjectDataMixin

from django.conf import settings
from django.utils.importlib import import_module

from django.core.urlresolvers import reverse
from bluebottle.utils.utils import StatusDefinition

from rest_framework import status

ORDER_MODEL = get_order_model()
DONATION_MODEL = get_model_class("DONATIONS_DONATION_MODEL")


class DonationApiTestCase(InitProjectDataMixin, TestCase):

    def setUp(self):
        settings.SESSION_ENGINE = 'django.contrib.sessions.backends.file'
        engine = import_module(settings.SESSION_ENGINE)
        store = engine.SessionStore()
        store.save()
        self.session = store
        self.client.cookies[settings.SESSION_COOKIE_NAME] = store.session_key

        self.addCleanup(self._clear_session)

        self.user1 = BlueBottleUserFactory.create()