Example #1
0
    def render(self, context):
        request = context['request']

        # get the full URL for the current page
        url = request.build_absolute_uri()

        # see if it's worth shortening this URL
        path = request.path.strip('/')
        next_shortcut = gen_shortcut(IttyBittyURL.objects.count() + 1)

        # if we have a shortcut that matches the path, we shouldn't make an Itty Bitty URL
        if IttyBittyURL.objects.filter(shortcut__exact=path).count() or \
            len(path) <= len(next_shortcut):
            # it's shorter than the generated shortcut would be... don't store
            # the object and just use the URL itself
            ittybitty = IttyBittyURL(url=url, shortcut=path)
        else:
            # get the Itty Bitty URL object for this URL, and create one if one
            # doesn't already exist
            ittybitty, created = IttyBittyURL.objects.get_or_create(url=url)

        if self.varname:
            # if the user specified a varname, inject the object into the context
            context[self.varname] = ittybitty
            return ''
        else:
            # if no varname given, just spit the shortcut URL into the template
            return ittybitty.get_shortcut()
Example #2
0
    def render(self, context):
        request = context["request"]

        # get the full URL for the current page
        url = request.build_absolute_uri()

        # see if it's worth shortening this URL
        path = request.path.strip("/")
        next_shortcut = gen_shortcut(IttyBittyURL.objects.count() + 1)

        # if we have a shortcut that matches the path, we shouldn't make an Itty Bitty URL
        if IttyBittyURL.objects.filter(shortcut__exact=path).count() or len(path) <= len(next_shortcut):
            # it's shorter than the generated shortcut would be... don't store
            # the object and just use the URL itself
            ittybitty = IttyBittyURL(url=url, shortcut=path)
        else:
            # get the Itty Bitty URL object for this URL, and create one if one
            # doesn't already exist
            ittybitty, created = IttyBittyURL.objects.get_or_create(url=url)

        if self.varname:
            # if the user specified a varname, inject the object into the context
            context[self.varname] = ittybitty
            return ""
        else:
            # if no varname given, just spit the shortcut URL into the template
            return ittybitty.get_shortcut()
Example #3
0
    def save(self, *args, **kwargs):
        self.sef_title = unidecode(self.title)
        super(Sources, self).save(*args, **kwargs)

        self.sef_description = unidecode(self.description)
        super(Sources, self).save(*args, **kwargs)

        p = IttyBittyURL(url=self.link)
        p.save()
        self.link = p.get_shortcut()
        super(Sources, self).save(*args, **kwargs)
Example #4
0
    def save(self, *args, **kwargs):
        self.sef_title = unidecode(self.title)
        super(Sources, self).save(*args, **kwargs)

        self.sef_description = unidecode(self.description)
        super(Sources, self).save(*args, **kwargs)

        p = IttyBittyURL(url=self.link)
        p.save()
        self.link = p.get_shortcut()
        super(Sources, self).save(*args, **kwargs)