コード例 #1
0
ファイル: members.py プロジェクト: claytron/karl
def _member_profile_batch(context, request):
    community = find_interface(context, ICommunity)
    member_names = community.member_names
    profiles_path = resource_path(find_profiles(context))
    batch = get_catalog_batch(
        context, request,
        batch_size = 12,
        interfaces = [IProfile],
        path={'query': profiles_path, 'depth': 1},
        allowed={'query': effective_principals(request), 'operator': 'or'},
        name = list(member_names),
        sort_index='lastfirst',
        )
    return batch
コード例 #2
0
ファイル: people.py プロジェクト: araymund/karl
def recent_content_view(context, request):
    batch = get_catalog_batch(context, request,
        sort_index='creation_date', reverse=True,
        interfaces=[IContent], creator=context.__name__,
        allowed={'query': effective_principals(request), 'operator': 'or'},
        )

    recent_items = []
    for item in batch['entries']:
        adapted = getMultiAdapter((item, request), IGridEntryInfo)
        recent_items.append(adapted)

    page_title = "Content Added Recently by %s" % context.title
    api = TemplateAPI(context, request, page_title)
    return dict(api=api,
             batch_info=batch,
             recent_items=recent_items)
コード例 #3
0
ファイル: people.py プロジェクト: zagy/karl
def recent_content_view(context, request):
    batch = get_catalog_batch(context, request,
        sort_index='creation_date', reverse=True,
        interfaces=[IContent], creator=context.__name__,
        allowed={'query': effective_principals(request), 'operator': 'or'},
        )

    recent_items = []
    for item in batch['entries']:
        adapted = getMultiAdapter((item, request), IGridEntryInfo)
        recent_items.append(adapted)

    layout = request.layout_manager.layout
    layout.page_title = "Content Added Recently by %s" % context.title
    api = TemplateAPI(context, request, layout.page_title)
    return dict(api=api,
             batch_info=batch,
             recent_items=recent_items)
コード例 #4
0
ファイル: peopledirectory.py プロジェクト: hathawsh/karl
def get_grid_data(context, request, start=0, limit=12, sort_on=None, reverse=False, width=GRID_WIDTH):
    """Gets the data for the jquery report grid.
    """
    columns = [COLUMNS[colid] for colid in context.columns]
    columns_jsdata = get_column_jsdata(columns, width - SCROLLBAR_WIDTH)
    if sort_on is None:
        sort_on = columns[0].id
    sort_index = COLUMNS[sort_on].sort_index

    kw = get_report_query(context, request)
    try:
        batch = get_catalog_batch(
            context, request, batch_start=start, batch_size=limit, sort_index=sort_index, reverse=reverse, **kw
        )
    except ParseError, e:
        # user entered something weird in the text search box.
        # show no results.
        batch = {"entries": [], "total": 0}
コード例 #5
0
ファイル: people.py プロジェクト: reebalazs/karl
def recent_content_view(context, request):
    batch = get_catalog_batch(
        context,
        request,
        sort_index="creation_date",
        reverse=True,
        interfaces=[IContent],
        creator=context.__name__,
        allowed={"query": effective_principals(request), "operator": "or"},
    )

    recent_items = []
    for item in batch["entries"]:
        adapted = getMultiAdapter((item, request), IGridEntryInfo)
        recent_items.append(adapted)

    page_title = "Content Added Recently by %s" % context.title
    api = TemplateAPI(context, request, page_title)
    return render_template_to_response(
        "templates/profile_recent_content.pt", api=api, batch_info=batch, recent_items=recent_items
    )
コード例 #6
0
ファイル: members.py プロジェクト: zagy/karl
def _member_profile_batch(context, request):
    community = find_interface(context, ICommunity)
    member_names = community.member_names
    profiles_path = resource_path(find_profiles(context))
    batch = get_catalog_batch(
        context,
        request,
        batch_size=12,
        interfaces=[IProfile],
        path={
            'query': profiles_path,
            'depth': 1
        },
        allowed={
            'query': effective_principals(request),
            'operator': 'or'
        },
        name=list(member_names),
        sort_index='lastfirst',
    )
    return batch
コード例 #7
0
ファイル: pushdowns.py プロジェクト: zagy/karl
def myprofile_ajax_view(context, request):
    results = {}
    # template provision
    if request.params.get('needsTemplate', 'false') in ('true', 'True'):
        # We need the template. So, let's fetch it.
        layout = request.layout_manager.layout
        results['microtemplate'] = layout.microtemplates['myprofile']
        results['partials'] = []
    # Fetch the data

    # 2nd column: my communities (preferred communities)
    communities_folder = find_communities(context)
    communities = get_my_communities(communities_folder, request)
    communities = sorted(communities,
                         key=attrgetter('last_activity_date'),
                         reverse=True)
    communities_info = [
        dict(
            title=community.title,
            description=community.description,
            url=community.url,
            actions=[
                dict(
                    url=community.url +
                    (a_name if a_name != 'overview' else 'view.html'),
                    title=a_name.capitalize(),
                    last=a_name == 'wiki',
                )
                for a_name in ('overview', 'blog', 'calendar', 'files', 'wiki')
            ],
        ) for community in communities[:5]
    ]

    # 3rd column: My Recent Activity
    recent_items = []
    recent_items_batch = get_catalog_batch(
        context,
        request,
        batch_size=5,
        interfaces=[ICommunityContent],
        sort_index="modified_date",
        reverse=True,
        modified_by=authenticated_userid(request),
        allowed={
            'query': effective_principals(request),
            'operator': 'or'
        })

    for item in recent_items_batch["entries"]:
        adapted = getMultiAdapter((item, request), IGridEntryInfo)
        community = find_community(item)
        if community is not None:
            community_adapter = getMultiAdapter((community, request),
                                                ICommunityInfo)
            community_info = dict(
                url=community_adapter.url,
                title=community_adapter.title,
            )
        else:
            community_info = None
        # Since this is json, we need a real dict...
        recent_items.append(
            dict(
                title=adapted.title,
                url=adapted.url,
                modified=item.modified.strftime('%Y-%m-%dT%H:%M:%S'),
                creator_title=adapted.creator_title,
                type=adapted.type,
                community=community_info,
            ))

    profiles = find_profiles(request.context)
    userid = authenticated_userid(request)
    profile = profiles.get(userid)

    photo = profile.get('photo')
    if photo is not None:
        icon_url = thumb_url(photo, request, (45, 60))
    else:
        icon_url = request.static_url(
            'karl.views:static/images/defaultUser.gif')
    # Assemble the final result.
    results['data'] = {
        'profile_name':
        profile.title,
        'profile_url':
        request.resource_url(profile),
        'icon_url':
        icon_url,
        'logout_url':
        "%s/logout.html" % request.application_url,
        'department':
        profile.department,
        'position':
        profile.position,
        'email':
        profile.email,
        'extension':
        profile.extension,
        'phone':
        profile.phone,
        'panels': [{
            'class': 'mycommunities',
            'title': 'My Active Communities',
            'communities': communities_info,
        }, {
            'class': 'myrecentitems',
            'title': 'My Recent Activity',
            'contexts': recent_items,
        }],
    }

    return results
コード例 #8
0
ファイル: pushdowns.py プロジェクト: zagy/karl
def radar_ajax_view(context, request):
    # Example result set, for demonstrating the widget without
    # a real server database.
    results = {}
    # Datetime of the current search. (The client will pass it back
    # to us the next time, and we can decide if an update is needed)
    now = datetime.datetime.now()
    now_iso = now.isoformat()
    results['ts'] = now_iso
    ts_iso = request.params.get('ts', '')
    # template provision
    if request.params.get('needsTemplate', 'false') in ('true', 'True'):
        # We need the template. So, let's fetch it.
        layout = request.layout_manager.layout
        results['microtemplate'] = layout.microtemplates['radar']
        results['partials'] = []
    # Sometimes there is no need for an update. The server can just return
    # empty data. A condition is that a ts parameter is sent to us. The
    # other condition (does the client need an update?) is now simulated
    # with a random choice.
    if ts_iso and random.choice([False, True]):
        results['data'] = None
    else:
        # Fetch the data

        # 2nd column: my communities (preferred communities)
        communities_folder = find_communities(context)
        communities = get_my_communities(communities_folder, request)
        communities_info = [
            dict(
                title=community.title,
                description=community.description,
                url=community.url,
                actions=[
                    dict(
                        url=community.url +
                        (a_name if a_name != 'overview' else 'view.html'),
                        title=a_name.capitalize(),
                        last=a_name == 'files',
                    ) for a_name in ('overview', 'blog', 'calendar', 'files',
                                     'wiki')
                ],
            ) for community in communities[:5]
        ]

        # 3rd column: My Recent Activity
        recent_items = []
        recent_items_batch = get_catalog_batch(
            context,
            request,
            batch_size=5,
            interfaces=[ICommunityContent],
            sort_index="modified_date",
            reverse=True,
            modified_by=authenticated_userid(request),
            allowed={
                'query': effective_principals(request),
                'operator': 'or'
            })

        for item in recent_items_batch["entries"]:
            adapted = getMultiAdapter((item, request), IGridEntryInfo)
            community = find_community(item)
            if community is not None:
                community_adapter = getMultiAdapter((community, request),
                                                    ICommunityInfo)
                community_info = dict(
                    url=community_adapter.url,
                    title=community_adapter.title,
                )
            else:
                community_info = None
            # Since this is json, we need a real dict...
            recent_items.append(
                dict(
                    title=adapted.title,
                    url=adapted.url,
                    modified=adapted.modified,
                    creator_title=adapted.creator_title,
                    type=adapted.type,
                    community=community_info,
                ))

        # Provide fake "approval items" for the "approvals" tab.

        approval_waitinglist_items = [{
            'title':
            'Approval Waiting List',
            'group': [{
                'title': 'e-Payment',
                'count': 0,
                'id': 'table1'
            }, {
                'title': 'Grant Payment',
                'count': 2,
                'id': 'table2'
            }, {
                'title': 'Contract Review',
                'count': 3,
            }, {
                'title': 'Contract Approval',
                'count': 2,
            }, {
                'title': 'Contract Payment',
                'count': 1,
            }, {
                'title': 'Hardware / Software Request',
                'count': 4,
            }]
        }, {
            'title':
            'Payment Waiting List',
            'group': [{
                'title': 'e-Payment',
                'count': 0,
            }, {
                'title': 'Grant Payment',
                'count': 133,
            }, {
                'title': 'Contract Payment',
                'count': 116,
            }]
        }, {
            'title':
            'Accrual Waiting List',
            'group': [{
                'title': 'Grant Accrual',
                'count': 7,
            }]
        }, {
            'title':
            'Fixed Assets Waiting List',
            'group': [{
                'title': 'e-Approval',
                'count': 7,
            }, {
                'title': 'e-Bridge for Posting',
                'count': 3,
            }]
        }]

        approval_table1_items = [{
            'amt': '45.09',
            'via': 'Check',
            'approvedBy': 'Some Person',
            'status': 'Approved',
            'statusDate': '02/09/2012',
            'overdueBy': '13',
        }, {
            'amt': '13.00',
            'via': 'Wire',
            'approvedBy': 'Another Person',
            'status': 'Submitted',
            'statusDate': '02/14/2012',
            'overdueBy': '16',
        }, {
            'amt': '71.21',
            'via': 'Check',
            'approvedBy': 'Last Person',
            'status': 'Approved',
            'statusDate': '02/13/2012',
            'overdueBy': '18',
        }]

        for i, row in enumerate(approval_table1_items):
            row['rowClass'] = 'even' if i % 2 else 'odd'

        import copy
        approval_table2_items = 2 * copy.deepcopy(approval_table1_items)
        for i, row in enumerate(approval_table2_items):
            row['rowClass'] = 'even' if i % 2 else 'odd'

        # Assemble the final result.
        results['data'] = {
            # home section
            'home': [{
                'class': 'homepanel1',
                'title': 'My Communities',
                'communities': communities_info,
            }, {
                'class': 'homepanel2',
                'title': 'My Recent Activity',
                'contexts': recent_items,
            }],
            # approvals section
            'approvals': [{
                'class': 'approvalpanel1',
                'waitinglist': {
                    'items': approval_waitinglist_items,
                },
            }, {
                'class':
                'approvalpanel2',
                'tables': [{
                    'id': 'table1',
                    'title': 'Open Project Project',
                    'items': approval_table1_items,
                }, {
                    'id': 'table2',
                    'title': 'Very Open Project',
                    'items': approval_table2_items,
                }],
            }],
        }

        results['state'] = {
            'chart1': {
                'options': {
                    'title': 'Company Performance',
                    'hAxis': {
                        'title': 'Year',
                        'titleTextStyle': {
                            'color': 'red'
                        },
                    },
                    'width': 200,  # Must have fixed width! (matching css)
                },
                'columns': [
                    ['string', 'Year'],
                    ['number', 'Sales'],
                    ['number', 'Expenses'],
                ],
                'rows': [
                    ['2004', 1000, 400],
                    ['2005', 1170, 460],
                    ['2006', 660, 1120],
                    ['2007', 1030, 540],
                ],
            },
            'chart2': {
                'options': {
                    'title': 'Monthly Operating Revenue',
                    'hAxis': {
                        'title': 'Project',
                        'titleTextStyle': {
                            'color': 'red'
                        },
                    },
                    'width': 400,  # Must have fixed width! (matching css)
                },
                'columns': [
                    ['string', 'Project'],
                    ['number', 'Budgeted'],
                    ['number', 'Actual'],
                ],
                'rows': [
                    ['My First Project', 1000, 400],
                    ['Another Project', 1170, 460],
                    ['A Third Project', 660, 1120],
                ],
            },
        }

    return results
コード例 #9
0
ファイル: test_batch.py プロジェクト: boothead/karl
 def _callFUT(self, context, request, **kw):
     from karl.views.batch import get_catalog_batch
     return get_catalog_batch(context, request, **kw)
コード例 #10
0
ファイル: test_batch.py プロジェクト: lslaz1/karl
 def _callFUT(self, context, request, **kw):
     from karl.views.batch import get_catalog_batch
     return get_catalog_batch(context, request, **kw)
コード例 #11
0
ファイル: pushdowns.py プロジェクト: hj91/karl
def myprofile_ajax_view(context, request):
    results = {}
    # template provision
    if request.params.get('needsTemplate', 'false') in ('true', 'True'):
        # We need the template. So, let's fetch it.
        layout = request.layout_manager.layout
        results['microtemplate'] = layout.microtemplates['myprofile']
        results['partials'] = []
    # Fetch the data

    # 2nd column: my communities (preferred communities)
    communities_folder = find_communities(context)
    communities = get_my_communities(communities_folder, request)
    communities = sorted(communities,
                         key=attrgetter('last_activity_date'),
                         reverse=True)
    communities_info = [
        dict(
            title=community.title,
            description=community.description,
            url=community.url,
            actions=[dict(
                url=community.url + (a_name if a_name != 'overview' else 'view.html'),
                title=a_name.capitalize(),
                last=a_name == 'wiki',
                ) for a_name in ('overview', 'blog', 'calendar', 'files', 'wiki')],
        )
        for community in communities[:5]
    ]

    # 3rd column: My Recent Activity
    recent_items = []
    recent_items_batch = get_catalog_batch(context, request, batch_size=5,
        interfaces=[ICommunityContent], sort_index="modified_date",
        reverse=True, modified_by=authenticated_userid(request),
        allowed={'query': effective_principals(request), 'operator': 'or'})

    for item in recent_items_batch["entries"]:
        adapted = getMultiAdapter((item, request), IGridEntryInfo)
        community = find_community(item)
        if community is not None:
            community_adapter = getMultiAdapter((community, request),
                                                ICommunityInfo)
            community_info = dict(
                url=community_adapter.url,
                title=community_adapter.title,
            )
        else:
            community_info = None
        # Since this is json, we need a real dict...
        recent_items.append(dict(
            title=adapted.title,
            url=adapted.url,
            modified=item.modified.strftime('%Y-%m-%dT%H:%M:%S'),
            creator_title=adapted.creator_title,
            type=adapted.type,
            community=community_info,
            ))

    profiles = find_profiles(request.context)
    userid = authenticated_userid(request)
    profile = profiles.get(userid)

    photo = profile.get('photo')
    if photo is not None:
        icon_url = thumb_url(photo, request, (45,60))
    else:
        icon_url = request.static_url('karl.views:static/images/defaultUser.gif')
    # Assemble the final result.
    results['data'] = {
        'profile_name': profile.title,
        'profile_url': request.resource_url(profile),
        'icon_url': icon_url,
        'logout_url': "%s/logout.html" % request.application_url,
        'department': profile.department,
        'position': profile.position,
        'email': profile.email,
        'extension': profile.extension,
        'phone': profile.phone,
        'panels': [{
            'class': 'mycommunities',
            'title': 'My Active Communities',
            'communities': communities_info,
            }, {
            'class': 'myrecentitems',
            'title': 'My Recent Activity',
            'contexts': recent_items,
            }],
        }

    return results
コード例 #12
0
ファイル: pushdowns.py プロジェクト: hj91/karl
def radar_ajax_view(context, request):
    # Example result set, for demonstrating the widget without
    # a real server database.
    results = {}
    # Datetime of the current search. (The client will pass it back
    # to us the next time, and we can decide if an update is needed)
    now = datetime.datetime.now()
    now_iso = now.isoformat()
    results['ts'] = now_iso
    ts_iso = request.params.get('ts', '')
    # template provision
    if request.params.get('needsTemplate', 'false') in ('true', 'True'):
        # We need the template. So, let's fetch it.
        layout = request.layout_manager.layout
        results['microtemplate'] = layout.microtemplates['radar']
        results['partials'] = []
    # Sometimes there is no need for an update. The server can just return
    # empty data. A condition is that a ts parameter is sent to us. The
    # other condition (does the client need an update?) is now simulated
    # with a random choice.
    if ts_iso and random.choice([False, True]):
        results['data'] = None
    else:
        # Fetch the data

        # 2nd column: my communities (preferred communities)
        communities_folder = find_communities(context)
        communities = get_my_communities(communities_folder, request)
        communities_info = [
            dict(
                title=community.title,
                description=community.description,
                url=community.url,
                actions=[dict(
                    url=community.url + (a_name if a_name != 'overview' else 'view.html'),
                    title=a_name.capitalize(),
                    last=a_name == 'files',
                    ) for a_name in ('overview', 'blog', 'calendar', 'files', 'wiki')],
            )
            for community in communities[:5]
        ]

        # 3rd column: My Recent Activity
        recent_items = []
        recent_items_batch = get_catalog_batch(context, request, batch_size=5,
            interfaces=[ICommunityContent], sort_index="modified_date",
            reverse=True, modified_by=authenticated_userid(request),
            allowed={'query': effective_principals(request), 'operator': 'or'})

        for item in recent_items_batch["entries"]:
            adapted = getMultiAdapter((item, request), IGridEntryInfo)
            community = find_community(item)
            if community is not None:
                community_adapter = getMultiAdapter((community, request), ICommunityInfo)
                community_info = dict(
                    url=community_adapter.url,
                    title=community_adapter.title,
                )
            else:
                community_info = None
            # Since this is json, we need a real dict...
            recent_items.append(dict(
                title=adapted.title,
                url=adapted.url,
                modified=adapted.modified,
                creator_title=adapted.creator_title,
                type=adapted.type,
                community=community_info,
                ))

        # Provide fake "approval items" for the "approvals" tab.

        approval_waitinglist_items = [{
            'title': 'Approval Waiting List',
            'group': [{
                'title': 'e-Payment',
                'count': 0,
                'id': 'table1'
                }, {
                'title': 'Grant Payment',
                'count': 2,
                'id': 'table2'
                }, {
                'title': 'Contract Review',
                'count': 3,
                }, {
                'title': 'Contract Approval',
                'count': 2,
                }, {
                'title': 'Contract Payment',
                'count': 1,
                }, {
                'title': 'Hardware / Software Request',
                'count': 4,
                }
            ]
        }, {
            'title': 'Payment Waiting List',
            'group': [{
                'title': 'e-Payment',
                'count': 0,
                }, {
                'title': 'Grant Payment',
                'count': 133,
                }, {
                'title': 'Contract Payment',
                'count': 116,
                }
            ]
        }, {
            'title': 'Accrual Waiting List',
            'group': [{
                'title': 'Grant Accrual',
                'count': 7,
                }
            ]

        }, {
            'title': 'Fixed Assets Waiting List',
            'group': [{
                'title': 'e-Approval',
                'count': 7,
                }, {
                'title': 'e-Bridge for Posting',
                'count': 3,
                }
            ]

        }];


        approval_table1_items = [{
            'amt': '45.09',
            'via': 'Check',
            'approvedBy': 'Some Person',
            'status': 'Approved',
            'statusDate': '02/09/2012',
            'overdueBy': '13',
            }, {
            'amt': '13.00',
            'via': 'Wire',
            'approvedBy': 'Another Person',
            'status': 'Submitted',
            'statusDate': '02/14/2012',
            'overdueBy': '16',
            }, {
            'amt': '71.21',
            'via': 'Check',
            'approvedBy': 'Last Person',
            'status': 'Approved',
            'statusDate': '02/13/2012',
            'overdueBy': '18',
            }]

        for i, row in enumerate(approval_table1_items):
            row['rowClass'] = 'even' if i % 2 else 'odd'

        import copy
        approval_table2_items = 2 * copy.deepcopy(approval_table1_items)
        for i, row in enumerate(approval_table2_items):
            row['rowClass'] = 'even' if i % 2 else 'odd'

        # Assemble the final result.
        results['data'] = {
            # home section
            'home': [{
                'class': 'homepanel1',
                'title': 'My Communities',
                'communities': communities_info,
                }, {
                'class': 'homepanel2',
                'title': 'My Recent Activity',
                'contexts': recent_items,
                }],
            # approvals section
            'approvals': [{
                'class': 'approvalpanel1',
                'waitinglist': {
                    'items': approval_waitinglist_items,
                    },
                }, {
                'class': 'approvalpanel2',
                'tables': [{
                    'id': 'table1',
                    'title': 'Open Project Project',
                    'items': approval_table1_items,
                    }, {
                    'id': 'table2',
                    'title': 'Very Open Project',
                    'items': approval_table2_items,
                    }],
                }],
            }

        results['state'] = {
            'chart1': {
                'options' : {
                    'title': 'Company Performance',
                    'hAxis': {
                        'title': 'Year',
                        'titleTextStyle': {'color': 'red'},
                        },
                    'width': 200,      # Must have fixed width! (matching css)
                    },
                'columns': [
                    ['string', 'Year'],
                    ['number', 'Sales'],
                    ['number', 'Expenses'],
                    ],
                'rows': [
                    ['2004', 1000, 400],
                    ['2005', 1170, 460],
                    ['2006', 660, 1120],
                    ['2007', 1030, 540],
                    ],
                },
            'chart2': {
                'options' : {
                    'title': 'Monthly Operating Revenue',
                    'hAxis': {
                        'title': 'Project',
                        'titleTextStyle': {'color': 'red'},
                        },
                    'width': 400,      # Must have fixed width! (matching css)
                    },
                'columns': [
                    ['string', 'Project'],
                    ['number', 'Budgeted'],
                    ['number', 'Actual'],
                    ],
                'rows': [
                    ['My First Project', 1000, 400],
                    ['Another Project', 1170, 460],
                    ['A Third Project', 660, 1120],
                    ],
                },
            }


    return results