def update_basket(sender, instance, **kwargs): newsletters = [settings.BASKET_VOUCHED_NEWSLETTER] if instance.is_vouched: update_basket_task.delay(instance.id, newsletters) elif instance.basket_token: unsubscribe_from_basket_task.delay(instance.email, instance.basket_token, newsletters)
def add_member(self, userprofile, status=GroupMembership.MEMBER): """ Add a user to this group. Optionally specify status other than member. If user is already in the group with the given status, this is a no-op. If user is already in the group with a different status, their status will be updated if the change is a promotion. Otherwise, their status will not change. """ defaults = dict(status=status, date_joined=now()) membership, created = GroupMembership.objects.get_or_create(userprofile=userprofile, group=self, defaults=defaults) if created: if status == GroupMembership.MEMBER: # Joined # Group is functional area, we want to sent this update to Basket if self.functional_area: update_basket_task.delay(userprofile.id) else: if membership.status != status: # Status changed old_status = membership.status membership.status = status if (old_status, status) == (GroupMembership.PENDING, GroupMembership.MEMBER): # Request accepted membership.save() if self.functional_area: # Group is functional area, we want to sent this update to Basket. update_basket_task.delay(userprofile.id) email_membership_change.delay(self.pk, userprofile.user.pk, old_status, status)
def add_member(self, userprofile, status=GroupMembership.MEMBER): """ Add a user to this group. Optionally specify status other than member. If user is already in the group with the given status, this is a no-op. If user is already in the group with a different status, their status will be updated. """ defaults = dict(status=status, date_joined=now()) membership, created = GroupMembership.objects.get_or_create( userprofile=userprofile, group=self, defaults=defaults ) if created: if status == GroupMembership.MEMBER: # Joined update_basket_task.delay(userprofile.id) elif not created and membership.status != status: # Status changed old_status = membership.status membership.status = status membership.save() update_basket_task.delay(userprofile.id) if (old_status, status) == (GroupMembership.PENDING, GroupMembership.MEMBER): # Request accepted email_membership_change.delay(self.pk, userprofile.user.pk, old_status, status)
def remove_member(self, userprofile, send_email=True): membership = GroupMembership.objects.get(group=self, userprofile=userprofile) old_status = membership.status membership.delete() update_basket_task.delay(userprofile.id) if old_status == GroupMembership.PENDING and send_email: # Request denied email_membership_change.delay(self.pk, userprofile.user.pk, old_status, None)
def remove_member(self, userprofile, send_email=True): try: membership = GroupMembership.objects.get(group=self, userprofile=userprofile) except GroupMembership.DoesNotExist: return old_status = membership.status membership.delete() update_basket_task.delay(userprofile.id) if old_status == GroupMembership.PENDING and send_email: # Request denied email_membership_change.delay(self.pk, userprofile.user.pk, old_status, None)
def toggle_group_subscription(request, url): """Toggle the current user's membership of a group.""" group = get_object_or_404(Group, url=url) profile = request.user.userprofile # We don't operate on system groups using this view. if not group.system: if profile.groups.filter(id=group.id).exists(): profile.groups.remove(group) else: profile.groups.add(group) update_basket_task.delay(profile.id) return redirect(reverse('groups:show_group', args=[group.url]))
def remove_member(self, userprofile, send_email=True): try: membership = GroupMembership.objects.get(group=self, userprofile=userprofile) except GroupMembership.DoesNotExist: return old_status = membership.status membership.delete() # If group is functional area, we want to sent this update to Basket if self.functional_area: update_basket_task.delay(userprofile.id) if old_status == GroupMembership.PENDING and send_email: # Request denied email_membership_change.delay(self.pk, userprofile.user.pk, old_status, None)
def remove_member(self, userprofile, send_email=True): try: membership = GroupMembership.objects.get(group=self, userprofile=userprofile) except GroupMembership.DoesNotExist: return old_status = membership.status membership.delete() # If group is functional area, we want to sent this update to Basket if self.functional_area: update_basket_task.delay(userprofile.id) if old_status == GroupMembership.PENDING and send_email: # Request denied email_membership_change.delay(self.pk, userprofile.user.pk, old_status, None) elif old_status == GroupMembership.MEMBER and send_email: # Member removed member_removed_email.delay(self.pk, userprofile.user.pk)
def add_member(self, userprofile, status=GroupMembership.MEMBER): """ Add a user to this group. Optionally specify status other than member. If user is already in the group with the given status, this is a no-op. If user is already in the group with a different status, their status will be updated if the change is a promotion. Otherwise, their status will not change. If the group in question is the NDA group, also add the user to the NDA newsletter. """ defaults = dict(status=status, date_joined=now()) membership, created = GroupMembership.objects.get_or_create( userprofile=userprofile, group=self, defaults=defaults) if membership.status != status: # Status changed # The only valid status change states are: # PENDING to MEMBER # PENDING to PENDING_TERMS # PENDING_TERMS to MEMBER old_status = membership.status membership.status = status statuses = [ (GroupMembership.PENDING, GroupMembership.MEMBER), (GroupMembership.PENDING, GroupMembership.PENDING_TERMS), (GroupMembership.PENDING_TERMS, GroupMembership.MEMBER) ] if (old_status, status) in statuses: # Status changed membership.save() if membership.status in [ GroupMembership.PENDING, GroupMembership.MEMBER ]: email_membership_change.delay(self.pk, userprofile.user.pk, old_status, status) # Since there is no demotion, we can check if the new status is MEMBER and # subscribe the user to the NDA newsletter if the group is NDA if self.name == settings.NDA_GROUP and status == GroupMembership.MEMBER: update_basket_task.delay(userprofile.id, [settings.BASKET_NDA_NEWSLETTER])
def add_member(self, userprofile, status=GroupMembership.MEMBER): """ Add a user to this group. Optionally specify status other than member. If user is already in the group with the given status, this is a no-op. If user is already in the group with a different status, their status will be updated if the change is a promotion. Otherwise, their status will not change. If the group in question is the NDA group, also add the user to the NDA newsletter. """ defaults = dict(status=status, date_joined=now()) membership, created = GroupMembership.objects.get_or_create(userprofile=userprofile, group=self, defaults=defaults) if membership.status != status: # Status changed # The only valid status change states are: # PENDING to MEMBER # PENDING to PENDING_TERMS # PENDING_TERMS to MEMBER old_status = membership.status membership.status = status statuses = [(GroupMembership.PENDING, GroupMembership.MEMBER), (GroupMembership.PENDING, GroupMembership.PENDING_TERMS), (GroupMembership.PENDING_TERMS, GroupMembership.MEMBER)] if (old_status, status) in statuses: # Status changed membership.save() if membership.status in [GroupMembership.PENDING, GroupMembership.MEMBER]: email_membership_change.delay(self.pk, userprofile.user.pk, old_status, status) # Since there is no demotion, we can check if the new status is MEMBER and # subscribe the user to the NDA newsletter if the group is NDA if self.name == settings.NDA_GROUP and status == GroupMembership.MEMBER: update_basket_task.delay(userprofile.id, [settings.BASKET_NDA_NEWSLETTER])
def remove_member(self, userprofile): self.members.remove(userprofile) update_basket_task.delay(userprofile.id)
def update_basket(sender, instance, **kwargs): update_basket_task.delay(instance.id)
def update_basket(sender, instance, **kwargs): if instance.is_vouched: update_basket_task.delay(instance.id) elif instance.basket_token: unsubscribe_from_basket_task.delay(instance.email, instance.basket_token)
def add_member(self, userprofile): self.members.add(userprofile) update_basket_task.delay(userprofile.id)