def render(self, context): try: obj = self.obj.resolve(context) except template.VariableDoesNotExist: return '' try: prefix = self.get_prefix(obj) except (AttributeError, KeyError): return '' tinyid = converter.from_decimal(obj.pk) if hasattr(settings, 'SHORT_BASE_URL') and settings.SHORT_BASE_URL: short_url = urlparse.urljoin(settings.SHORT_BASE_URL, prefix + tinyid) if self.varname: context[self.varname] = short_url return '' else: return short_url try: short_url = urlresolvers.reverse('shorturls:redirect', kwargs={ 'prefix': prefix, 'tiny': tinyid }) if self.varname: context[self.varname] = short_url return '' else: return short_url except urlresolvers.NoReverseMatch: return ''
def render(self, context): try: obj = self.obj.resolve(context) except template.VariableDoesNotExist: return '' if isinstance(obj, six.string_types): obj, _created = Link.objects.get_or_create(url=obj) try: prefix = self.get_prefix(obj) except (AttributeError, KeyError): return '' tinyid = converter.from_decimal(obj.pk) if hasattr(settings, 'SHORT_BASE_URL') and settings.SHORT_BASE_URL: return urljoin(settings.SHORT_BASE_URL, prefix + tinyid) try: return reverse(views.redirect, kwargs={ 'prefix': prefix, 'tiny': tinyid }) except NoReverseMatch: return ''
def shorturl(obj): try: prefix = _get_prefix(obj) except (AttributeError, KeyError): return '' tinyid = converter.from_decimal(obj.pk) if hasattr(settings, 'SHORT_BASE_URL') and settings.SHORT_BASE_URL: return urlparse.urljoin(settings.SHORT_BASE_URL, prefix + tinyid) try: return urlresolvers.reverse('shorturls.views.redirect', kwargs = { 'prefix': prefix, 'tiny': tinyid }) except urlresolvers.NoReverseMatch: return ''
def get_short_url(self): try: prefix = self.get_prefix() except (AttributeError, KeyError): return '' tinyid = converter.from_decimal(self.pk) if hasattr(settings, 'SHORT_BASE_URL') and settings.SHORT_BASE_URL: return urlparse.urljoin(settings.SHORT_BASE_URL, prefix + tinyid) try: return urlresolvers.reverse('shorturls.views.redirect', kwargs={ 'prefix': prefix, 'tiny': tinyid }) except urlresolvers.NoReverseMatch: if hasattr(self, 'get_absolute_url'): return self.get_absolute_url() else: return None
def render(self, context): try: obj = self.obj.resolve(context) except template.VariableDoesNotExist: return '' try: prefix = self.get_prefix(obj) except (AttributeError, KeyError): return '' tinyid = converter.from_decimal(obj.pk) if hasattr(settings, 'SHORT_BASE_URL') and settings.SHORT_BASE_URL: return urlparse.urljoin(settings.SHORT_BASE_URL, prefix+tinyid) try: return urlresolvers.reverse('shorturls.views.redirect', kwargs = { 'prefix': prefix, 'tiny': tinyid }) except urlresolvers.NoReverseMatch: return ''
def render(self, context): try: obj = self.obj.resolve(context) except template.VariableDoesNotExist: return '' try: prefix = self.get_prefix(obj) except (AttributeError, KeyError): return '' tinyid = converter.from_decimal(obj.pk) if hasattr(settings, 'SHORT_BASE_URL') and settings.SHORT_BASE_URL: return urljoin(settings.SHORT_BASE_URL, prefix + tinyid) try: return urlresolvers.reverse(views.redirect, kwargs={ 'prefix': prefix, 'tiny': tinyid }) except urlresolvers.NoReverseMatch: return ''