def update_title(sender, instance, **kwargs): """ Update title of FeedSubscription for pre_save. Arguments: sender: model (FeedSubscription) instance: FeedSubscription instance **kwargs: not use """ if validators.validate_url(instance.url): instance.name = FeedParser(instance.url).title else: raise ValueError("Cannot insert and updating in model saving.")
def retrieve_title(sender, instance, **kwargs): """ Retreive title of specified url. Arguments: sender: :model (Bookmark) instance: Bookmark instance **kwargs: not use """ if instance.title: return instance.title else: if validators.validate_url(instance.url): data = PyQuery(instance.url) instance.title = data('head title').text()
def test_validate_url(self, _mock0, _mock1): self.assertTrue(validators.validate_url('http://example.org'))