'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.'

def add_member(self, userprofile, status=GroupMembership.MEMBER):

    defaults = dict(status=status, date_joined=now())
    (membership, _) = GroupMembership.objects.get_or_create(userprofile=userprofile, group=self, defaults=defaults)
    if membership.needs_renewal:
        membership.needs_renewal = False
        membership.save()
    if (membership.status != status):
        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):
            membership.save()
            if (membership.status in [GroupMembership.PENDING, GroupMembership.MEMBER]):
                email_membership_change.delay(self.pk, userprofile.user.pk, old_status, status)
            if ((self.name == settings.NDA_GROUP) and (status == GroupMembership.MEMBER)):
                subscribe_user_to_basket.delay(userprofile.id, [settings.BASKET_NDA_NEWSLETTER])
