Пример #1
0
def update_user_scope(user1, user2, scope, relation):
    '''
    Adds user2 to user1's scope memeber.
    e.g
      user1 = 'BigHeadSon', user2 = 'HisMother', socpe = 'home'
      then add HisMother to BigHeadSon's Home Socpe Group

    Before update user scope, the two persons need already have realtion.
    '''
    scope_dict = {
        'H': HOME,
        'R': RELATION,
        'F': FRIEND
    }

    scope = scope_dict.get(scope)

    if scope == HOME:
        update_scope_group(user1, user2, HOME)

        home_id = get_home_id(user1)
        join_to_group(username=user2, group=home_id)
        # add user2 to user1's group home
        if is_close_family_member(user1, user2, relation):
            update_scope_group(user2, user1, HOME)

            home_id = get_home_id(user2)
            join_to_group(username=user1, group=home_id)
            # add user1 to user2's group home
        else:
            update_scope_group(user2, user1, RELATION)
    else:
        update_scope_group(user1, user2, scope)
        update_scope_group(user2, user1, scope)
Пример #2
0
    def post(self, request):
        """
        Inviter invites Invitee join to group G,
        if G not exist, created a new group.

        post:

            {
                inviter: string,
                invitee: string,
                group: string // could be none, if no group id, create one
            }

        Returns:

            {
                status: HTTP status, // show if succeed update.
                group: string // group's unique name
            }

        ---
        parameters:
        - name: inviter
          descritpion: inviter account
          required: true
          type: string
          parameType: form

        - name: invitee
          descritpion: invitee account
          required: true
          type: string
          parameType: form

        - name: group
          descritpion: group unique name
          required: false
          type: string
          parameType: form

        """

        inviter = request.data.get('inviter', None)
        invitee = request.data.get('invitee', None)
        group_name = request.data.get('group', None)

        # category = 'H'
        if not group_name or not group_exist(group_name):
            group_name = create_group(creator=inviter)
            join_to_group(inviter, group_name)

        try:
            join_to_group(invitee, group_name)
            return Response(
                {'group': group_name},
                status=status.HTTP_201_CREATED,
            )
        except Exception as e:
            print e
            return Response(status=status.HTTP_406_NOT_ACCEPTABLE)