Example #1
0
def post_save_callback(sender, instance, **kwargs):
    # Initialize the 'sites' many2many field with the default site
    if hasattr(instance, 'sites') and not instance.sites.all().exists():
        instance.sites.add(Site.objects.get_current())

    maintenance = getattr(settings, 'SUBHUB_MAINTENANCE_AUTO', False)
    # log.debug(u"Post save callback with sender %s and instance %s and AUTO %s" % (unicode(sender), unicode(instance), maintenance))

    if isinstance(instance, StaticURIModel):
        if instance.uri_mode == URI_MODE.IMPORTED:
            # log.debug(u"%s is imported. Nothing to publish, but subscription renew" % instance)
            instance.subscribeToUpdades()
            # TODO check if a subscription is done, either lets do it
        elif isinstance(instance, coop_tag.models.TagBase):
            # Subscription done if it does not exists, in other it is simply renew
            if hasattr(settings, 'THESAURUS_HOST') and \
                    not settings.THESAURUS_HOST == 'http://thess.domain.com':
                instance.subscribeToUpdades(host=settings.THESAURUS_HOST)
        else:
            domain = Site.objects.get_current().domain
            if domain.startswith('http'):
                feed_url = '%s/feed/%s/' % (domain, sender.__name__.lower())
            else:
                feed_url = 'http://%s/feed/%s/' % (domain, sender.__name__.lower())
            try:
                subhub.publish([feed_url], instance.uri, False)
                #log.debug('publish done; Number of Dist task %s' % len(subhub.models.DistributionTask.objects.all()))
            except Exception, e:
                log.warning(u'Unable to publish %s for feed %s : %s' % (instance, feed_url, e))
Example #2
0
    def _notify_hub(self):
        def languages():
            if self.text_ru:
                yield 'ru'
            if self.text_en:
                yield 'en'
            if self.text_ru and self.text_en:
                yield None

        for language in languages():
            topics = [utils.iurl(reverse('marcus-feed'), language)] + \
                     [c.get_feed_url(language) for c in self.categories.all()]
            subhub.publish(
                [utils.absolute_url(t) for t in topics],
                utils.absolute_url(self.get_absolute_url(language)),
            )
Example #3
0
    def _notify_hub(self):
        def languages():
            if self.text_ru:
                yield 'ru'
            if self.text_en:
                yield 'en'
            if self.text_ru and self.text_en:
                yield None

        for language in languages():
            topics = [utils.iurl(reverse('marcus-feed'), language)] + \
                     [c.get_feed_url(language) for c in self.categories.all()]
            subhub.publish(
                [utils.absolute_url(t) for t in topics],
                utils.absolute_url(self.get_absolute_url(language)),
            )
Example #4
0
def post_save_callback(sender, instance, **kwargs):
    log.debug("Post save callback with sender %s and instance %s" % (sender, instance))
    if isinstance(instance, djRdf):
        # log.debug(u"Publish feeds for instance  %s " % instance)
        site = Site.objects.get_current()
        model = sender.__name__.lower()
        feed_url = 'http://%s/feed/%s/' % (site, model)
        feed_url_obj = '%s%s/' % (feed_url, instance.uuid)
        subhub.publish([feed_url, feed_url_obj], instance.uri, False)
    elif isinstance(instance, subhub.models.DistributionTask) and settings.SUBHUB_MAINTENANCE_AUTO:
        try:
            # log.debug("before call ENQUEUE, tasks %s" % len(subhub.models.DistributionTask.objects.all()))
            q.enqueue(letsCallDistributionTaskProcess)
            # log.debug('after call ENQUEUE')
        except Exception, e:
            log.warning(u"%s" % e)
Example #5
0
def post_delete_callback(sender, instance, **kwargs):
    if isinstance(instance, StaticURIModel):
        if instance.uri_mode == URI_MODE.IMPORTED:
            instance.unsubscribeToUpdates()
        if instance.uri_mode == URI_MODE.LOCAL:
            from coop_local.models import DeletedURI
            #peut etre à completer
            model_name = sender.__name__.lower()
            deleted = DeletedURI(uri=instance.uri, modified=datetime.datetime.now(),\
                rdf_type=unicode(instance.rdf_type), uuid=instance.uuid, model_name=model_name)
            deleted.save()
            domain = Site.objects.get_current().domain
            if domain.startswith('http'):
                feed_url = '%s/feed/%s/' % (domain, sender.__name__.lower())
            else:
                feed_url = 'http://%s/feed/%s/' % (domain, sender.__name__.lower())
            try:
                subhub.publish([feed_url], instance.uri, False)
                #log.debug('publish done; Number of Dist task %s' % len(subhub.models.DistributionTask.objects.all()))
            except Exception, e:
                log.warning(u'Unable to publish %s for feed %s : %s' % (instance, feed_url, e))
Example #6
0
 def save(self, **kwargs):
     super(Flag, self).save(**kwargs)
     feeds = [reverse('tag_feed', kwargs={'id': self.tag.id}), 
              reverse('user_feed', kwargs={'username': self.user.username})]
     subhub.publish([f for f in feeds],
                    self.get_absolute_url())