Example #1
0
"""
This should fail because you can not use path separator in templatedir directive.
"""
import grokcore.view as grok
import os.path

grok.templatedir('templatedirectoryname' + os.path.sep + 'subdirname')
Example #2
0
"""
You can explicitly specify the template directory using grok.templatedir on module level:

  >>> grok.testing.grok(__name__)

  >>> manfred = Mammoth()
  >>> from zope.publisher.browser import TestRequest
  >>> request = TestRequest()
  >>> from zope import component
  >>> view = component.getMultiAdapter((manfred, request), name='food')
  >>> print(view())
  <html>
  <body>
  ME GROK EAT MAMMOTH!
  </body>
  </html>

"""
import grokcore.view as grok

grok.templatedir('templatedirectoryname')


class Mammoth(grok.Context):
    pass


class Food(grok.View):
    pass
Example #3
0
  >>> from grokcore.view.testing import warn
  >>> import warnings
  >>> saved_warn = warnings.warn
  >>> warnings.warn = warn

  >>> import shared_template_dir_fixture

  >>> grok.testing.grok(__name__)
  From grok.testing's warn():
  ...UserWarning: Found the following unassociated template(s) when grokking
  'grokcore.view.tests.view.shared_template_dir': food, unassociated.  Define view classes inheriting from
  grok.View to enable the template(s)...

  >>> grok.testing.grok(shared_template_dir_fixture.__name__)
  From grok.testing's warn():
  ...UserWarning: Found the following unassociated template(s) when grokking
  'grokcore.view.tests.view.shared_template_dir_fixture': cavepainting, unassociated.  Define view classes inheriting from
  grok.View to enable the template(s)...

"""
import grokcore.view as grok


grok.templatedir("shared_templates")

class Mammoth(grok.Context):
    pass

class CavePainting(grok.View):
    pass
"""
A content provider is not allowed to define its own render method and
have a template associated with it at the same time.

  >>> grok.testing.grok(__name__)
  Traceback (most recent call last):
   ...
  ConfigurationExecutionError: martian.error.GrokError: Multiple possible ways
  to render contentprovider <class 'grokcore.view.tests.contentprovider.contentprovider_render_and_template.ContentProvider'>.
  It has both a 'render' method as well as an associated template.
  in:

"""

from zope.interface import Interface
import grokcore.view as grok

grok.templatedir('render_and_template_templates')

class ContentProvider(grok.ContentProvider):
    grok.name('foo')
    grok.context(Interface)
    grok.template('contentprovider')

    def render(self):
        """There's also a template!
        """
Example #5
0
"""
You can explicitly specify the template directory using grok.templatedir on module level:

  >>> grok.testing.grok(__name__)

  >>> manfred = Mammoth()
  >>> from zope.publisher.browser import TestRequest
  >>> request = TestRequest()
  >>> from zope import component
  >>> view = component.getMultiAdapter((manfred, request), name='food')
  >>> print view()
  <html>
  <body>
  ME GROK EAT MAMMOTH!
  </body>
  </html>

"""
import grokcore.view as grok

grok.templatedir('templatedirectoryname')

class Mammoth(grok.Context):
    pass

class Food(grok.View):
    pass
Example #6
0
  http://127.0.0.1

  >>> form = getMultiAdapter((helmut, request), name='form')
  >>> form
  <megrok.layout.tests.models.url.BearForm object at ...>

  >>> print form.application_url()
  http://127.0.0.1

"""

import grokcore.view as grok
from megrok.layout import Page, Layout, Form
from zope.interface import Interface, implements

grok.templatedir("templates")


class IBear(Interface):
    pass


class Panda(grok.Context):
    implements(IBear)


class Master(Layout):
    grok.context(IBear)


class BearForm(Form):
import grokcore.view as grok

grok.templatedir('idontexit')


class Mammoth(grok.Context):
    pass


class Food(grok.View):
    pass
import grokcore.view as grok

grok.templatedir('idontexit')

class Mammoth(grok.Context):
    pass

class Food(grok.View):
    pass
Example #9
0
"""
This should issue a UserWarning.
"""
import grokcore.view as grok
from first_module import Mammoth

grok.templatedir("templates")

class Food(grok.View):
    grok.context(Mammoth)

Example #10
0
import grokcore.view as grok
from grokcore.view.tests.view.cross_package_fixture.zbase import BaseView

grok.templatedir('more_templates')


class MoreSubView(BaseView):
    pass


class MoreSubViewOverrideTemplate(BaseView):
    grok.template('moretemplate')
Example #11
0
# -*- coding: utf-8 -*-

from grokcore import view as grok
from megrok import pagetemplate as pt
from zeam.form.base import form

grok.templatedir('default_templates')


class FormTemplate(pt.PageTemplate):
    pt.view(form.Form)
"""
This should fail because you can not use path separator in templatedir directive.
"""
import grokcore.view as grok
import os.path

grok.templatedir("templatedirectoryname" + os.path.sep + "subdirname")
Example #13
0
# -*- coding: utf-8 -*-

import grokcore.view as grok
from dolmen.file import IImageField
from dolmen.widget.file import (
    FileWidget, DisplayFileWidget, IFileWidget, FileSchemaField)
from zeam.form.base.interfaces import IFormData
from zeam.form.ztk.fields import registerSchemaField
from zope.interface import Interface

grok.templatedir('templates')


def register():
    """Entry point hook.
    """
    registerSchemaField(ImageSchemaField, IImageField)


class IImageWidget(IFileWidget):
    """A widget that represents a file.
    """


class ImageSchemaField(FileSchemaField):
    """An image field.
    """


class ImageWidget(FileWidget):
    """A widget for a named file object. It handles specificly an
Example #14
0
        class="edit-form" enctype="multipart/form-data">
     ...<span>Color</span>...
     ... value="globally dark" ...
     ... value="Apply" ...
  </form>


"""
import grokcore.component as grok

from grokcore.view import templatedir
from megrok.layout import Layout, DisplayForm, EditForm
from zope import interface, schema


templatedir('templates')


class ICowProperties(interface.Interface):
    color = schema.TextLine(title=u"Color")


class Cow(grok.Context):
    grok.implements(ICowProperties)
    color = u"globally dark"


class Master(Layout):
    grok.name('master')
    grok.context(Cow)
Example #15
0
import grokcore.view as grok
from grokcore.view.tests.view.cross_package_fixture.zbase import BaseView

grok.templatedir('more_templates')

class MoreSubView(BaseView):
    pass

class MoreSubViewOverrideTemplate(BaseView):
    grok.template('moretemplate')
Example #16
0
        class="edit-form" enctype="multipart/form-data">
     ...<span>Color</span>...
     ... value="globally dark" ...
     ... value="Apply" ...
  </form>


"""
import grokcore.component as grok

from grokcore.view import templatedir
from grok import Layout, DisplayFormPage, EditFormPage, FormPage
from zope import interface, schema


templatedir('templates')


class ICowProperties(interface.Interface):
    color = schema.TextLine(title=u"Color")


@grok.implementer(ICowProperties)
class Cow(grok.Context):
    color = u"globally dark"


class Master(Layout):
    grok.name('master')
    grok.context(Cow)
"""
A content provider is not allowed to define its own render method and
have a template associated with it at the same time.

  >>> grok.testing.grok(__name__)
  Traceback (most recent call last):
   ...
  ConfigurationExecutionError: martian.error.GrokError: Multiple possible ways
  to render contentprovider <class 'grokcore.view.tests.contentprovider.contentprovider_render_and_template.ContentProvider'>.
  It has both a 'render' method as well as an associated template.
  in:

"""

from zope.interface import Interface
import grokcore.view as grok

grok.templatedir('render_and_template_templates')


class ContentProvider(grok.ContentProvider):
    grok.name('foo')
    grok.context(Interface)
    grok.template('contentprovider')

    def render(self):
        """There's also a template!
        """