Example #1
0
def dump_distribution_info_report(context, db_statement):
    gen = gen_metadata(db_statement)
    metadatas = [m for m in gen if m['isTemplate'] == 'n']

    document_icon = context.registry['document_icon']
    url_icon = context.registry['url_icon']
    jstree = []
    for m in metadatas:
        data = m['data'].encode('utf-8')
        title = get_title(data)
        url_list = get_distribution_info(data)
        url_tree = []
        for url in url_list:
            url_tree.append({
                'data': {
                    'title': url,
                    'icon': url_icon,
                    'attributes': {
                        'href': url
                    }
                }
            })
        jstree.append({
            'data': {
                'title': title,
                'icon': document_icon
            },
            'children': url_tree
        })

    with output_file(context, 'report_distribution_info') as f:
        f.write(json.dumps(jstree))
def dump_points_of_contact_report(context, db_statement):
    gen = gen_metadata(db_statement)
    metadatas = [m for m in gen if m['isTemplate'] == 'n']
    organisations = {}
    organisations2 = {}
    for m in metadatas:
        id = str(m['id'])
        data = m['data'].encode('utf-8')
        title = get_title(data)
        contacts = get_points_of_contact(data)
        for c in contacts:
            org_name = c.get('organisation', '')
            if type(c.get('email', [])) == type([]):
                emails = c.get('email', [])
            else:
                emails = [c.get('email', '')]
            role = c.get('role', '')
            
            if org_name not in organisations:
                organisations[org_name] = {}
            if title not in organisations[org_name]:
                organisations[org_name][title] = {}
            if role not in organisations[org_name][title]:
                organisations[org_name][title][role] = []
            organisations[org_name][title][role].extend(emails)
    
    organisation_icon = context.registry['organisation_icon'] 
    document_icon = context.registry['document_icon']
    role_icon = context.registry['role_icon']
    email_icon = context.registry['email_icon']
    jstree = []
    for org, v in organisations.iteritems():
        doc_tree = []
        for title, v2 in v.iteritems():
            role_tree = []
            for role, emails in v2.iteritems():
                email_tree = []
                for email in emails:
                    email_tree.append({'data': {'title': email, 'icon': email_icon, 'attributes': {'href': 'mailto:'+email}}})
                role_tree.append({'data': {'title': role, 'icon': role_icon}, 'children': email_tree})
            if len(role_tree) == 1 and role_tree[0]['data']['title'] == '':
                email_tree = role_tree[0]['children']
                doc_tree.append({'data': {'title': title, 'icon': document_icon}, 'children': email_tree})
            else:
                doc_tree.append({'data': {'title': title, 'icon': document_icon}, 'children': role_tree})
        jstree.append({'data': {'title': org, 'icon': organisation_icon}, 'state': 'open', 'children': doc_tree})

    with output_file(context, 'report_points_of_contact') as f:
        f.write(json.dumps(jstree))
def dump_distribution_info_report(context, db_statement):
    gen = gen_metadata(db_statement)
    metadatas = [m for m in gen if m['isTemplate'] == 'n']

    document_icon = context.registry['document_icon']
    url_icon = context.registry['url_icon']   
    jstree = []
    for m in metadatas:
        data = m['data'].encode('utf-8')
        title = get_title(data)
        url_list = get_distribution_info(data)
        url_tree = []
        for url in url_list:
            url_tree.append({'data': {'title': url, 'icon': url_icon, 'attributes': {'href': url}}})
        jstree.append({'data': {'title': title, 'icon': document_icon}, 'children': url_tree})

    with output_file(context, 'report_distribution_info') as f:
        f.write(json.dumps(jstree))
Example #4
0
def dump_points_of_contact_report(context, db_statement):
    gen = gen_metadata(db_statement)
    metadatas = [m for m in gen if m['isTemplate'] == 'n']
    organisations = {}
    organisations2 = {}
    for m in metadatas:
        id = str(m['id'])
        data = m['data'].encode('utf-8')
        title = get_title(data)
        contacts = get_points_of_contact(data)
        for c in contacts:
            org_name = c.get('organisation', '')
            if type(c.get('email', [])) == type([]):
                emails = c.get('email', [])
            else:
                emails = [c.get('email', '')]
            role = c.get('role', '')

            if org_name not in organisations:
                organisations[org_name] = {}
            if title not in organisations[org_name]:
                organisations[org_name][title] = {}
            if role not in organisations[org_name][title]:
                organisations[org_name][title][role] = []
            organisations[org_name][title][role].extend(emails)

    organisation_icon = context.registry['organisation_icon']
    document_icon = context.registry['document_icon']
    role_icon = context.registry['role_icon']
    email_icon = context.registry['email_icon']
    jstree = []
    for org, v in organisations.iteritems():
        doc_tree = []
        for title, v2 in v.iteritems():
            role_tree = []
            for role, emails in v2.iteritems():
                email_tree = []
                for email in emails:
                    email_tree.append({
                        'data': {
                            'title': email,
                            'icon': email_icon,
                            'attributes': {
                                'href': 'mailto:' + email
                            }
                        }
                    })
                role_tree.append({
                    'data': {
                        'title': role,
                        'icon': role_icon
                    },
                    'children': email_tree
                })
            if len(role_tree) == 1 and role_tree[0]['data']['title'] == '':
                email_tree = role_tree[0]['children']
                doc_tree.append({
                    'data': {
                        'title': title,
                        'icon': document_icon
                    },
                    'children': email_tree
                })
            else:
                doc_tree.append({
                    'data': {
                        'title': title,
                        'icon': document_icon
                    },
                    'children': role_tree
                })
        jstree.append({
            'data': {
                'title': org,
                'icon': organisation_icon
            },
            'state': 'open',
            'children': doc_tree
        })

    with output_file(context, 'report_points_of_contact') as f:
        f.write(json.dumps(jstree))