Esempio n. 1
0
def create_members(request, microcosm_id):

    if request.method == 'POST':
        pass
    elif request.method == 'GET':
        offset = int(request.GET.get('offset', 0))

        microcosm_url, params, headers = Microcosm.build_request(request.get_host(), id=microcosm_id,
            offset=offset, access_token=request.access_token)
        request.view_requests.append(grequests.get(microcosm_url, params=params, headers=headers))

        try:
            responses = response_list_to_dict(grequests.map(request.view_requests))
        except APIException as exc:
            return respond_with_error(request, exc)

        microcosm = Microcosm.from_api_response(responses[microcosm_url])

        view_data = {
            'user': Profile(responses[request.whoami_url], summary=False) if request.whoami_url else None,
            'site': Site(responses[request.site_url]),
            'site_section': 'memberships',
            'content': microcosm,
            'item_type': 'memberships',
            'pagination': build_pagination_links(responses[microcosm_url]['items']['links'], microcosm.items)
        }
        return render(request, members_form_template, view_data)
Esempio n. 2
0
def single_microcosm(request, microcosm_id):

    # Pagination offset of items within the microcosm.
    try:
        offset = int(request.GET.get('offset', 0))
    except ValueError:
        offset = 0

    microcosm_url, params, headers = Microcosm.build_request(request.get_host(), id=microcosm_id,
                                                             offset=offset, access_token=request.access_token)
    request.view_requests.append(grequests.get(microcosm_url, params=params, headers=headers))
    try:
        responses = response_list_to_dict(grequests.map(request.view_requests))
    except APIException as exc:
        return respond_with_error(request, exc)

    microcosm = Microcosm.from_api_response(responses[microcosm_url])

    view_data = {
        'user': Profile(responses[request.whoami_url], summary=False) if request.whoami_url else None,
        'site': Site(responses[request.site_url]),
        'content': microcosm,
        'item_type': 'microcosm',
        'pagination': build_pagination_links(responses[microcosm_url]['items']['links'], microcosm.items)
    }

    return render(request, microcosm_single_template, view_data)
Esempio n. 3
0
def list_members(request, microcosm_id):
    try:
        offset = int(request.GET.get('offset', 0))
    except ValueError:
        offset = 0

    microcosm_url, params, headers = Microcosm.build_request(request.get_host(), id=microcosm_id,
        offset=offset, access_token=request.access_token)
    request.view_requests.append(grequests.get(microcosm_url, params=params, headers=headers))
    try:
        responses = response_list_to_dict(grequests.map(request.view_requests))
    except APIException as exc:
        return respond_with_error(request, exc)
    microcosm = Microcosm.from_api_response(responses[microcosm_url])

    roles_url, params, headers = RoleList.build_request(request.META['HTTP_HOST'], id=microcosm_id,
        offset=offset, access_token=request.access_token)
    request.view_requests.append(grequests.get(roles_url, params=params, headers=headers))
    try:
        responses = response_list_to_dict(grequests.map(request.view_requests))
    except APIException as exc:
        return respond_with_error(request, exc)
    roles = RoleList.from_api_response(responses[roles_url])

    view_data = {
        'user': Profile(responses[request.whoami_url], summary=False) if request.whoami_url else None,
        'site': Site(responses[request.site_url]),
        'site_section': 'memberships',
        'content': microcosm,
        'memberships': roles,
        'item_type': 'microcosm',
        'pagination': build_pagination_links(responses[roles_url]['roles']['links'], roles.items)
    }

    return render(request, members_list_template, view_data)
Esempio n. 4
0
def list_members(request, microcosm_id):
    try:
        offset = int(request.GET.get('offset', 0))
    except ValueError:
        offset = 0

    microcosm_url, params, headers = Microcosm.build_request(
        request.get_host(),
        id=microcosm_id,
        offset=offset,
        access_token=request.access_token)
    request.view_requests.append(
        grequests.get(microcosm_url, params=params, headers=headers))
    try:
        responses = response_list_to_dict(grequests.map(request.view_requests))
    except APIException as exc:
        return respond_with_error(request, exc)
    microcosm = Microcosm.from_api_response(responses[microcosm_url])

    roles_url, params, headers = RoleList.build_request(
        request.META['HTTP_HOST'],
        id=microcosm_id,
        offset=offset,
        access_token=request.access_token)
    request.view_requests.append(
        grequests.get(roles_url, params=params, headers=headers))
    try:
        responses = response_list_to_dict(grequests.map(request.view_requests))
    except APIException as exc:
        return respond_with_error(request, exc)
    roles = RoleList.from_api_response(responses[roles_url])

    view_data = {
        'user':
        Profile(responses[request.whoami_url], summary=False)
        if request.whoami_url else None,
        'site':
        Site(responses[request.site_url]),
        'site_section':
        'memberships',
        'content':
        microcosm,
        'memberships':
        roles,
        'item_type':
        'microcosm',
        'pagination':
        build_pagination_links(responses[roles_url]['roles']['links'],
                               roles.items)
    }

    return render(request, members_list_template, view_data)
Esempio n. 5
0
def confirm(request):
    """
    View for moderation actions on a single item.
    """

    if request.method == 'GET':
        if request.GET.get('item_type') == 'conversation':
            url, params, headers = Conversation.build_request(
                request.get_host(),
                request.GET.get('item_id'),
                access_token=request.access_token
            )
            request.view_requests.append(grequests.get(url, params=params, headers=headers))
            responses = response_list_to_dict(grequests.map(request.view_requests))
            content = Conversation.from_api_response(responses[url])

        elif request.GET.get('item_type') == 'event':
            url, params, headers = Event.build_request(
                request.get_host(),
                request.GET.get('item_id'),
                access_token=request.access_token
            )
            request.view_requests.append(grequests.get(url, params=params, headers=headers))
            responses = response_list_to_dict(grequests.map(request.view_requests))
            content = Event.from_api_response(responses[url])

        elif request.GET.get('item_type') == 'microcosm':
            url, params, headers = Microcosm.build_request(
                request.get_host(),
                request.GET.get('item_id'),
                access_token=request.access_token
            )
            request.view_requests.append(grequests.get(url, params=params, headers=headers))
            responses = response_list_to_dict(grequests.map(request.view_requests))
            content = Microcosm.from_api_response(responses[url])

        view_data = {
            'user': Profile(responses[request.whoami_url], summary=False),
            'site': Site(responses[request.site_url]),
            'content': content,
            'item_type': request.GET.get('item_type'),
            'action': request.GET.get('action'),
        }

        if request.GET.get('action') == 'move':
            # Fetch list of microcosms to supply in form.
            view_data['microcosms'] = MicrocosmList.retrieve(
                request.get_host(),
                access_token=request.access_token
            )

        return render(request, 'forms/moderation_item.html', view_data)
Esempio n. 6
0
def edit_members(request, microcosm_id, group_id):

    if request.method == 'POST':
        pass
    elif request.method == 'GET':
        try:
            offset = int(request.GET.get('offset', 0))
        except ValueError:
            offset = 0

        microcosm_url, params, headers = Microcosm.build_request(request.get_host(), id=microcosm_id,
            offset=offset, access_token=request.access_token)
        request.view_requests.append(grequests.get(microcosm_url, params=params, headers=headers))

        role_url, params, headers = Role.build_request(request.get_host(), microcosm_id=microcosm_id,
            id=group_id, offset=offset, access_token=request.access_token)
        request.view_requests.append(grequests.get(role_url, params=params, headers=headers))

        criteria_url, params, headers = RoleCriteriaList.build_request(request.get_host(),
            microcosm_id=microcosm_id, id=group_id, offset=offset, access_token=request.access_token)
        request.view_requests.append(grequests.get(criteria_url, params=params, headers=headers))

        profiles_url, params, headers = RoleProfileList.build_request(request.get_host(),
            microcosm_id=microcosm_id, id=group_id, offset=offset, access_token=request.access_token)
        request.view_requests.append(grequests.get(profiles_url, params=params, headers=headers))

        try:
            responses = response_list_to_dict(grequests.map(request.view_requests))
        except APIException as exc:
            return respond_with_error(request, exc)

        microcosm = Microcosm.from_api_response(responses[microcosm_url])
        role = Role.from_api_response(responses[role_url])
        criteria = RoleCriteriaList(responses[criteria_url])
        profiles = RoleProfileList(responses[profiles_url])

        view_data = {
            'user': Profile(responses[request.whoami_url], summary=False) if request.whoami_url else None,
            'site': Site(responses[request.site_url]),
            'site_section': 'memberships',
            'content': microcosm,
            'role': role,
            'criteria': criteria,
            'profiles': profiles,
            'item_type': 'memberships',
            'state_edit': True,
            'pagination': build_pagination_links(responses[microcosm_url]['items']['links'], microcosm.items)
        }

        return render(request, members_form_template, view_data)
Esempio n. 7
0
def root_microcosm(request):

    # Pagination offset of items within the microcosm.
    try:
        offset = int(request.GET.get('offset', 0))
    except ValueError:
        offset = 0

    microcosm_id = 0
    microcosm_url, params, headers = Microcosm.build_request(
        request.get_host(),
        id=microcosm_id,
        offset=offset,
        access_token=request.access_token)
    request.view_requests.append(
        grequests.get(microcosm_url, params=params, headers=headers))
    try:
        responses = response_list_to_dict(grequests.map(request.view_requests))
    except APIException as exc:
        return respond_with_error(request, exc)

    microcosm = Microcosm.from_api_response(responses[microcosm_url])

    view_data = {
        'user':
        Profile(responses[request.whoami_url], summary=False)
        if request.whoami_url else None,
        'site':
        Site(responses[request.site_url]),
        'content':
        microcosm,
        'item_type':
        'microcosm',
        'pagination':
        build_pagination_links(responses[microcosm_url]['items']['links'],
                               microcosm.items)
    }

    return render(request, microcosm_root_template, view_data)
Esempio n. 8
0
def edit_members(request, microcosm_id, group_id):

    if request.method == 'POST':
        pass
    elif request.method == 'GET':
        try:
            offset = int(request.GET.get('offset', 0))
        except ValueError:
            offset = 0

        microcosm_url, params, headers = Microcosm.build_request(
            request.get_host(),
            id=microcosm_id,
            offset=offset,
            access_token=request.access_token)
        request.view_requests.append(
            grequests.get(microcosm_url, params=params, headers=headers))

        role_url, params, headers = Role.build_request(
            request.get_host(),
            microcosm_id=microcosm_id,
            id=group_id,
            offset=offset,
            access_token=request.access_token)
        request.view_requests.append(
            grequests.get(role_url, params=params, headers=headers))

        criteria_url, params, headers = RoleCriteriaList.build_request(
            request.get_host(),
            microcosm_id=microcosm_id,
            id=group_id,
            offset=offset,
            access_token=request.access_token)
        request.view_requests.append(
            grequests.get(criteria_url, params=params, headers=headers))

        profiles_url, params, headers = RoleProfileList.build_request(
            request.get_host(),
            microcosm_id=microcosm_id,
            id=group_id,
            offset=offset,
            access_token=request.access_token)
        request.view_requests.append(
            grequests.get(profiles_url, params=params, headers=headers))

        try:
            responses = response_list_to_dict(
                grequests.map(request.view_requests))
        except APIException as exc:
            return respond_with_error(request, exc)

        microcosm = Microcosm.from_api_response(responses[microcosm_url])
        role = Role.from_api_response(responses[role_url])
        criteria = RoleCriteriaList(responses[criteria_url])
        profiles = RoleProfileList(responses[profiles_url])

        view_data = {
            'user':
            Profile(responses[request.whoami_url], summary=False)
            if request.whoami_url else None,
            'site':
            Site(responses[request.site_url]),
            'site_section':
            'memberships',
            'content':
            microcosm,
            'role':
            role,
            'criteria':
            criteria,
            'profiles':
            profiles,
            'item_type':
            'memberships',
            'state_edit':
            True,
            'pagination':
            build_pagination_links(responses[microcosm_url]['items']['links'],
                                   microcosm.items)
        }

        return render(request, members_form_template, view_data)
Esempio n. 9
0
def confirm(request):
    """
    View for moderation actions on a single item.
    """

    if request.method == 'POST':
        if request.POST.get('item_type') == 'conversation':
            url, params, headers = Conversation.build_request(
                request.get_host(),
                request.POST.get('item_id'),
                access_token=request.access_token)
            request.view_requests.append(
                grequests.get(url, params=params, headers=headers))
            responses = response_list_to_dict(
                grequests.map(request.view_requests))
            content = Conversation.from_api_response(responses[url])

        elif request.POST.get('item_type') == 'event':
            url, params, headers = Event.build_request(
                request.get_host(),
                request.POST.get('item_id'),
                access_token=request.access_token)
            request.view_requests.append(
                grequests.get(url, params=params, headers=headers))
            responses = response_list_to_dict(
                grequests.map(request.view_requests))
            content = Event.from_api_response(responses[url])

        elif request.POST.get('item_type') == 'microcosm':
            url, params, headers = Microcosm.build_request(
                request.get_host(),
                request.POST.get('item_id'),
                access_token=request.access_token)
            request.view_requests.append(
                grequests.get(url, params=params, headers=headers))
            responses = response_list_to_dict(
                grequests.map(request.view_requests))
            content = Microcosm.from_api_response(responses[url])

        view_data = {
            'user': Profile(responses[request.whoami_url], summary=False),
            'site': Site(responses[request.site_url]),
            'content': content,
            'item_type': request.POST.get('item_type'),
            'action': request.POST.get('action'),
        }

        if request.POST.get('action') == 'move':
            # Fetch list of microcosms to supply in form.
            microcosms = MicrocosmList.retrieve(
                request.get_host(), access_token=request.access_token)

            if request.POST.get('item_type') == 'microcosm':
                newlist = []
                nuke = content.id
                found = False
                for m in microcosms.microcosms:
                    if m['id'] == nuke:
                        found = True
                        nuke = m['id']
                    elif m.get('parent_id') and m['parent_id'] == nuke:
                        found = True
                        nuke = m['id']
                    else:
                        if found:
                            nuke = 0
                        newlist.append(m)
                microcosms.microcosms = newlist

            view_data['microcosms'] = microcosms

        return render(request, 'forms/moderation_item.html', view_data)
Esempio n. 10
0
 def testMicrocosmAsDict(self):
     data = json.loads(open(os.path.join(TEST_ROOT, 'data', 'microcosm.json')).read())['data']
     microcosm = Microcosm.from_api_response(data)
     microcosm.as_dict
Esempio n. 11
0
def confirm(request):
    """
    View for moderation actions on a single item.
    """

    if request.method == 'POST':
        if request.POST.get('item_type') == 'conversation':
            url, params, headers = Conversation.build_request(
                request.get_host(),
                request.POST.get('item_id'),
                access_token=request.access_token
            )
            request.view_requests.append(grequests.get(url, params=params, headers=headers))
            responses = response_list_to_dict(grequests.map(request.view_requests))
            content = Conversation.from_api_response(responses[url])

        elif request.POST.get('item_type') == 'event':
            url, params, headers = Event.build_request(
                request.get_host(),
                request.POST.get('item_id'),
                access_token=request.access_token
            )
            request.view_requests.append(grequests.get(url, params=params, headers=headers))
            responses = response_list_to_dict(grequests.map(request.view_requests))
            content = Event.from_api_response(responses[url])

        elif request.POST.get('item_type') == 'microcosm':
            url, params, headers = Microcosm.build_request(
                request.get_host(),
                request.POST.get('item_id'),
                access_token=request.access_token
            )
            request.view_requests.append(grequests.get(url, params=params, headers=headers))
            responses = response_list_to_dict(grequests.map(request.view_requests))
            content = Microcosm.from_api_response(responses[url])

        view_data = {
            'user': Profile(responses[request.whoami_url], summary=False),
            'site': Site(responses[request.site_url]),
            'content': content,
            'item_type': request.POST.get('item_type'),
            'action': request.POST.get('action'),
        }

        if request.POST.get('action') == 'move':
            # Fetch list of microcosms to supply in form.
            microcosms = MicrocosmList.retrieve(
                request.get_host(),
                access_token=request.access_token
            )

            if request.POST.get('item_type') == 'microcosm':
                newlist = []
                nuke = content.id
                found = False
                for m in microcosms.microcosms:
                    if m['id'] == nuke:
                        found = True
                        nuke = m['id']
                    elif m.get('parent_id') and m['parent_id'] == nuke:
                        found = True
                        nuke = m['id']
                    else:
                        if found:
                            nuke = 0
                        newlist.append(m)
                microcosms.microcosms = newlist


            view_data['microcosms'] = microcosms

        return render(request, 'forms/moderation_item.html', view_data)
Esempio n. 12
0
 def testMicrocosmAsDict(self):
     data = json.loads(
         open(os.path.join(TEST_ROOT, 'data',
                           'microcosm.json')).read())['data']
     microcosm = Microcosm.from_api_response(data)
     microcosm.as_dict
Esempio n. 13
0
 def testMicrocosmAsDict(self):
     data = json.loads(open(os.path.join(TEST_ROOT, "data", "microcosm.json")).read())["data"]
     microcosm = Microcosm.from_api_response(data)
     microcosm.as_dict