Esempio n. 1
0
File: redis.py Progetto: Pheox/ella
    def _get_score_limits(self):
        max_score = None
        min_score = None

        if self.date_range:
            max_score = repr(to_timestamp(min(self.date_range[1], now())))
            min_score = repr(to_timestamp(self.date_range[0]))
        return min_score, max_score
Esempio n. 2
0
    def _get_score_limits(self):
        max_score = None
        min_score = None

        if self.date_range:
            max_score = repr(to_timestamp(min(self.date_range[1], now())))
            min_score = repr(to_timestamp(self.date_range[0]))
        return min_score, max_score
Esempio n. 3
0
def publishable_published(publishable, **kwargs):
    pipe = client.pipeline()
    for l in publishable.listing_set.all():
        ListingHandlerClass().add_publishable(l.category,
                                              publishable,
                                              repr(to_timestamp(
                                                  l.publish_from)),
                                              pipe=pipe,
                                              commit=False)
    pipe.execute()
Esempio n. 4
0
def publishable_published(publishable, **kwargs):
    pipe = client.pipeline()
    for l in publishable.listing_set.all():
        ListingHandlerClass().add_publishable(
            l.category,
            publishable,
            repr(to_timestamp(l.publish_from)),
            pipe=pipe,
            commit=False
        )
    pipe.execute()
Esempio n. 5
0
    def add_publishable(cls, publishable, pipe=None, commit=True):
        if pipe is None:
            pipe = client.pipeline()

        for k in cls.get_keys(publishable):
            pipe.zadd(k, cls.get_value(publishable), repr(to_timestamp(publishable.publish_from)))

        if commit:
            pipe.execute()
        else:
            return pipe
Esempio n. 6
0
File: redis.py Progetto: Pheox/ella
def listing_post_save(sender, instance, **kwargs):
    pipe = getattr(instance, '__pipe', None)
    if instance.publishable.is_published():
        pipe = RedisListingHandler.add_publishable(
            instance.category,
            instance.publishable,
            repr(to_timestamp(instance.publish_from)),
            pipe=pipe,
            commit=False
        )
    if pipe:
        pipe.execute()
Esempio n. 7
0
File: redis.py Progetto: Pheox/ella
def listing_post_delete(sender, instance, **kwargs):
    # but only delete it if the model delete went through
    pipe = instance.__pipe
    for l in instance.publishable.listing_set.all():
        RedisListingHandler.add_publishable(
            l.category,
            instance.publishable,
            repr(to_timestamp(l.publish_from)),
            pipe=pipe,
            commit=False
        )
    pipe.execute()
Esempio n. 8
0
def serialize_publishable(request, publishable):
    return {
        'id': publishable.id,
        'url': publishable.get_absolute_url(),
        'title': publishable.title,
        'publish_from': to_timestamp(publishable.publish_from) * 1000,
        'content_type': publishable.content_type.name,
        'description': publishable.description,
        'photo': serialize_photo(request, publishable.photo, formats=api_settings.PUBLISHABLE_PHOTO_FORMATS) if publishable.photo_id else None,
        'authors': [serialize_author(request, a) for a in publishable.authors.all()],
        'source': serialize_source(request, publishable.source) if publishable.source_id else None
    }
Esempio n. 9
0
 def add_publishable(cls,
                     category,
                     publishable,
                     score=None,
                     publish_from=None,
                     pipe=None,
                     commit=True):
     if score is None:
         score = repr(to_timestamp(publish_from or now()))
     return super(TimeBasedListingHandler,
                  cls).add_publishable(category,
                                       publishable,
                                       score,
                                       pipe=pipe,
                                       commit=commit)
Esempio n. 10
0
def comment_post_save(instance, **kwargs):
    if hasattr(instance, '__pub_info'):
        is_public = instance.is_public and not instance.is_removed
        was_public = instance.__pub_info['is_public'] and not instance.__pub_info['is_removed']

        # Base queryset for public comments
        public_comments = comments.get_model()._default_manager.filter(
            content_type=instance.content_type_id,
            object_pk=instance.object_pk,
            is_public=True,
            is_removed=False
        )

        # If the comment's "publicity" was modified in any way, update the count key
        if (was_public and not is_public) or (not was_public and is_public):
            client.set(
                COMCOUNT_KEY % (instance.content_type_id, instance.object_pk),
                public_comments.count()
            )
        # If no change to the "publicity" of the comment was made, return
        else:
            return

        # Update the last comment info
        last_keu = LASTCOM_KEY % (instance.content_type_id, instance.object_pk)
        try:
            last_com = public_comments.latest('submit_date')
            client.hmset(last_keu, {
                'submit_date': repr(to_timestamp(last_com.submit_date)),
                'user_id': last_com.user_id or '',
                'username': last_com.user_name,
                'comment': last_com.comment,
                'url': last_com.url,
            })
        except comments.get_model().DoesNotExist:
            client.delete(last_keu)

        # update the listing handlers
        obj = instance.content_object
        if isinstance(obj, Publishable) and obj.is_published():
            publishable_published(obj)
Esempio n. 11
0
def comment_posted(comment, **kwargs):
    count_key = COMCOUNT_KEY % (comment.content_type_id, comment.object_pk)
    last_keu = LASTCOM_KEY % (comment.content_type_id, comment.object_pk)

    pipe = client.pipeline()
    pipe.incr(count_key)
    pipe.hmset(last_keu, {
        'submit_date': repr(to_timestamp(comment.submit_date)),
        'user_id': comment.user_id or '',
        'username': comment.user_name,
        'comment': comment.comment,
        'url': comment.url,
    })

    obj = comment.content_object
    if not isinstance(obj, Publishable) or not obj.is_published():
        pipe.execute()
    elif Listing.objects.get_listing_handler(RECENTLY_COMMENTED_LH, fallback=False):
        Listing.objects.get_listing_handler(RECENTLY_COMMENTED_LH).incr_score(obj.category, obj, pipe=pipe, commit=False)
        pipe.execute()
        publishable_published(obj)
Esempio n. 12
0
File: redis.py Progetto: kvbik/ella
 def add_publishable(cls, category, publishable, score=None, publish_from=None, pipe=None, commit=True):
     if score is None:
         score = repr(to_timestamp(publish_from or now()))
     return super(TimeBasedListingHandler, cls).add_publishable(category, publishable, score, pipe=pipe, commit=commit)