Example #1
0
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.")
Example #2
0
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.")
Example #3
0
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()
Example #4
0
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()
Example #5
0
 def test_validate_url(self, _mock0, _mock1):
     self.assertTrue(validators.validate_url('http://example.org'))