Exemple #1
0
    def get_content(self):
        """Return the actual content.

        If this is a ForeignKey, the model instance it points at will be returned.
        Otherwise, the content itself is returned as a string.
        """
        if self.typ == "fk":
            if not self.content:
                return None

            options = stemplates.get_field(self.page.template, self.title)[2]

            app_label = options.get("app", "tinycms")
            model_name = options.get("model", "Page")
            model = get_model(app_label, model_name)

            try:
                return model.objects.get(id=self.content)
            except model.DoesNotExist:
                return None
        elif self.typ == "bool":
            try:
                result = True if int(self.content) else False
            except ValueError:
                result = True
            return result
        elif self.typ in ["file", "img"]:
            from filebrowser.base import FileObject
            from django.conf import settings
            import os

            return FileObject(os.path.join(settings.MEDIA_ROOT, self.content))
        else:
            return self.content
Exemple #2
0
    def get_content(self):
        """Return the actual content.

        If this is a ForeignKey, the model instance it points at will be returned.
        Otherwise, the content itself is returned as a string.
        """
        if self.typ == 'fk':
            if not self.content:
                return None

            options = stemplates.get_field(self.page.template, self.title)[2]

            app_label = options.get('app', 'stoat')
            model_name = options.get('model', 'Page')
            model = get_model(app_label, model_name)

            try:
                return model.objects.get(id=self.content)
            except model.DoesNotExist:
                return None
        elif self.typ == 'bool':
            return True if int(self.content) else False
        else:
            return self.content
Exemple #3
0
    def get_content(self):
        """Return the actual content.

        If this is a ForeignKey, the model instance it points at will be returned.
        Otherwise, the content itself is returned as a string.
        """
        if self.typ == 'fk':
            if not self.content:
                return None

            options = stemplates.get_field(self.page.template, self.title)[2]

            app_label = options.get('app', 'stoat')
            model_name = options.get('model', 'Page')
            model = get_model(app_label, model_name)

            try:
                return model.objects.get(id=self.content)
            except model.DoesNotExist:
                return None
        elif self.typ == 'bool':
            return True if int(self.content) else False
        else:
            return self.content