Пример #1
0
def share_level_for_editor(request, levelID):
    """ Shares a level with the provided list of recipients """
    recipientIDs = request.POST.getlist('recipientIDs[]')
    action = request.POST.get('action')

    level = get_object_or_404(Level, id=levelID)
    recipients = User.objects.filter(id__in=recipientIDs)

    def can_share_level_with(r):
        return permissions.can_share_level_with(r, level.owner.user)

    users = [recipient.userprofile.user for recipient in recipients if can_share_level_with(recipient)]

    if action == 'share':
        level_management.share_level(level, *users)
    elif action == 'unshare':
        level_management.unshare_level(level, *users)

    return get_sharing_information_for_editor(request, levelID)
Пример #2
0
def share_level_for_editor(request, levelID):
    """ Shares a level with the provided list of recipients """
    recipientIDs = request.POST.getlist('recipientIDs[]')
    action = request.POST.get('action')

    level = get_object_or_404(Level, id=levelID)
    recipients = User.objects.filter(id__in=recipientIDs)

    def can_share_level_with(r):
        return permissions.can_share_level_with(r, level.owner.user)

    users = [recipient.userprofile.user for recipient in recipients if can_share_level_with(recipient)]

    if action == 'share':
        level_management.share_level(level, *users)
    elif action == 'unshare':
        level_management.unshare_level(level, *users)

    return get_sharing_information_for_editor(request, levelID)
Пример #3
0
    def post(self, request, **kwargs):
        """
        Gets the level id and recipient ids from the request, and shares or
        unshares the level according to the action from the request.
        :param request: the post request sent to the view.
        :return a call to the SharingInformationForEditor class to return the new
        sharing information of the level.
        """
        levelID = kwargs["levelID"]
        recipientIDs = request.POST.getlist("recipientIDs[]")
        action = request.POST.get("action")

        level = get_object_or_404(Level, id=levelID)

        recipients = User.objects.filter(id__in=recipientIDs)
        users = self._get_users_to_share_level_with(recipients)

        if action == "share":
            level_management.share_level(level, *users)
        elif action == "unshare":
            level_management.unshare_level(level, *users)

        return SharingInformationForEditor().get(request, levelID=levelID)