Example #1
0
def report_view(context, request):
    client_json_data = {
        'grid_data': get_grid_data(context, request),
        }
    api = TemplateAPI(context, request, context.title)
    peopledir = find_peopledirectory(context)
    section = context.__parent__
    peopledir_tabs = get_tabs(peopledir, request, section.__name__)

    mgr = ILetterManager(context)
    letter_info = mgr.get_info(request)
    kw, qualifiers = get_search_qualifiers(request)

    descriptions = get_report_descriptions(context)
    print_url = model_url(context, request, 'print.html', **kw)
    csv_url = model_url(context, request, 'csv', **kw)
    pictures_url = model_url(context, request, 'picture_view.html', **kw)
    opensearch_url = model_url(context, request, 'opensearch.xml')

    return render_template_to_response(
        'templates/people_report.pt',
        api=api,
        peopledir=peopledir,
        peopledir_tabs=peopledir_tabs,
        head_data=convert_to_script(client_json_data),
        descriptions=descriptions,
        letters=letter_info,
        print_url=print_url,
        csv_url=csv_url,
        pictures_url=pictures_url,
        qualifiers=qualifiers,
        opensearch_url=opensearch_url,
        actions=get_actions(context, request),
        )
Example #2
0
def main():
    parser = OptionParser(description=__doc__)
    parser.add_option(
        '-C',
        '--config',
        dest='config',
        default=None,
        help="Specify a paster config file. Defaults to $CWD/etc/karl.ini")
    parser.add_option('-d',
                      '--dry-run',
                      dest='dry_run',
                      action="store_true",
                      default=False,
                      help="Don't commit the transactions")

    options, args = parser.parse_args()
    if args:
        parser.error("Too many parameters: %s" % repr(args))

    config = options.config
    if config is None:
        config = get_default_config()
    root, closer = open_root(config)

    peopledir = find_peopledirectory(root)
    reindex_peopledirectory(peopledir)

    if options.dry_run:
        transaction.abort()
    else:
        transaction.commit()
Example #3
0
    def create(self, container):
        """
        container is root['people']['categories'], or moral equivalent.
        """
        title = self._element_value(self.element, 'title')
        sync_id = self.element.get('id')
        name = make_name(container, title)
        description = self._element_value(self.element, 'description')

        category_element = self.element.find(self.NS_PREFIX + 'category')
        category_id = category_element.get('id')
        category = container.get(category_id, None)
        if category is None:
            category = PeopleCategory(category_element.text.strip())
            container[category_id] = category
            peopledir = find_peopledirectory(container)
            notify(PeopleDirectorySchemaChanged(peopledir))

        category_item = PeopleCategoryItem(title, description)
        if sync_id is not None:
            category_item.sync_id = sync_id  # OSI artifact

        if name in category:
            del category[name]
        category[name] = category_item
Example #4
0
def report_view(context, request):
    api = TemplateAPI(context, request, context.title)
    peopledir = find_peopledirectory(context)
    section = context.__parent__
    peopledir_tabs = get_tabs(peopledir, request, section.__name__)
    client_json_data = {"grid_data": get_grid_data(context, request)}

    descriptions = get_report_descriptions(context)
    mgr = ILetterManager(context)
    letter_info = mgr.get_info(request)

    kw, qualifiers = get_search_qualifiers(request)
    print_url = resource_url(context, request, "print.html", **kw)
    csv_url = resource_url(context, request, "csv", **kw)
    pictures_url = resource_url(context, request, "picture_view.html", **kw)
    opensearch_url = resource_url(context, request, "opensearch.xml")

    return dict(
        api=api,
        peopledir=peopledir,
        peopledir_tabs=peopledir_tabs,
        head_data=convert_to_script(client_json_data),
        descriptions=descriptions,
        letters=letter_info,
        print_url=print_url,
        csv_url=csv_url,
        pictures_url=pictures_url,
        qualifiers=qualifiers,
        opensearch_url=opensearch_url,
        actions=get_actions(context, request),
        mailto=_get_mailto(context, peopledir),
    )
Example #5
0
    def checkPermission(self, info):
        """ Does user have permission to author content in the given context?

        Uses ACL security policy to test.
        """
        users = find_users(self.context)
        for target in info['targets']:
            if 'error' in target:
                continue
            report_name = target.get('report')
            if report_name is not None:
                pd = find_peopledirectory(self.context)
                context = find_resource(pd, report_name.split('+'))
                permission = "email"
            else:
                communities = find_communities(self.context)
                community = communities[target['community']]
                context = community[target['tool']]
                permission = "create"  # XXX In theory could depend on target
            user = users.get_by_id(info['author'])
            if user is not None:
                user = dict(user)
                # XXX check this!
                user['karl.identity'] = {'id': info['author']}

            # BFG Security API always assumes http request, so we fabricate a
            # fake request.
            request = Request.blank('/')
            request.environ['karl.identity'] = user
            request.context = self.context

            if not has_permission(permission, context, request):
                target['error'] = 'Permission Denied'
Example #6
0
    def checkPermission(self, info):
        """ Does user have permission to author content in the given context?

        Uses ACL security policy to test.
        """
        users = find_users(self.context)
        for target in info['targets']:
            if 'error' in target:
                continue
            report_name = target.get('report')
            if report_name is not None:
                pd = find_peopledirectory(self.context)
                context = find_model(pd, report_name.split('+'))
                permission = "email"
            else:
                communities = find_communities(self.context)
                community = communities[target['community']]
                context = community[target['tool']]
                permission = "create"   # XXX In theory could depend on target
            user = users.get_by_id(info['author'])
            if user is not None:
                user = dict(user)
                user['repoze.who.userid'] = info['author']

            # BFG Security API always assumes http request, so we fabricate a
            # fake request.
            request = webob.Request.blank('/')
            request.environ['repoze.who.identity'] = user

            if not has_permission(permission, context, request):
                target['error'] = 'Permission Denied'
Example #7
0
def section_view(context, request):

    subs = [
        sub for sub in context.values() if
        has_permission('view', sub, request) and IPeopleReport.providedBy(sub)
    ]

    if len(subs) == 1:
        return HTTPFound(location=resource_url(subs[0], request))

    api = TemplateAPI(context, request, context.title)
    peopledir = find_peopledirectory(context)
    peopledir_tabs = get_tabs(peopledir, request, context.__name__)
    columns = [{
        'html': render_report_group(x, request, 'column'),
        'width': getattr(x, 'width', 50)
    } for x in context.values()]
    columns = [x for x in columns if x['html']]
    return dict(
        api=api,
        peopledir=peopledir,
        peopledir_tabs=peopledir_tabs,
        context_tools=peopledir_tabs,
        columns=columns,
        actions=get_actions(context, request),
    )
Example #8
0
def evolve(root):
    pd = find_peopledirectory(root)
    for name, section in pd.items():
        acl = getattr(section, '__acl__', [])
        no_inherit = bool(acl) and acl[-1] == DENY_ALL
        if no_inherit:
            acl = acl[:-1]
        acl.append((Allow, 'group.KarlStaff', ('email', )))
        if no_inherit:
            acl.append(DENY_ALL)
        section.__acl__ = acl
Example #9
0
 def test_find_peopledirectory(self):
     from karl.utils import find_peopledirectory
     pd = testing.DummyModel()
     from zope.interface import directlyProvides
     from karl.models.interfaces import IPeopleDirectory
     directlyProvides(pd, IPeopleDirectory)
     site = testing.DummyModel()
     site['people'] = pd
     context = testing.DummyModel()
     pd['obj'] = context
     self.assertEqual(find_peopledirectory(context), pd)
Example #10
0
 def test_find_peopledirectory(self):
     from karl.utils import find_peopledirectory
     pd = testing.DummyModel()
     from zope.interface import directlyProvides
     from karl.models.interfaces import IPeopleDirectory
     directlyProvides(pd, IPeopleDirectory)
     site = testing.DummyModel()
     site['people'] = pd
     context = testing.DummyModel()
     pd['obj'] = context
     self.assertEqual(find_peopledirectory(context), pd)
Example #11
0
def evolve(root):
    pd = find_peopledirectory(root)
    for name, section in pd.items():
        acl = getattr(section, '__acl__', [])
        no_inherit = bool(acl) and acl[-1] == DENY_ALL
        if no_inherit:
            acl = acl[:-1]
        acl.append((Allow, 'group.KarlStaff', ('email',)))
        if no_inherit:
            acl.append(DENY_ALL)
        section.__acl__ = acl
Example #12
0
def admin_contents_movedown_view(context, request):
    peopledir = find_peopledirectory(context)
    api = TemplateAPI(context, request, 'Contents')
    name = request.GET['name']
    order = context.order
    n = order.index(name)
    if n+1 == len(order):
       api.status_message = 'Already at bottom of list'
    else:
       order[n], order[n+1] = order[n+1], order[n]
       context.order = order
    return HTTPFound(location=model_url(context, request, 'admin.html'))
Example #13
0
def admin_contents_moveup_view(context, request):
    peopledir = find_peopledirectory(context)
    api = TemplateAPI(context, request, "Contents")
    name = request.GET["name"]
    order = context.order
    n = order.index(name)
    if n == 0:
        api.status_message = "Already at top of list"
    else:
        order[n], order[n - 1] = order[n - 1], order[n]
        context.order = order
    return HTTPFound(location=resource_url(context, request, "admin.html"))
Example #14
0
def get_report_descriptions(report):
    descriptions = []  # [(value title, description)]
    categories = find_peopledirectory(report)['categories']
    for catid, filter in report.items():
        cat = categories.get(catid)
        if cat:
            for value in filter.values:
                catitem = cat.get(value)
                if catitem:
                    descriptions.append((catitem.title, catitem.description))
    descriptions.sort()
    return [d for (t, d) in descriptions]
Example #15
0
def get_report_descriptions(report):
    descriptions = []  # [(value title, description)]
    categories = find_peopledirectory(report)['categories']
    for catid, filter in report.items():
        cat = categories.get(catid)
        if cat:
            for value in filter.values:
                catitem = cat.get(value)
                if catitem:
                    descriptions.append((catitem.title, catitem.description))
    descriptions.sort()
    return [d for (t, d) in descriptions]
Example #16
0
 def isReport(self, name):
     """ See IMailinDispatcher.
     """
     root = find_root(self.context)
     if name in root.list_aliases:
         return True
     pd = find_peopledirectory(self.context)
     tokens = name.split('+')
     try:
         find_model(pd, tokens)
     except KeyError:
         return False
     return True
Example #17
0
 def isReport(self, name):
     """ See IMailinDispatcher.
     """
     root = find_root(self.context)
     if name in root.list_aliases:
         return True
     pd = find_peopledirectory(self.context)
     tokens = name.split('+')
     try:
         find_resource(pd, tokens)
     except KeyError:
         return False
     return True
Example #18
0
def upload_peopledirectory_xml(context, request):
    peopledir = find_peopledirectory(context)

    if 'form.submit' in request.POST:
        # 'xml' should be the uploaded file.
        xml = request.POST['xml'].file
        tree = etree.parse(xml)
        peopleconf(context, tree, force_reindex=True)
        return HTTPFound(location=resource_url(context, request))

    return dict(api=TemplateAPI(context, request, 'Upload People XML'),
                peopledir=peopledir,
                #actions=get_actions(context, request),
               )
Example #19
0
def upload_peopledirectory_xml(context, request):
    peopledir = find_peopledirectory(context)

    if 'form.submit' in request.POST:
        # 'xml' should be the uploaded file.
        xml = request.POST['xml'].file
        tree = etree.parse(xml)
        peopleconf(context, tree, force_reindex=True)
        return HTTPFound(location=resource_url(context, request))

    return dict(
        api=TemplateAPI(context, request, 'Upload People XML'),
        peopledir=peopledir,
        #actions=get_actions(context, request),
    )
Example #20
0
def admin_contents(context, request):
    peopledir = find_peopledirectory(context)
    api = TemplateAPI(context, request, "Contents")
    if "form.delete" in request.POST:
        if "selected" not in request.POST:
            api.status_message = "Please select a value"
        else:
            selected = request.POST["selected"]
            if isinstance(selected, basestring):
                selected = [selected]
            for name in selected:
                del context[name]
            return HTTPFound(location=resource_url(context, request, "admin.html"))
    actions = get_admin_actions(context, request)
    del actions[0]  # Get rid of "Edit" action--doesn't make sense here.
    actions += get_actions(context, request)
    return dict(api=api, peopledir=peopledir, actions=actions, has_categories=peopledir is context)
Example #21
0
    def process_message(self, message, info, target, text, attachments):
        report_name = target.get('report')
        if report_name is not None:
            pd = find_peopledirectory(self.root)
            context = find_model(pd, report_name.split('+'))
        else:
            community = find_communities(self.root)[target['community']]
            context = tool = community[target['tool']]

            if target['in_reply_to'] is not None:
                docid = int(hex_to_docid(target['in_reply_to']))
                catalog = find_catalog(context)
                path = catalog.document_map.address_for_docid(docid)
                item = find_model(self.root, path)
                context = item

        IMailinHandler(context).handle(message, info, text, attachments)
Example #22
0
    def processMessage(self, message, info, text, attachments):
        report_name = info.get('report')
        if report_name is not None:
            pd = find_peopledirectory(self.root)
            target = find_model(pd, report_name.split('+'))
        else:
            community = find_communities(self.root)[info['community']]
            target = tool = community[info['tool']]

            # XXX this should be more like:
            if info['in_reply_to'] is not None:
                docid = int(hex_to_docid(info['in_reply_to']))
                catalog = find_catalog(target)
                path = catalog.document_map.address_for_docid(docid)
                item = find_model(self.root, path)
                target = item

        IMailinHandler(target).handle(message, info, text, attachments)
Example #23
0
def show_profiles_view(context, request):
    """
    This view is basically deprecated.  If there is a people directory present,
    we'll redirect there.
    """
    people = find_peopledirectory(context)
    if people:
        return HTTPFound(request.resource_url(people))

    # No people directory, show basic listing of profiles
    system_name = get_setting(context, 'system_name', 'KARL')
    page_title = '%s Profiles' % system_name
    api = TemplateAPI(context, request, page_title)

    # Grab the data for the two listings, main communities and portlet
    search = ICatalogSearch(context)

    query = dict(sort_index='title', interfaces=[IProfile], limit=5)

    titlestartswith = request.params.get('titlestartswith')
    if titlestartswith:
        query['titlestartswith'] = (titlestartswith, titlestartswith)

    num, docids, resolver = search(**query)

    profiles = []
    for docid in docids:
        model = resolver(docid)
        if model is None:
            continue
        profiles.append(model)

    mgr = ILetterManager(context)
    letter_info = mgr.get_info(request)

    return render_to_response(
        'templates/profiles.pt',
        dict(api=api,
             profiles=profiles,
             letters=letter_info),
        request=request,
        )
Example #24
0
def admin_contents(context, request):
    peopledir = find_peopledirectory(context)
    api = TemplateAPI(context, request, 'Contents')
    if 'form.delete' in request.POST:
        if 'selected' not in request.POST:
            api.status_message = 'Please select a value'
        else:
            for name in request.POST.getall('selected'):
                del context[name]
            return HTTPFound(
                location=resource_url(context, request, 'admin.html'))
    actions = get_admin_actions(context, request)
    del actions[0]  # Get rid of "Edit" action--doesn't make sense here.
    actions += get_actions(context, request)
    return dict(
        api=api,
        peopledir=peopledir,
        actions=actions,
        has_categories=peopledir is context,
    )
Example #25
0
def admin_contents(context, request):
    peopledir = find_peopledirectory(context)
    api = TemplateAPI(context, request, 'Contents')
    if 'form.delete' in request.POST:
        if 'selected' not in request.POST:
            api.status_message = 'Please select a value'
        else:
            for name in request.POST.getall('selected'):
                del context[name]
            return HTTPFound(location=resource_url(context, request,
                                                'admin.html')
                            )
    actions = get_admin_actions(context, request)
    del actions[0]  # Get rid of "Edit" action--doesn't make sense here.
    actions += get_actions(context, request)
    return dict(api=api,
                peopledir=peopledir,
                actions=actions,
                has_categories=peopledir is context,
               )
Example #26
0
    def process_message(self, message, info, target, text, attachments):
        report_name = target.get('report')
        if report_name is not None:
            pd = find_peopledirectory(self.root)
            context = find_resource(pd, report_name.split('+'))
        else:
            community = find_communities(self.root)[target['community']]
            context = community[target['tool']]

            if target['in_reply_to'] is not None:
                docid = int(hex_to_docid(target['in_reply_to']))
                catalog = find_catalog(context)
                path = catalog.document_map.address_for_docid(docid)
                if path is None:
                    # replied-to content doesn't exist anymore.
                    # Do not process.
                    return 'Content no longer exists.'
                item = find_resource(self.root, path)
                context = item

        IMailinHandler(context).handle(message, info, text, attachments)
Example #27
0
def section_view(context, request):

    subs = [sub for sub in context.values() if has_permission("view", sub, request) and IPeopleReport.providedBy(sub)]

    if len(subs) == 1:
        return HTTPFound(location=resource_url(subs[0], request))

    api = TemplateAPI(context, request, context.title)
    peopledir = find_peopledirectory(context)
    peopledir_tabs = get_tabs(peopledir, request, context.__name__)
    columns = [
        {"html": render_report_group(x, request, "column"), "width": getattr(x, "width", 50)} for x in context.values()
    ]
    columns = [x for x in columns if x["html"]]
    return dict(
        api=api,
        peopledir=peopledir,
        peopledir_tabs=peopledir_tabs,
        columns=columns,
        actions=get_actions(context, request),
    )
Example #28
0
File: mailin.py Project: zagy/karl
    def process_message(self, message, info, target, text, attachments):
        report_name = target.get('report')
        if report_name is not None:
            pd = find_peopledirectory(self.root)
            context = find_resource(pd, report_name.split('+'))
        else:
            community = find_communities(self.root)[target['community']]
            context = community[target['tool']]

            if target['in_reply_to'] is not None:
                docid = int(hex_to_docid(target['in_reply_to']))
                catalog = find_catalog(context)
                path = catalog.document_map.address_for_docid(docid)
                if path is None:
                    # replied-to content doesn't exist anymore.
                    # Do not process.
                    return 'Content no longer exists.'
                item = find_resource(self.root, path)
                context = item

        IMailinHandler(context).handle(message, info, text, attachments)
Example #29
0
def show_profiles_view(context, request):
    """
    This view is basically deprecated.  If there is a people directory present,
    we'll redirect there.
    """
    people = find_peopledirectory(context)
    if people:
        return HTTPFound(request.resource_url(people))

    # No people directory, show basic listing of profiles
    system_name = get_setting(context, 'system_name', 'KARL')
    page_title = '%s Profiles' % system_name
    api = TemplateAPI(context, request, page_title)

    # Grab the data for the two listings, main communities and portlet
    search = ICatalogSearch(context)

    query = dict(sort_index='title', interfaces=[IProfile], limit=5)

    titlestartswith = request.params.get('titlestartswith')
    if titlestartswith:
        query['titlestartswith'] = (titlestartswith, titlestartswith)

    num, docids, resolver = search(**query)

    profiles = []
    for docid in docids:
        model = resolver(docid)
        if model is None:
            continue
        profiles.append(model)

    mgr = ILetterManager(context)
    letter_info = mgr.get_info(request)

    return render_to_response(
        'templates/profiles.pt',
        dict(api=api, profiles=profiles, letters=letter_info),
        request=request,
    )
Example #30
0
def section_view(context, request):

    subs = [sub for sub in context.values()
              if has_permission('view', sub, request) and
                 IPeopleReport.providedBy(sub)]

    if len(subs) == 1:
        return HTTPFound(location=model_url(subs[0], request))

    api = TemplateAPI(context, request, context.title)
    peopledir = find_peopledirectory(context)
    peopledir_tabs = get_tabs(peopledir, request, context.__name__)
    columns = [{'html': render_report_group(x, request, 'column'),
                'width': getattr(x, 'width', 50)}
                        for x in context.values()]
    columns = [x for x in columns if x['html']]
    return dict(api=api,
                peopledir=peopledir,
                peopledir_tabs=peopledir_tabs,
                columns=columns,
                actions=get_actions(context, request),
               )
Example #31
0
def section_view(context, request):
    if not context.columns:
        if len(context) == 1:
            # display the single report as the content of this section
            report = context.values()[0]
            if has_permission('view', report, request):
                return report_view(report, request)
            raise Forbidden("Report is not accessible")

    api = TemplateAPI(context, request, context.title)
    peopledir = find_peopledirectory(context)
    peopledir_tabs = get_tabs(peopledir, request, context.__name__)
    column_html = [render_report_group(column, request, 'column')
        for column in context.columns]
    return render_template_to_response(
        'templates/people_section.pt',
        api=api,
        peopledir=peopledir,
        peopledir_tabs=peopledir_tabs,
        column_html=column_html,
        actions=get_actions(context, request),
        )
Example #32
0
    def create(self, container):
        """
        container is root['people'].categories, or moral equivalent.
        """
        title = _element_value(self, self.element, 'title')
        sync_id = self.element.get('id')
        name = make_name(container, title)
        description = _element_value(self, self.element, 'description')

        category_element = self.element.find(self.NS_PREFIX + 'category')
        category_id = category_element.get('id')
        category = container.get(category_id, None)
        if category is None:
            category = PeopleCategory(category_element.text.strip())
            container[category_id] = category
            peopledir = find_peopledirectory(container)
            notify(PeopleDirectorySchemaChanged(peopledir))

        category_item = PeopleCategoryItem(title, description)
        if sync_id is not None:
            category_item.sync_id = sync_id # OSI artifact

        category[name] = category_item
Example #33
0
def main():
    parser = OptionParser(description=__doc__)
    parser.add_option('-C', '--config', dest='config', default=None,
        help="Specify a paster config file. Defaults to $CWD/etc/karl.ini")
    parser.add_option('-d', '--dry-run', dest='dry_run',
        action="store_true", default=False,
        help="Don't commit the transactions")

    options, args = parser.parse_args()
    if args:
        parser.error("Too many parameters: %s" % repr(args))

    config = options.config
    if config is None:
        config = get_default_config()
    root, closer = open_root(config)

    peopledir = find_peopledirectory(root)
    reindex_peopledirectory(peopledir)

    if options.dry_run:
        transaction.abort()
    else:
        transaction.commit()
Example #34
0
def report_view(context, request, pictures=False):
    api = TemplateAPI(context, request, context.title)
    peopledir = find_peopledirectory(context)
    section = context.__parent__
    section_name = section.__name__
    while section and not IPeopleSection.providedBy(section):
        section = section.__parent__
    if section:
        section_name = section.__name__
    peopledir_tabs = get_tabs(peopledir, request, section_name)

    # make the max limit here ridiculously huge so the frontend can just deal
    # with rendering all of the data. this should scale fairly well up to
    # quite large datasets (several thousand if not tens of thousands) -- if
    # it starts becoming an issue, then the limit will need to be reduced, and
    # the client lib updated to handle the paging interaction with the backend
    report_data = get_grid_data(context, request, limit=2147483647)

    batch = report_data['batch']
    if pictures:
        rows = profile_photo_rows(batch['entries'], request, api)
    else:
        rows = None
    del(report_data['batch']) # non-json serializable
    client_json_data = {'grid_data': report_data}


    descriptions = get_report_descriptions(context)
    mgr = ILetterManager(context)
    letter_info = mgr.get_info(request)

    kw, qualifiers = get_search_qualifiers(request)
    print_url = resource_url(context, request, 'print.html', **kw)
    csv_url = resource_url(context, request, 'csv', **kw)
    pictures_url = resource_url(context, request, 'picture_view.html', **kw)
    tabular_url = resource_url(context, request, **kw)
    opensearch_url = resource_url(context, request, 'opensearch.xml')
    mailto=_get_mailto(context, peopledir)

    actions = [
        {'name': 'print', 'title': 'Print',
         'description': 'Print this report', 'bs-icon': 'icon-print',
         'url': request.resource_url(context, 'print.html')},
        {'name': 'csv', 'title': 'Export as CSV',
         'description': 'Export this report as CSV', 'bs-icon': 'icon-download',
         'url': request.resource_url(context, 'csv')}]

    if mailto:
        actions.insert(0, {
            'name': 'email', 'title': 'Email', 'bs-icon': 'icon-envelope',
            'description': 'Email', 'url': mailto})

    if opensearch_url:
        actions.insert(0, {
            'name': 'opensearch', 'title': 'Opensearch',
            'bs-icon': 'icon-search',
            'description': 'Add KARL People Search to your browser toolbar',
            'url': "javascript:window.external.AddSearchProvider('%s');" %
                   opensearch_url})

    return dict(
        api=api,
        peopledir=peopledir,
        peopledir_tabs=peopledir_tabs,
        context_tools=peopledir_tabs,
        batch_info=batch,
        head_data=convert_to_script(client_json_data),
        rows=rows,
        descriptions=descriptions,
        letters=letter_info,
        print_url=print_url,
        csv_url=csv_url,
        pictures_url=pictures_url,
        tabular_url=tabular_url,
        qualifiers=qualifiers,
        opensearch_url=opensearch_url,
        actions=get_actions(context, request),
        mailto=mailto,
    )
Example #35
0
def picture_view(context, request):
    sort_index = COLUMNS[context.columns[0]].sort_index

    kw = get_report_query(context, request)
    try:
        batch_info = get_catalog_batch_grid(
            context, request, batch_size=12, sort_index=sort_index, **kw)
    except ParseError, e:
        # user entered something weird in the text search box.
        # show no results.
        batch_info = {'entries': [], 'total': 0, 'batching_required': False}

    api = TemplateAPI(context, request, context.title)
    rows = profile_photo_rows(batch_info['entries'], request, api)

    peopledir = find_peopledirectory(context)
    section = context.__parent__
    peopledir_tabs = get_tabs(peopledir, request, section.__name__)

    mgr = ILetterManager(context)
    letter_info = mgr.get_info(request)
    kw, qualifiers = get_search_qualifiers(request)

    descriptions = get_report_descriptions(context)
    print_url = model_url(context, request, 'print.html', **kw)
    csv_url = model_url(context, request, 'csv', **kw)
    tabular_url = model_url(context, request, **kw)

    return render_template_to_response(
        'templates/people_pictures.pt',
        api=api,
Example #36
0
def evolve(context):
    remove_broken_objects(context['profiles'], sys.stdout)

    print "Reindexing people directory"
    peopledir = find_peopledirectory(context)
    reindex_peopledirectory(peopledir)
Example #37
0
def report_view(context, request, pictures=False):
    api = TemplateAPI(context, request, context.title)
    peopledir = find_peopledirectory(context)
    section = context.__parent__
    section_name = section.__name__
    while section and not IPeopleSection.providedBy(section):
        section = section.__parent__
    if section:
        section_name = section.__name__
    peopledir_tabs = get_tabs(peopledir, request, section_name)
    report_data = get_grid_data(context, request)
    
    # ux2 slickgrid only
    widgets = {
        'peoplegrid': report_data['slickgrid_info']['widget_options'], 
        #{
            ##'loadData': [],   ##     search_folder(context, request,
                ##from_=0,
                ##to=_pre_fetch,
                ##sort_col='modified',
                ##sort_dir=-1,
                # XXX hint from ux1
                ##_raw_get_container_batch=_raw_get_container_batch,
                #),
            ##'url': resource_url(context, request, 'peoplegrid.json'),
            #},
        }




    batch = report_data['batch']
    if pictures:
        rows = profile_photo_rows(batch['entries'], request, api)
    else:
        rows = None
    del(report_data['batch']) # non-json serializable
    client_json_data = {'grid_data': report_data}


    descriptions = get_report_descriptions(context)
    mgr = ILetterManager(context)
    letter_info = mgr.get_info(request)

    kw, qualifiers = get_search_qualifiers(request)
    print_url = resource_url(context, request, 'print.html', **kw)
    csv_url = resource_url(context, request, 'csv', **kw)
    pictures_url = resource_url(context, request, 'picture_view.html', **kw)
    tabular_url = resource_url(context, request, **kw)
    opensearch_url = resource_url(context, request, 'opensearch.xml')
    mailto=_get_mailto(context, peopledir)

    formats = [   # ux2
        {'name': 'tabular',
         'selected': not pictures,
         'bs-icon': 'icon-th-list',
         'url': tabular_url,
         'title': 'Tabular View',
         'description': 'Show table'},
        {'name': 'picture',
         'selected': pictures,
         'bs-icon': 'icon-th',
         'url': pictures_url,
         'title': 'Picture View',
         'description': 'Show pictures'}
    ]

    actions = [
        {'name': 'print', 'title': 'Print',
         'description': 'Print this report', 'bs-icon': 'icon-print',
         'url': request.resource_url(context, 'print.html')},
        {'name': 'csv', 'title': 'Export as CSV',
         'description': 'Export this report as CSV', 'bs-icon': 'icon-download',
         'url': request.resource_url(context, 'csv')}]

    if mailto:
        actions.insert(0, {
            'name': 'email', 'title': 'Email', 'bs-icon': 'icon-envelope',
            'description': 'Email', 'url': mailto})

    if opensearch_url:
        actions.insert(0, {
            'name': 'opensearch', 'title': 'Opensearch',
            'bs-icon': 'icon-search',
            'description': 'Add KARL People Search to your browser toolbar',
            'url': "javascript:window.external.AddSearchProvider('%s');" %
                   opensearch_url})

    return dict(
        api=api,   # deprecated in ux2
        peopledir=peopledir,   # deprecated in ux2
        peopledir_tabs=peopledir_tabs, # deprecated in ux2
        context_tools=peopledir_tabs,
        head_data=convert_to_script(client_json_data), # deprecated in ux2
        report_data=report_data, # ux2
        batch_info=batch, # deprecated in ux2
        batch=batch, # ux2
        rows=rows,
        descriptions=descriptions,
        letters=letter_info,
        formats=formats, # ux2
        report_actions=actions, # ux2
        print_url=print_url,        # deprecated in ux2
        csv_url=csv_url,            # deprecated in ux2
        pictures_url=pictures_url,  # deprecated in ux2
        tabular_url=tabular_url,    # deprecated in ux2
        qualifiers=qualifiers,      # deprecated in ux2
        opensearch_url=opensearch_url, # deprecated in ux2
        actions=get_actions(context, request),
        mailto=mailto,              # deprecated in ux2
        widgets=widgets, # ux2 with karlgrid (slickgrid)
    )
Example #38
0
def report_view(context, request, pictures=False):
    api = TemplateAPI(context, request, context.title)
    peopledir = find_peopledirectory(context)
    section = context.__parent__
    section_name = section.__name__
    while section and not IPeopleSection.providedBy(section):
        section = section.__parent__
    if section:
        section_name = section.__name__
    peopledir_tabs = get_tabs(peopledir, request, section_name)
    report_data = get_grid_data(context, request)

    batch = report_data['batch']
    if pictures:
        rows = profile_photo_rows(batch['entries'], request, api)
    else:
        rows = None
    del (report_data['batch'])  # non-json serializable
    client_json_data = {'grid_data': report_data}

    descriptions = get_report_descriptions(context)
    mgr = ILetterManager(context)
    letter_info = mgr.get_info(request)

    kw, qualifiers = get_search_qualifiers(request)
    print_url = resource_url(context, request, 'print.html', **kw)
    csv_url = resource_url(context, request, 'csv', **kw)
    pictures_url = resource_url(context, request, 'picture_view.html', **kw)
    tabular_url = resource_url(context, request, **kw)
    opensearch_url = resource_url(context, request, 'opensearch.xml')
    mailto = _get_mailto(context, peopledir)

    actions = [{
        'name': 'print',
        'title': 'Print',
        'description': 'Print this report',
        'bs-icon': 'icon-print',
        'url': request.resource_url(context, 'print.html')
    }, {
        'name': 'csv',
        'title': 'Export as CSV',
        'description': 'Export this report as CSV',
        'bs-icon': 'icon-download',
        'url': request.resource_url(context, 'csv')
    }]

    if mailto:
        actions.insert(
            0, {
                'name': 'email',
                'title': 'Email',
                'bs-icon': 'icon-envelope',
                'description': 'Email',
                'url': mailto
            })

    if opensearch_url:
        actions.insert(
            0, {
                'name':
                'opensearch',
                'title':
                'Opensearch',
                'bs-icon':
                'icon-search',
                'description':
                'Add KARL People Search to your browser toolbar',
                'url':
                "javascript:window.external.AddSearchProvider('%s');" %
                opensearch_url
            })

    return dict(
        api=api,
        peopledir=peopledir,
        peopledir_tabs=peopledir_tabs,
        context_tools=peopledir_tabs,
        batch_info=batch,
        head_data=convert_to_script(client_json_data),
        rows=rows,
        descriptions=descriptions,
        letters=letter_info,
        print_url=print_url,
        csv_url=csv_url,
        pictures_url=pictures_url,
        tabular_url=tabular_url,
        qualifiers=qualifiers,
        opensearch_url=opensearch_url,
        actions=get_actions(context, request),
        mailto=mailto,
    )
Example #39
0
def report_view(context, request, pictures=False):
    api = TemplateAPI(context, request, context.title)
    peopledir = find_peopledirectory(context)
    section = context.__parent__
    section_name = section.__name__
    while section and not IPeopleSection.providedBy(section):
        section = section.__parent__
    if section:
        section_name = section.__name__
    peopledir_tabs = get_tabs(peopledir, request, section_name)
    report_data = get_grid_data(context, request)

    # ux2 slickgrid only
    widgets = {
        'peoplegrid': report_data['slickgrid_info']['widget_options'],
        #{
        ##'loadData': [],   ##     search_folder(context, request,
        ##from_=0,
        ##to=_pre_fetch,
        ##sort_col='modified',
        ##sort_dir=-1,
        # XXX hint from ux1
        ##_raw_get_container_batch=_raw_get_container_batch,
        #),
        ##'url': resource_url(context, request, 'peoplegrid.json'),
        #},
    }

    batch = report_data['batch']
    if pictures:
        rows = profile_photo_rows(batch['entries'], request, api)
    else:
        rows = None
    del (report_data['batch'])  # non-json serializable
    client_json_data = {'grid_data': report_data}

    descriptions = get_report_descriptions(context)
    mgr = ILetterManager(context)
    letter_info = mgr.get_info(request)

    kw, qualifiers = get_search_qualifiers(request)
    print_url = resource_url(context, request, 'print.html', **kw)
    csv_url = resource_url(context, request, 'csv', **kw)
    pictures_url = resource_url(context, request, 'picture_view.html', **kw)
    tabular_url = resource_url(context, request, **kw)
    opensearch_url = resource_url(context, request, 'opensearch.xml')
    mailto = _get_mailto(context, peopledir)

    formats = [  # ux2
        {
            'name': 'tabular',
            'selected': not pictures,
            'bs-icon': 'icon-th-list',
            'url': tabular_url,
            'title': 'Tabular View',
            'description': 'Show table'
        }, {
            'name': 'picture',
            'selected': pictures,
            'bs-icon': 'icon-th',
            'url': pictures_url,
            'title': 'Picture View',
            'description': 'Show pictures'
        }
    ]

    actions = [{
        'name': 'print',
        'title': 'Print',
        'description': 'Print this report',
        'bs-icon': 'icon-print',
        'url': request.resource_url(context, 'print.html')
    }, {
        'name': 'csv',
        'title': 'Export as CSV',
        'description': 'Export this report as CSV',
        'bs-icon': 'icon-download',
        'url': request.resource_url(context, 'csv')
    }]

    if mailto:
        actions.insert(
            0, {
                'name': 'email',
                'title': 'Email',
                'bs-icon': 'icon-envelope',
                'description': 'Email',
                'url': mailto
            })

    if opensearch_url:
        actions.insert(
            0, {
                'name':
                'opensearch',
                'title':
                'Opensearch',
                'bs-icon':
                'icon-search',
                'description':
                'Add KARL People Search to your browser toolbar',
                'url':
                "javascript:window.external.AddSearchProvider('%s');" %
                opensearch_url
            })

    return dict(
        api=api,  # deprecated in ux2
        peopledir=peopledir,  # deprecated in ux2
        peopledir_tabs=peopledir_tabs,  # deprecated in ux2
        context_tools=peopledir_tabs,
        head_data=convert_to_script(client_json_data),  # deprecated in ux2
        report_data=report_data,  # ux2
        batch_info=batch,  # deprecated in ux2
        batch=batch,  # ux2
        rows=rows,
        descriptions=descriptions,
        letters=letter_info,
        formats=formats,  # ux2
        report_actions=actions,  # ux2
        print_url=print_url,  # deprecated in ux2
        csv_url=csv_url,  # deprecated in ux2
        pictures_url=pictures_url,  # deprecated in ux2
        tabular_url=tabular_url,  # deprecated in ux2
        qualifiers=qualifiers,  # deprecated in ux2
        opensearch_url=opensearch_url,  # deprecated in ux2
        actions=get_actions(context, request),
        mailto=mailto,  # deprecated in ux2
        widgets=widgets,  # ux2 with karlgrid (slickgrid)
    )
Example #40
0
def evolve(context):
    remove_broken_objects(context['profiles'], sys.stdout)

    print "Reindexing people directory"
    peopledir = find_peopledirectory(context)
    reindex_peopledirectory(peopledir)
Example #41
0
def report_view(context, request, pictures=False):
    api = TemplateAPI(context, request, context.title)
    peopledir = find_peopledirectory(context)
    section = context.__parent__
    section_name = section.__name__
    while section and not IPeopleSection.providedBy(section):
        section = section.__parent__
    if section:
        section_name = section.__name__
    peopledir_tabs = get_tabs(peopledir, request, section_name)

    # make the max limit here ridiculously huge so the frontend can just deal
    # with rendering all of the data. this should scale fairly well up to
    # quite large datasets (several thousand if not tens of thousands) -- if
    # it starts becoming an issue, then the limit will need to be reduced, and
    # the client lib updated to handle the paging interaction with the backend
    report_data = get_grid_data(context, request, limit=2147483647)

    batch = report_data['batch']
    if pictures:
        rows = profile_photo_rows(batch['entries'], request, api)
    else:
        rows = None
    del (report_data['batch'])  # non-json serializable
    client_json_data = {'grid_data': report_data}

    descriptions = get_report_descriptions(context)
    mgr = ILetterManager(context)
    letter_info = mgr.get_info(request)

    kw, qualifiers = get_search_qualifiers(request)
    print_url = resource_url(context, request, 'print.html', **kw)
    csv_url = resource_url(context, request, 'csv', **kw)
    pictures_url = resource_url(context, request, 'picture_view.html', **kw)
    tabular_url = resource_url(context, request, **kw)
    opensearch_url = resource_url(context, request, 'opensearch.xml')
    mailto = _get_mailto(context, peopledir)

    actions = [{
        'name': 'print',
        'title': 'Print',
        'description': 'Print this report',
        'bs-icon': 'icon-print',
        'url': request.resource_url(context, 'print.html')
    }, {
        'name': 'csv',
        'title': 'Export as CSV',
        'description': 'Export this report as CSV',
        'bs-icon': 'icon-download',
        'url': request.resource_url(context, 'csv')
    }]

    if mailto:
        actions.insert(
            0, {
                'name': 'email',
                'title': 'Email',
                'bs-icon': 'icon-envelope',
                'description': 'Email',
                'url': mailto
            })

    if opensearch_url:
        actions.insert(
            0, {
                'name':
                'opensearch',
                'title':
                'Opensearch',
                'bs-icon':
                'icon-search',
                'description':
                'Add KARL People Search to your browser toolbar',
                'url':
                "javascript:window.external.AddSearchProvider('%s');" %
                opensearch_url
            })

    return dict(
        api=api,
        peopledir=peopledir,
        peopledir_tabs=peopledir_tabs,
        context_tools=peopledir_tabs,
        batch_info=batch,
        head_data=convert_to_script(client_json_data),
        rows=rows,
        descriptions=descriptions,
        letters=letter_info,
        print_url=print_url,
        csv_url=csv_url,
        pictures_url=pictures_url,
        tabular_url=tabular_url,
        qualifiers=qualifiers,
        opensearch_url=opensearch_url,
        actions=get_actions(context, request),
        mailto=mailto,
    )