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
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)
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)
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)
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)
def save_model(self, request, obj, form, change): cache.bust(obj, update=False) super(self.__class__, self).save_model(request, obj, form, change)
def delete(self, *args, **kwargs): super(Commitment, self).delete(*args, **kwargs) cache.bust(self)
def save(self, *args, **kwargs): super(Commitment, self).save(*args, **kwargs) cache.bust(self)
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 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)
def save(self, *args, **kwargs): self.body = strip_tags(self.rich_text_body) super(ContentItem, self).save(*args, **kwargs) cache.bust(self)
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()
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)
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)
def save(self): super(User, self).save() cache.bust(self)
def save(self): self.last_modified = datetime.datetime.utcnow() cache.bust(self) super(TopList, self).save()
def save(self, *args, **kwargs): super(TimelineItem, self).save(*args, **kwargs) cache.bust(self)
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)