Exemplo n.º 1
0
    def test_config_nosub(self, client):
        """ instance has config, no subcontent """
        class T1(ModellessSpoke):
            implicit_add = False

        class T2(ModellessSpoke):
            explicit_children = (T1, )

        type_registry.register(T1)
        type_registry.register(T2)

        assert T2(DummyContent(allowed="")).allowed_spokes() == ()
Exemplo n.º 2
0
    def test_non_implicit_but_children(self, client):
        """ T1 cannot be added explicitly but is in T2's children """
        class T1(ModellessSpoke):
            implicit_add = False

        class T2(ModellessSpoke):
            children = (T1, )

        type_registry.register(T1)
        type_registry.register(T2)

        assert T1 in T2(DummyContent()).allowed_spokes()
Exemplo n.º 3
0
    def test_explicit(self, client):
        """ Simple case, no restrictions """
        class T1(ModellessSpoke):
            implicit_add = True  ## default

        class T2(ModellessSpoke):
            children = None

        type_registry.register(T1)
        type_registry.register(T2)

        assert T1 in T2(DummyContent()).allowed_spokes()
Exemplo n.º 4
0
            def content(self):
                class DummyType(Spoke):
                    model = DummyContent
                    children = ()
                    add_to_index = False

                    @classmethod
                    def name(cls):
                        return DummyContent.get_name()

                type_registry.register(DummyType)

                return DummyContent()
Exemplo n.º 5
0
            def content(self):
                class DummyType(Spoke):
                    model = DummyContent
                    children = (Type1Type, Type2Type)
                    primary = Type1Type
                    add_to_index = False

                    @classmethod
                    def name(cls):
                        return cls.model.get_name()

                type_registry.register(DummyType)

                return DummyContent()
Exemplo n.º 6
0
    def test_config_simpleconf(self, client):
        """ instance overrides default. In stead of all implicit content,
            only allow T1 """
        class T1(ModellessSpoke):
            implicit_add = False

        class T2(ModellessSpoke):
            explicit_children = None

        type_registry.register(T1)
        type_registry.register(T2)

        assert T1 in T2(DummyContent(allowed="t1")).allowed_spokes()
        assert T2 not in T2(DummyContent(allowed="t1")).allowed_spokes()
Exemplo n.º 7
0
    def test_config_spoke_allowed(self, client):
        """ Use the allowed() method on spokes """
        class T1(ModellessSpoke):
            implicit_add = False

        class T2(ModellessSpoke):
            explicit_children = None

        type_registry.register(T1)
        type_registry.register(T2)

        t = T1(DummyContent())
        t.allow_spokes((T1, T2))

        assert T1 in t.allowed_spokes()
        assert T2 in t.allowed_spokes()
Exemplo n.º 8
0
    def test_no_implicit_unattached(self, client):
        """ An unattached node cannot restrict its children but
            should still not allow creation of non-implicit_add
            types """


        class DummyType(Spoke):
            model = DummyContent
            children = ()
            implicit_add = False
            add_to_index = False

            @classmethod
            def title(cls):
                return ''

        type_registry.register(DummyType)


        node = Node.root()
        toolbar = Toolbar(node, superuser_request("/"), "view")
        for c in toolbar.children():
            assert c['name'] != DummyType.name()
Exemplo n.º 9
0
class News(NewsBase):
    pass

class NewsForm(formfactory(News)):
    body = forms.CharField(widget=TinyMCE(), required=False)

class NewsType(Spoke):
    model = News
    form = NewsForm

    title = "A simple News item"

    type_icon = icon = "news.png"

    def index_description(self):
        """ truncate body text if no explicit description available """
        return self.description()

    def description(self):
        """ truncate body text if no explicit description available """
        if self.instance.intro:
            return self.instance.intro

        if self.instance.description:
            return self.instance.description

        return Truncator(strip_tags(self.instance.body)).words(50,
                         truncate=" ...")
template_registry.register(NewsType, "wheelcms_spokes/news_view.html", "Basic News view", default=True)
type_registry.register(NewsType)
Exemplo n.º 10
0
    m2m = models.ManyToManyField("self")


class TypeM2MType(Spoke):
    model = TypeM2M


class TypeUnique(Content):
    uniek = models.TextField(unique=True)


class TypeUniqueType(Spoke):
    model = TypeUnique


type_registry.register(Type1Type)
type_registry.register(Type2Type)
type_registry.register(TestFileType)
type_registry.register(TestImageType)
type_registry.register(OtherTestFileType)
type_registry.register(OtherTestImageType)
type_registry.register(TypeM2MType)
type_registry.register(TypeUniqueType)

from wheelcms_axle.content import TypeRegistry


class TestTypeRegistry(TypeRegistry):
    """
        A type registry without HayStack registration
    """
Exemplo n.º 11
0

class CommentType(Spoke):
    implicit_add = False   # can't create through frontend directly
    add_to_index = False   # do not index in search
    discussable = False    # well...

    model = Comment
    form = formfactory(Comment)

    title = "A comment"
    # type_icon = icon = ..

template_registry.register(CommentType, "wheelcms_comments/comment_view.html", _("Comment View"), default=True)

type_registry.register(CommentType)

class Configuration(models.Model):
    main = models.ForeignKey(BaseConfiguration, related_name="comments")
    enabled = models.BooleanField(default=True)
    notify_address = models.EmailField(blank=True)

class ConfigurationForm(forms.ModelForm):
    class Meta:
        model = Configuration
        exclude = ['main']

configuration_registry.register("comments", "Comments", Configuration, ConfigurationForm)


from wheelcms_axle.actions import action_registry
Exemplo n.º 12
0
        class PageIndex(indexfactory(cls)):
            description = SpokeCharField(spoke=cls,
                                         stored=True, indexed=False,
                                         model_attr="index_description")

        return PageIndex

    def context(self, handler, request, node):
        ctx = super(PageType, self).context(handler, request, node)
        wpm = 180  # avg adult for monitor
        # XXX NOTTESTED
        ctx['reading_minutes'] = (len(strip_tags(self.instance.body).split())/wpm) + 1
        return ctx

def contentlisting_context(handler, request, node):
    language = get_active_language()

    q = node_proxy_factory(Node, language).objects.children(node).filter(contentbase__language=language).order_by("position")

    if not access.has_access(request.user, node):
        q = q.public()

    return dict(contents=q)

type_registry.register(PageType)
template_registry.register(PageType, "wheelcms_spokes/page_view.html",
                           "Basic Page view", default=True)
template_registry.register(PageType, "wheelcms_spokes/page_contents.html",
                           "Contents Listing", default=False,
                           context=contentlisting_context)
Exemplo n.º 13
0
        ctx = super(ValveBlogType, self).context(handler, request, node)
        ctx.update(blog_context(handler, request, node))

        return ctx

    def feed(self):
        ## XXX Use content object manager once available
        return ValveEntry.objects.filter(
                 node__tree_path__startswith=self.instance.node.tree_path,
                 state="published",
                 language=self.instance.language).order_by("-created")

def global_blog_context(handler, request, node):
    ctx = blog_context(handler, request, node)
    ctx['all_blogs'] = ValveBlog.objects.filter(state="published")
    ctx['global_context'] = True

    return ctx

type_registry.register(ValveBlogType)
template_registry.register(ValveBlogType, "wheelcms_valve/valveblog_view.html",
                           "Blog view", default=True)
type_registry.register(ValveEntryType)
template_registry.register(ValveEntryType, "wheelcms_valve/valveentry_view.html",
                           "Blog entry view", default=True)

template_registry.register(PageType, "wheelcms_valve/valveblog_view.html",
                           "Blog view", default=False,
                           context=global_blog_context)