Example #1
0
    def save(self, *args, **kwargs):
        """
        Before saving do the following:
        - Clean the url before saving
        - Fill in the name
        """

        # You can't timetravel into the future
        if self.used and self.used > timezone.now():
            self.used = timezone.now()

        if not self.url:
            raise ValueError("url field must be set")

        if not ("http://" in self.url or "https://" in self.url):
            self.url = "http://" + self.url

        # Note this may raise urllib2.URLException
        # if so, use the existing title
        try:
            self.title = tools.link_title(self.url)
        except urllib2.URLError:
            pass

        if tools.is_youtube(self.url):
            self.url = tools.youtube_url_cleaner(self.url)
            self.title = tools.youtube_clean_title(self.title)
        elif tools.is_vimeo(self.url):
            self.url = tools.vimeo_url_cleaner(self.url)
            self.title = tools.vimeo_clean_title(self.title)

        super(Video, self).save(*args, **kwargs)
Example #2
0
 def save(self, *args, **kwargs):
     if self.title == "" or self.title == self.url:
         self.title = tools.link_title(self.url)
     super(Media, self).save(*args, **kwargs)