def render(self, context):
        user1_instance = template.resolve_variable(self.user1, context)
        user2_instance = template.resolve_variable(self.user2, context)
        if user2_instance == user1_instance:
            context[self.context_var] = 'self'
            return ''

        social_auth_backend = None

        user_social_auth = user1_instance.social_auth.filter(provider="facebook")
        if user_social_auth.exists():
            social_auth_backend = "facebook"
        else:
            user_social_auth = user1_instance.social_auth.filter(provider="twitter")
            if user_social_auth.exists():
                social_auth_backend = "twitter"

        if user_social_auth.exists():
            friends = cache.get(user1_instance.username+"SocialFriendList")
            if friends is None:
                friends = SocialFriendList.objects.existing_social_friends(user_social_auth[0])
                cache.set(user1_instance.username+"SocialFriendList", friends)

            if user2_instance in friends and relationship_exists(user1_instance, user2_instance, 'following'):
                context[self.context_var] = social_auth_backend
                return ''

        if relationship_exists(user1_instance, user2_instance, 'following'):
            context[self.context_var] = 'level1'
            return ''
        else:
            friends = user1_instance.relationships.following()
            for friend in friends:
                if user2_instance in friend.relationships.following() and user2_instance != user1_instance:
                    context[self.context_var] = 'level2'
                    return ''

        context[self.context_var] = ''
        return ''        
Beispiel #2
0
 def render(self, context):
     # Determine if user is a coordinator of one of other's teams.
     user = context['user']
     profile = context['profile']
     other = profile.user
     #
     is_me = context['is_me']
     #
     # Determine if current user is a coordinator of a team that the other user is a member of.
     coordinator_teams = set(m.team for m in user.member_set.filter(is_coordinator=True))
     other_teams = set(other.team_set.all())
     if other_teams.intersection(coordinator_teams):
         is_coordinator = True
     else:
         is_coordinator = False
     #
     # Determine if the other user follows the current user.
     is_friend = relationship_exists(other, user, 'following')
     #
     # Now determine privacy settings for each section.
     privacy_conditions = {
         # privacy-code: lookup-fn,
         'P': False,
         'C': is_coordinator,
         'F': is_coordinator or is_friend,
         'A': True,
     }
     for section in [
         'name',
         'zip_code',
         'interests',
         'bio',
         'email',
         'phone_number',
         'messaging',
         'mailing_address',
         'preferred_contact_methods',
         'occupation',
         'employer',
         'union',
         ]:
         privacy_name = '{0}_privacy'.format(section)
         privacy_code = getattr(profile, privacy_name)
         context['can_view_{0}'.format(section)] = is_me or privacy_conditions[privacy_code]
         if privacy_code != 'A':
             context['{0}_restricted'.format(section)] = True
     return u''
    def test_relationship_exists(self):
        self.assertTrue(relationship_exists(self.john, self.yoko, 'following'))
        self.assertTrue(relationship_exists(self.john, self.yoko, 'followers'))
        self.assertTrue(relationship_exists(self.john, self.yoko, 'friends'))

        self.assertTrue(relationship_exists(self.yoko, self.john, 'following'))
        self.assertTrue(relationship_exists(self.yoko, self.john, 'followers'))
        self.assertTrue(relationship_exists(self.yoko, self.john, 'friends'))

        self.assertTrue(relationship_exists(self.john, self.paul, 'following'))
        self.assertFalse(relationship_exists(self.john, self.paul, 'followers'))
        self.assertFalse(relationship_exists(self.john, self.paul, 'friends'))

        self.assertFalse(relationship_exists(self.paul, self.john, 'following'))
        self.assertTrue(relationship_exists(self.paul, self.john, 'followers'))
        self.assertFalse(relationship_exists(self.paul, self.john, 'friends'))

        self.assertTrue(relationship_exists(self.paul, self.john, 'blocking'))
        self.assertFalse(relationship_exists(self.paul, self.john, 'blockers'))
Beispiel #4
0
    def test_relationship_exists(self):
        self.assertTrue(relationship_exists(self.john, self.yoko, "following"))
        self.assertTrue(relationship_exists(self.john, self.yoko, "followers"))
        self.assertTrue(relationship_exists(self.john, self.yoko, "friends"))

        self.assertTrue(relationship_exists(self.yoko, self.john, "following"))
        self.assertTrue(relationship_exists(self.yoko, self.john, "followers"))
        self.assertTrue(relationship_exists(self.yoko, self.john, "friends"))

        self.assertTrue(relationship_exists(self.john, self.paul, "following"))
        self.assertFalse(relationship_exists(self.john, self.paul, "followers"))
        self.assertFalse(relationship_exists(self.john, self.paul, "friends"))

        self.assertFalse(relationship_exists(self.paul, self.john, "following"))
        self.assertTrue(relationship_exists(self.paul, self.john, "followers"))
        self.assertFalse(relationship_exists(self.paul, self.john, "friends"))

        self.assertTrue(relationship_exists(self.paul, self.john, "blocking"))
        self.assertFalse(relationship_exists(self.paul, self.john, "blockers"))
Beispiel #5
0
    def test_relationship_exists(self):
        self.assertTrue(relationship_exists(self.john, self.yoko, 'following'))
        self.assertTrue(relationship_exists(self.john, self.yoko, 'followers'))
        self.assertTrue(relationship_exists(self.john, self.yoko, 'friends'))

        self.assertTrue(relationship_exists(self.yoko, self.john, 'following'))
        self.assertTrue(relationship_exists(self.yoko, self.john, 'followers'))
        self.assertTrue(relationship_exists(self.yoko, self.john, 'friends'))

        self.assertTrue(relationship_exists(self.john, self.paul, 'following'))
        self.assertFalse(relationship_exists(self.john, self.paul,
                                             'followers'))
        self.assertFalse(relationship_exists(self.john, self.paul, 'friends'))

        self.assertFalse(relationship_exists(self.paul, self.john,
                                             'following'))
        self.assertTrue(relationship_exists(self.paul, self.john, 'followers'))
        self.assertFalse(relationship_exists(self.paul, self.john, 'friends'))

        self.assertTrue(relationship_exists(self.paul, self.john, 'blocking'))
        self.assertFalse(relationship_exists(self.paul, self.john, 'blockers'))
Beispiel #6
0
# --- PROFILE PRIVACY ---


def _is_coordinator(u, o):
    coordinator_teams = set(m.team for m in u.member_set.filter(is_coordinator=True))
    other_teams = set(o.team_set.all())
    if other_teams.intersection(coordinator_teams):
        return True
    else:
        return False

_privacy_conditions = {
    # privacy-code: lookup-fn,
    'P': lambda u, o: False,
    'C': lambda u, o: _is_coordinator(u, o),
    'F': lambda u, o: _is_coordinator(u, o) or relationship_exists(o, u, 'following'),
    'A': lambda u, o: True,
}

for _section in [
    'name',
    'zip_code',
    'mailing_address',
    'email',
    'phone_number',
    'messaging',
    'preferred_contact_methods',
    'bio',
    'interests',
    'occupation',
    'employer',