Exemple #1
0
    def target_models(self):
        target_models = []

        for target_model in self._target_models:
            target_models.append(resolve_model_string(target_model))

        return target_models
Exemple #2
0
    def target_model(self):
        """
        Defines the model used by the base ChooserBlock for ID <-> instance
        conversions. If a single page type is specified in target_model,
        we can use that to get the more specific instance "for free"; otherwise
        use the generic Page model.
        """
        if len(self.target_models) == 1:
            return self.target_models[0]

        return resolve_model_string('tuiuiucore.Page')
Exemple #3
0
def page_models_from_string(string):
    page_models = []

    for sub_string in string.split(','):
        page_model = resolve_model_string(sub_string)

        if not issubclass(page_model, Page):
            raise ValueError("Model is not a page")

        page_models.append(page_model)

    return tuple(page_models)
    def target_models(cls):
        if cls.page_type:
            target_models = []

            for page_type in cls.page_type:
                try:
                    target_models.append(resolve_model_string(page_type))
                except LookupError:
                    raise ImproperlyConfigured(
                        "{0}.page_type must be of the form 'app_label.model_name', given {1!r}"
                        .format(cls.__name__, page_type))
                except ValueError:
                    raise ImproperlyConfigured(
                        "{0}.page_type refers to model {1!r} that has not been installed"
                        .format(cls.__name__, page_type))

            return target_models
        else:
            return [cls.model._meta.get_field(cls.field_name).rel.to]
Exemple #5
0
    def get_queryset(self):
        request = self.request

        # Allow pages to be filtered to a specific type
        if 'type' not in request.GET:
            model = Page
        else:
            model_name = request.GET['type']
            try:
                model = resolve_model_string(model_name)
            except LookupError:
                raise BadRequestError("type doesn't exist")
            if not issubclass(model, Page):
                raise BadRequestError("type doesn't exist")

        # Get live pages that are not in a private section
        queryset = model.objects.public().live()

        # Filter by site
        queryset = queryset.descendant_of(request.site.root_page, inclusive=True)

        return queryset
Exemple #6
0
    def test_resolve_from_class(self):
        model = resolve_model_string(Page)

        self.assertEqual(model, Page)
Exemple #7
0
    def test_resolve_from_string_with_different_default_app(self):
        model = resolve_model_string('tuiuiucore.Page',
                                     default_app='tuiuiuadmin')

        self.assertEqual(model, Page)
Exemple #8
0
    def test_resolve_from_string(self):
        model = resolve_model_string('tuiuiucore.Page')

        self.assertEqual(model, Page)