How to use the feincms.utils.get_object function in FeinCMS

To help you get started, we’ve selected a few FeinCMS examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github feincms / feincms / feincms / tests.py View on Github external
        self.assertRaises(AttributeError, lambda: get_object('feincms.does_not_exist'))
        self.assertRaises(ImportError, lambda: get_object('feincms.does_not_exist.fn'))
github matthiask / django-content-editor / feincms / tests.py View on Github external
def test_get_object(self):
        from feincms.utils import get_object

        self.assertRaises(AttributeError, lambda: get_object('feincms.does_not_exist'))
        self.assertRaises(ImportError, lambda: get_object('feincms.does_not_exist.fn'))

        self.assertEqual(get_object, get_object('feincms.utils.get_object'))
github matthiask / django-content-editor / feincms / tests.py View on Github external
        self.assertRaises(AttributeError, lambda: get_object('feincms.does_not_exist'))
        self.assertRaises(ImportError, lambda: get_object('feincms.does_not_exist.fn'))
github django-leonardo / django-leonardo / leonardo / module / web / widget / application / models.py View on Github external
def process(self, request, **kw):
        page_url = self.parent.get_absolute_url()

        if "path_mapper" in self.app_config:
            path_mapper = get_object(self.app_config["path_mapper"])
            path, page_url = path_mapper(
                request.path,
                page_url,
                appcontent_parameters=self.parameters
            )
        else:
            path = request._feincms_extra_context['extra_path']

        # Resolve the module holding the application urls.
        urlconf_path = self.app_config.get('urls', self.urlconf_path)

        try:
            fn, args, kwargs = resolve(path, urlconf_path)
        except (ValueError, Resolver404):
            raise Resolver404(str('Not found (resolving %r in %r failed)') % (
                path, urlconf_path))
github lvanderree / feincms-mercury / mercury / views.py View on Github external
"""
    content save handler
    Returns a HttpResponse whose content is JSON to tell if the operation succeeded.
    """
    result = {'result': False}

    if request.method == 'POST':
        if request.POST['content']:
            page_items = loads(request.POST['content'])

            for content_key, item in page_items.iteritems():
                # TODO: use form, so cleaned value can be retrieved

                content = item['value']
                if settings.FEINCMS_TIDY_HTML:
                    content , errors, warnings = get_object(settings.FEINCMS_TIDY_FUNCTION)(content)

                matches = re.search('^page-page-richtextcontent-(\d+)-(\d+)$', content_key)
                if matches:
                    page_id, content_id = matches.group(1), matches.group(2)

                    # TODO: replace with more flexible solution (not tied to the RichTextContent model), as done in _frontend_editing_view
                    RTC = Page.content_type_for(RichTextContent)
                    rtc = RTC.objects.get(id=content_id, parent__id=page_id)
                    rtc.text = content

                    rtc.save()
                    # TODO: this should be done differently; being able to handle every page-item separartly (see formsets)
                    result = {'result': True}

    return HttpResponse(dumps(result),
            content_type="application/json")
github django-leonardo / django-leonardo / leonardo / module / web / widget / application / models.py View on Github external
# context_processor
        request._feincms_extra_context.update(self.parameters)
        request._feincms_extra_context.update({'widget': self})

        # Save the application configuration for reuse elsewhere
        request._feincms_extra_context.update({
            'app_config': dict(
                self.app_config,
                urlconf_path=self.urlconf_path,
            ),
        })

        view_wrapper = self.app_config.get("view_wrapper", None)
        if view_wrapper:
            fn = partial(
                get_object(view_wrapper),
                view=fn,
                appcontent_parameters=self.parameters
            )

        output = fn(request, *args, **kwargs)

        # handle django rest framework as external application
        if hasattr(output, 'renderer_context'):
            output.context_data = output.renderer_context
            output.standalone = True

        if isinstance(output, HttpResponse):

            # update context
            if hasattr(output, 'context_data'):
                output.context_data['widget'] = self
github feincms / feincms / feincms / apps / contents.py View on Github external
try:
                        # TODO use urlconf_path from POST if set
                        # urlconf_path = request.POST.get('...urlconf_path',
                        #     instance.urlconf_path)
                        self.app_config = cls.ALL_APPS_CONFIG[
                            instance.urlconf_path]['config']
                    except KeyError:
                        self.app_config = {}

                    self.custom_fields = {}
                    admin_fields = self.app_config.get('admin_fields', {})

                    if isinstance(admin_fields, dict):
                        self.custom_fields.update(admin_fields)
                    else:
                        get_fields = get_object(admin_fields)
                        self.custom_fields.update(
                            get_fields(self, *args, **kwargs))

                    params = self.instance.parameters
                    for k, v in self.custom_fields.items():
                        v.initial = params.get(k)
                        self.fields[k] = v
                        if k in params:
                            self.fields[k].initial = params[k]
github feincms / feincms / feincms / module / medialibrary / thumbnail.py View on Github external
def admin_thumbnail(mediafile, dimensions="100x100"):
    global _cached_thumbnailer
    if not _cached_thumbnailer:
        _cached_thumbnailer = get_object(settings.FEINCMS_MEDIALIBRARY_THUMBNAIL)
    return _cached_thumbnailer(mediafile, dimensions=dimensions)
github lvanderree / feincms-mercury / mercury / models.py View on Github external
def clean(self, value, model_instance):
        value = super(HTMLField, self).clean(value, model_instance)

        if settings.FEINCMS_TIDY_HTML:
            value, errors, warnings = get_object(settings.FEINCMS_TIDY_FUNCTION)(value )

        return value
github matthiask / django-content-editor / feincms / content / application / models.py View on Github external
def process(self, request, **kw):
        page_url = self.parent.get_absolute_url()

        # Provide a way for appcontent items to customize URL processing by
        # altering the perceived path of the page:
        if "path_mapper" in self.app_config:
            path_mapper = get_object(self.app_config["path_mapper"])
            path, page_url = path_mapper(
                request.path,
                page_url,
                appcontent_parameters=self.parameters
            )
        else:
            path = request._feincms_extra_context['extra_path']

        # Resolve the module holding the application urls.
        urlconf_path = self.app_config.get('urls', self.urlconf_path)

        try:
            fn, args, kwargs = resolve(path, urlconf_path)
        except (ValueError, Resolver404):
            raise Resolver404(str('Not found (resolving %r in %r failed)') % (
                path, urlconf_path))