Ejemplo n.º 1
0
    def link(self, model, name='', mounted=None, default=None):
        """Create a link (URL) to a view on a model.

        If no link can be constructed for the model instance, a
        :exc:``morepath.LinkError`` will be raised. ``None`` is treated
        specially: if ``None`` is passed in the default value will be
        returned.

        :param model: the model instance to link to, or ``None``.
        :param name: the name of the view to link to. If omitted, the
          the default view is looked up.
        :param mounted: a :class:`morepath.path.Mount` instance for
          which the view should be looked up. If ommitted, this is the
          current mount.
        :param default: if ``None`` is passed in, the default value will
          be returned. By default this is ``None``.

        """
        if model is None:
            return default
        if mounted is None:
            mounted = self.mounts[-1]
        path, parameters = generic.link(
            self, model, mounted, lookup=mounted.lookup())
        parts = []
        if path:
            parts.append(path)
        if name:
            parts.append(name)
        result = '/' + '/'.join(parts)
        if parameters:
            result += '?' + urllib.urlencode(parameters, True)
        return result
Ejemplo n.º 2
0
    def link(self, model, name=''):
        """Create a link (URL) to a view on a model.

        :param model: the model to link to.
        :param name: the name of the view to link to. If omitted, the
          the default view is looked up.
        """
        result = generic.link(
            self, model, lookup=self.lookup)
        if name:
            result += '/' + name
        return result
Ejemplo n.º 3
0
 def link(self, obj, name="", default=None):
     if obj is None:
         return default
     path, parameters = generic.link(self.request, obj, self.mounted, lookup=self.mounted.lookup)
     parts = []
     if path:
         parts.append(path)
     if name:
         parts.append(name)
     result = "/" + "/".join(parts)
     if parameters:
         result += "?" + urlencode(parameters, True)
     return result
Ejemplo n.º 4
0
    def link(self, model, name='', mounted=None):
        """Create a link (URL) to a view on a model.

        :param model: the model to link to.
        :param name: the name of the view to link to. If omitted, the
          the default view is looked up.
        :param mounted: a :class:`morepath.model.Mount` instance for
          which the view should be looked up. If ommitted, this is the
          current mount.
        """
        if mounted is None:
            mounted = self.mounts[-1]
        result = generic.link(
            self, model, mounted, lookup=mounted.lookup())
        if name:
            result += '/' + name
        return result
Ejemplo n.º 5
0
 def find(app, obj):
     return generic.link(self, obj, app, lookup=app.lookup)
Ejemplo n.º 6
0
 def link(self, model, name=''):
     result = generic.link(self, model, lookup=self.lookup)
     if name:
         result += '/' + name
     return result
Ejemplo n.º 7
0
 def link(self, model, name=''):
     result = generic.link(
         self, model, lookup=self.lookup)
     if name:
         result += '/' + name
     return result