Ejemplo n.º 1
0
    def confirm(cls, message_id):
        message = Message.objects.get(id=message_id)
        # Increment subscriber_emails_sent for the publication by 1 atomically
        # Return the rows affected by the update. Since we've included the "< max_subscriber_emails" condition
        # in the WHERE clause, the update would not change any rows for a campaign that has used up all its e-mails
        affected = Publication.objects.filter(id=message.publication_id, subscriber_emails_sent__lt=F('max_subscriber_emails')).update(subscriber_emails_sent = F('subscriber_emails_sent') + 1)
        if not affected:
            raise NoMessagesRemaining('This publication has no messages remaining')     # Rolls back the transaction
        cache.bust(message.publication)

        message.confirmed=True
        message.save()
        return message
Ejemplo n.º 2
0
def follow(request, user_id):
    followed = get_object_or_404(User, pk=user_id)
    follow_instance, created = UserToUserFollow.objects.get_or_create(follower=request.user, followed=followed)
    if not follow_instance.is_following:
        follow_instance.is_following = True
        follow_instance.save()
    if created:
        send_notification(type=EmailTypes.FOLLOW,
                user=followed, entity=request.user)
    cache.bust(followed)

    if request.is_ajax():
        button = render_inclusiontag(request, "follow_button followed", "users_tags", {'followed': followed})
        return json_response({'button': button})
    else:
        return redirect(followed)
Ejemplo n.º 3
0
def unfollow(request, user_id):
    followed = get_object_or_404(User, pk=user_id)
    try:
        follow_instance = UserToUserFollow.objects.get(follower=request.user, followed=followed)
        follow_instance.is_following = False
        follow_instance.stopped_following = datetime.datetime.now()
        follow_instance.save()
    except UserToUserFollow.DoesNotExist:
        pass
    cache.bust(followed)

    if request.is_ajax():
        button = render_inclusiontag(request, "follow_button followed", "users_tags", {'followed': followed})
        return json_response({'button': button})
    else:
        return redirect(followed)
Ejemplo n.º 4
0
def unfollow(request, user_id):
    followed = get_object_or_404(User, pk=user_id)
    try:
        follow_instance = UserToUserFollow.objects.get(follower=request.user,
                                                       followed=followed)
        follow_instance.is_following = False
        follow_instance.stopped_following = datetime.datetime.now()
        follow_instance.save()
    except UserToUserFollow.DoesNotExist:
        pass
    cache.bust(followed)

    if request.is_ajax():
        button = render_inclusiontag(request, "follow_button followed",
                                     "users_tags", {'followed': followed})
        return json_response({'button': button})
    else:
        return redirect(followed)
Ejemplo n.º 5
0
def follow(request, user_id):
    followed = get_object_or_404(User, pk=user_id)
    follow_instance, created = UserToUserFollow.objects.get_or_create(
        follower=request.user, followed=followed)
    if not follow_instance.is_following:
        follow_instance.is_following = True
        follow_instance.save()
    if created:
        send_notification(type=EmailTypes.FOLLOW,
                          user=followed,
                          entity=request.user)
    cache.bust(followed)

    if request.is_ajax():
        button = render_inclusiontag(request, "follow_button followed",
                                     "users_tags", {'followed': followed})
        return json_response({'button': button})
    else:
        return redirect(followed)
Ejemplo n.º 6
0
    def save(self):
        #Note: I want to move all this img stuff to the forms that set them...
        #not here on the model. This is a hack so we ensure the model id is
        #used in the filename.
        if not self.id and not self.img_url._committed:
            #most likely you need to watch small img too
            thumbnail_url_comm = self.img_url._committed
            self.img_url._committed = True
            self.thumbnail_url._committed = True
            super(MediaItem, self).save()
            self.img_url._committed = False
            self.thumbnail_url._committed = thumbnail_url_comm

        if not self.id and not self.thumbnail_url._committed:
            self.thumbnail_url._committed = True
            super(MediaItem, self).save()
            self.thumbnail_url._committed = False

        self.img_url.storage.inst_id = self.id
        self.thumbnail_url.storage.inst_id = self.id
        super(MediaItem, self).save()
        cache.bust(self)
Ejemplo n.º 7
0
    def save(self):
        #Note: I want to move all this img stuff to the forms that set them...
        #not here on the model. This is a hack so we ensure the model id is
        #used in the filename.
        if not self.id and not self.img_url._committed:
            #most likely you need to watch small img too
            thumbnail_url_comm = self.img_url._committed
            self.img_url._committed = True
            self.thumbnail_url._committed = True
            super(MediaItem, self).save()
            self.img_url._committed = False
            self.thumbnail_url._committed = thumbnail_url_comm

        if not self.id and not self.thumbnail_url._committed:
            self.thumbnail_url._committed = True
            super(MediaItem, self).save()
            self.thumbnail_url._committed = False

        self.img_url.storage.inst_id = self.id
        self.thumbnail_url.storage.inst_id = self.id
        super(MediaItem, self).save()
        cache.bust(self)
Ejemplo n.º 8
0
 def save_model(self, request, obj, form, change):
     cache.bust(obj, update=False)
     super(self.__class__, self).save_model(request, obj, form, change)
Ejemplo n.º 9
0
 def delete(self, *args, **kwargs):
     super(Commitment, self).delete(*args, **kwargs)
     cache.bust(self)
Ejemplo n.º 10
0
 def save(self, *args, **kwargs):
     super(Commitment, self).save(*args, **kwargs)
     cache.bust(self)
Ejemplo n.º 11
0
                    f.stopped_following = datetime.now()
                f.save()
                request.user.refresh_users_following()
                ent.refresh_followers()
                if created:
                    #FeedStream.post_new_follow(request.user, ent)
                    send_notification(type=EmailTypes.FOLLOW,
                                      user=ent,
                                      entity=request.user)
            except Exception, inst:
                log(inst)

        if not ent:
            continue
        else:
            cache.bust(ent)

    return json_response({'result': 1})


@AccountRequired
@PostOnly
def remove_user(request):
    request.user.is_active = False
    request.user.save()
    cache.bust_on_handle(request.user, request.user.username)
    logout(request)
    return unset_auth_cookies(json_response({'result': 1}))


@PostOnly
Ejemplo n.º 12
0
 def get(cls, id, force_db=False):
     if force_db:
         top_list = TopList.objects.get(id=id)
         cache.bust(top_list)
         return top_list
     return cache.get(cls, id)
Ejemplo n.º 13
0
 def delete(self, *args, **kwargs):
     super(Commitment, self).delete(*args, **kwargs)
     cache.bust(self)
Ejemplo n.º 14
0
 def save(self, *args, **kwargs):
     self.body = strip_tags(self.rich_text_body)
     super(ContentItem, self).save(*args, **kwargs)
     cache.bust(self)
Ejemplo n.º 15
0
                    f.stopped_following = datetime.now()
                f.save()
                request.user.refresh_users_following()
                ent.refresh_followers()
                if created:
                    #FeedStream.post_new_follow(request.user, ent)
                    send_notification(type=EmailTypes.FOLLOW,
                                      user=ent,
                                      entity=request.user)
            except Exception, inst:
                log(inst)

        if not ent:
            continue
        else:
            cache.bust(ent)

    return json_response({'result' : 1})

@AccountRequired
@PostOnly
def remove_user(request):
    request.user.is_active = False
    request.user.save()
    cache.bust_on_handle(request.user, request.user.username)
    logout(request)
    return unset_auth_cookies(json_response({'result':1}))

@PostOnly
def forgot_password(request):
    email = request.POST['email'].strip()
Ejemplo n.º 16
0
 def get(cls, id, force_db=False):
     if force_db:
         obj = cls.objects.get(id=id)
         cache.bust(obj)
         return obj
     return cache.get(cls, id)
Ejemplo n.º 17
0
 def save(self, *args, **kwargs):
     self.body = strip_tags(self.rich_text_body)
     super(ContentItem, self).save(*args, **kwargs)
     cache.bust(self)
Ejemplo n.º 18
0
 def get(cls, id, force_db=False):
     if force_db:
         issue = Issue.objects.get(id=id)
         cache.bust(issue)
         return issue
     return cache.get(cls, id)
Ejemplo n.º 19
0
 def save(self):
     super(User, self).save()
     cache.bust(self)
Ejemplo n.º 20
0
 def save(self):
     self.last_modified = datetime.datetime.utcnow()
     cache.bust(self)
     super(TopList, self).save()
Ejemplo n.º 21
0
 def save(self, *args, **kwargs):
     super(TimelineItem, self).save(*args, **kwargs)
     cache.bust(self)
Ejemplo n.º 22
0
 def get(cls, id, force_db=False):
     if force_db:
         top_list = TopList.objects.get(id=id)
         cache.bust(top_list)
         return top_list
     return cache.get(cls, id)
Ejemplo n.º 23
0
 def save_model(self, request, obj, form, change):
     cache.bust(obj, update=False)
     super(self.__class__, self).save_model(request, obj, form, change)
Ejemplo n.º 24
0
 def save(self, *args, **kwargs):
     super(Commitment, self).save(*args, **kwargs)
     cache.bust(self)
Ejemplo n.º 25
0
 def save(self):
     super(User, self).save()
     cache.bust(self)
Ejemplo n.º 26
0
 def save(self):
     self.last_modified = datetime.datetime.utcnow()
     cache.bust(self)
     super(TopList, self).save()
Ejemplo n.º 27
0
 def get(cls, id, force_db=False):
     if force_db:
         org = User.objects.get(id=id)
         cache.bust(org)
         return org
     return cache.get(cls, id)
Ejemplo n.º 28
0
 def save(self, *args, **kwargs):
     super(TimelineItem, self).save(*args, **kwargs)
     cache.bust(self)
Ejemplo n.º 29
0
 def get(cls, id, force_db=False):
     if force_db:
         org = User.objects.get(id=id)
         cache.bust(org)
         return org
     return cache.get(cls, id)