def clean_url(self): original = utils.get_real_url(self.cleaned_data['url']) result = settings.BASEURL + utils.itou(models.get_free_id()) if len(original) <= len(result): logger.error(original) logger.error(result) raise forms.ValidationError("URL is short already") return original
def main(opts): url = utils.get_real_url(opts['<url>'], timeout=5.0) pk = utils.utoi(opts['<short>']) update = opts.get('--update', False) logger.debug(opts) logger.debug(url) logger.debug(pk) try: su = models.URL.objects.get(pk=pk) except models.URL.DoesNotExist: su = models.URL.objects.create(pk=pk) su.url = url su.save() else: if update: su.url = url su.save() else: raise ValueError("Short url '{0}' exists!".format(su))