Ejemplo n.º 1
0
    def get_context_data(self, **kwargs):

        ctx = super(LikersForObject, self).get_context_data(**kwargs)
        try:
            ctx['object'] = urn_to_object(self.request.GET['uri'])
        except:
            ctx['object'] = urn_to_object(self.request.POST['uri'])

        return ctx
Ejemplo n.º 2
0
    def form_valid(self, form):
        """
        If the form is invalid, re-render the context data with the
        data-filled form and errors.
        """
        self.object = urn_to_object(form.data.get('uri'))

        return self.render_to_response(self.get_context_data(form=form))
Ejemplo n.º 3
0
    def form_valid(self, form):
        """
        If the form is invalid, re-render the context data with the
        data-filled form and errors.
        """
        self.object = urn_to_object(form.data.get('uri'))

        return self.render_to_response(self.get_context_data(form=form))
Ejemplo n.º 4
0
    def url(self):

        """ If the URI is an URN, resolve to actual object url,
        otherwise leave it. If the object is not found, the url is
        return as '' """

        url = ""

        if self.uri.startswith("urn:"):
            obj = urn_to_object(self.uri)

            if obj:
                url = obj.get_absolute_url()
        else:
            url = self.uri    

        return url
Ejemplo n.º 5
0
def link_as_a(link):

    ctx = {}

    _link = link.split("::")[0]

    if _link.startswith("urn"):

        obj = urn_to_object(_link)

        ctx['url'] = obj.get_absolute_url()
        ctx['title'] = obj.title
    else:
        ctx['url'] = ctx['title'] = _link

    if "::" in link:
        ctx['target'] = link.split("::")[1] or ""
    else:
        ctx['target'] = ""

    return ctx
Ejemplo n.º 6
0
    def render(self, name, value, attrs=None):

        lexval = ""

        if value:
            url = value.split("::")[0]

            if url.startswith("urn"):
                lexval = urn_to_object(url).title
            else:
                lexval = url or ""

        context = {'name': name,
                   'lexical_value': lexval,
                   'value': value or "",
                   }

        html = render_to_string('djinn_forms/snippets/link_widget.html',
                                context)

        return mark_safe(u"".join(html))
Ejemplo n.º 7
0
    def render(self, name, value, attrs=None):

        lexval = ""

        if value:
            url = value.split("::")[0]

            if url.startswith("urn"):
                lexval = urn_to_object(url).title
            else:
                lexval = url or ""

        context = {
            'name': name,
            'lexical_value': lexval,
            'value': value or "",
        }

        html = render_to_string('djinn_forms/snippets/link_widget.html',
                                context)

        return mark_safe(u"".join(html))
Ejemplo n.º 8
0
    def test_urn_to_object(self):

        self.assertEquals(
            self.obj,
            urn_to_object("urn:pu.in:pgcontent:article:%s" % self.obj.id))
Ejemplo n.º 9
0
    def test_urn_to_object(self):

        self.assertEquals(
            self.obj,
            urn_to_object("urn:pu.in:pgcontent:article:%s" % self.obj.id))
Ejemplo n.º 10
0
    def get_context_data(self, **kwargs):

        ctx = super(LikersForObject, self).get_context_data(**kwargs)
        ctx['object'] =  urn_to_object(self.request.REQUEST['uri'])

        return ctx
Ejemplo n.º 11
0
    def convert_item(self, item):

        return urn_to_object(item)