Example #1
0
def search_service(request):
    filters = {}
    objects = []

    if 'entityid' in request.GET:
        form = ServiceSearchForm(request.GET)
        if form.is_valid():
            entityid = form.cleaned_data['entityid']
            entityid = entityid.strip()
            filters['entityid__icontains'] = entityid
    else:
        form = ServiceSearchForm()
    entity_type = request.GET.get('entity_type', None)

    if entity_type:
        filters['entity_type'] = entity_type

    if filters:
        objects = Entity.objects.filter(**filters)

    if objects and 'format' in request.GET.keys():
        entities = []
        for entity in objects:
            entities.append({
                'entityid':
                entity.entityid,
                'name':
                entity.name,
                'absolute_url':
                entity.get_absolute_url(),
                'types': [unicode(item) for item in entity.types.all()],
                'federations': [(unicode(item.name), item.get_absolute_url())
                                for item in entity.federations.all()],
            })

        return export_query_set(request.GET.get('format'), entities,
                                'entities_search_result',
                                ('entityid', 'types', 'federations'))

    entities = []
    for entity in objects:
        entities.append({
            'entityid':
            entity.entityid,
            'name':
            entity.name,
            'absolute_url':
            entity.get_absolute_url(),
            'types': [unicode(item) for item in entity.types.all()],
            'federations': [(unicode(item.name), item.get_absolute_url())
                            for item in entity.federations.all()],
        })

    return render_to_response('metadataparser/service_search.html', {
        'settings': settings,
        'searchform': form,
        'object_list': entities,
        'show_filters': False,
    },
                              context_instance=RequestContext(request))
Example #2
0
def search_service(request):
    filters = {}
    objects = []
    if request.method == 'GET':
        if 'entityid' in request.GET:
            form = ServiceSearchForm(request.GET)
            if form.is_valid():
                entityid = form.cleaned_data['entityid']
                entityid = entityid.strip()
                filters['entityid__icontains'] = entityid

        else:
            form = ServiceSearchForm()
        entity_type = request.GET.get('entity_type', None)
        if entity_type:
            filters['entity_type'] = entity_type
        if filters:
            objects = Entity.objects.filter(**filters)

    if objects and 'format' in request.GET.keys():
        return export_query_set(request.GET.get('format'), objects,
                                'entities_search_result', ('', 'types', 'federations'))

    return render_to_response('metadataparser/service_search.html',
        {'searchform': form,
         'object_list': objects,
         'show_filters': False,
        }, context_instance=RequestContext(request))
Example #3
0
def federation_view(request, federation_slug=None):
    if federation_slug:
        request.session['%s_process_done' % federation_slug] = False
        request.session['%s_num_entities' % federation_slug] = 0
        request.session['%s_cur_entities' % federation_slug] = 0
        request.session.save()

    federation = get_object_or_404(Federation, slug=federation_slug)

    entity_type = None
    if request.GET and 'entity_type' in request.GET:
        entity_type = request.GET['entity_type']
        ob_entities = Entity.objects.filter(federations__id=federation.id).filter(types__xmlname=entity_type)
    else:
        ob_entities = Entity.objects.filter(federations__id=federation.id)
    
    ob_entities = ob_entities.prefetch_related('types', 'federations')
    pagination = _paginate_fed(ob_entities, request.GET.get('page'))

    entities = []
    for entity in ob_entities:
        entities.append({
            'entityid': entity.entityid,
            'name': entity.name,
            'absolute_url': entity.get_absolute_url(),
            'types': [unicode(item) for item in entity.types.all()],
            'federations': [(unicode(item.name), item.get_absolute_url()) for item in entity.federations.all()],
        })

    if 'format' in request.GET:
        return export_query_set(request.GET.get('format'), entities,
                                'entities_search_result', ('entityid', 'types', 'federations'))

    context = RequestContext(request)
    user = context.get('user', None)
    add_entity = user and user.has_perm('metadataparser.add_federation')
    pie_chart = fed_pie_chart(request, federation.id)

    return render_to_response('metadataparser/federation_view.html',
            {'settings': settings,
             'federation': federation,
             'entity_types': DESCRIPTOR_TYPES,
             'entity_type': entity_type or 'All',
             'fed_types': dict(FEDERATION_TYPES),
             'entities': entities,
             'show_filters': True,
             'add_entity': add_entity,
             'lang': request.GET.get('lang', 'en'),
             'update_entities': request.GET.get('update', 'false'),
             'statcharts': [pie_chart],
             'pagination': pagination,
            }, context_instance=context)
Example #4
0
File: views.py Project: GEANT/met
def search_service(request):
    filters = {}
    objects = []

    if 'entityid' in request.GET:
        form = ServiceSearchForm(request.GET)
        if form.is_valid():
            entityid = form.cleaned_data['entityid']
            entityid = entityid.strip()
            filters['entityid__icontains'] = entityid
    else:
        form = ServiceSearchForm()
    entity_type = request.GET.get('entity_type', None)

    if entity_type:
        filters['entity_type'] = entity_type

    if filters:
        objects = Entity.objects.filter(**filters)

    if objects and 'format' in request.GET.keys():
        entities = []
        for entity in objects:
            entities.append({
                'entityid': entity.entityid,
                'name': entity.name,
                'absolute_url': entity.get_absolute_url(),
                'types': [unicode(item) for item in entity.types.all()],
                'federations': [(unicode(item.name), item.get_absolute_url()) for item in entity.federations.all()],
            })

        return export_query_set(request.GET.get('format'), entities,
                                'entities_search_result', ('entityid', 'types', 'federations'))

    entities = []
    for entity in objects:
        entities.append({
            'entityid': entity.entityid,
            'name': entity.name,
            'absolute_url': entity.get_absolute_url(),
            'types': [unicode(item) for item in entity.types.all()],
            'federations': [(unicode(item.name), item.get_absolute_url()) for item in entity.federations.all()],
        })

    return render_to_response('metadataparser/service_search.html',
        {'settings': settings,
         'searchform': form,
         'object_list': entities,
         'show_filters': False,
        }, context_instance=RequestContext(request))
Example #5
0
def _index_export(export, export_format, objects):
    counters = (
                ('all', {}),
                ('IDPSSO', {'types__xmlname': 'IDPSSODescriptor'}),
                ('SPSSO', {'types__xmlname': 'SPSSODescriptor'}),
               )

    if not export in ['interfederations', 'federations', 'most_federated_entities']:
        return HttpResponseBadRequest('Not valid export query')

    if export == 'most_federated_entities':
        return export_query_set(export_format, objects['most_federated_entities'],
                                'most_federated_entities', ('entityid', 'types', 'name', 'federations'))
    else:
        return export_summary(export_format, objects[export],
                              'entity_set', '%s_summary' % export,
                              counters)
Example #6
0
File: views.py Project: GEANT/met
def _index_export(export, export_format, objects):
    counters = (
                ('all', {}),
                ('IDPSSO', {'types__xmlname': 'IDPSSODescriptor'}),
                ('SPSSO', {'types__xmlname': 'SPSSODescriptor'}),
               )

    if not export in ['interfederations', 'federations', 'most_federated_entities']:
        return HttpResponseBadRequest('Not valid export query')

    if export == 'most_federated_entities':
        return export_query_set(export_format, objects['most_federated_entities'],
                                'most_federated_entities', ('entityid', 'types', 'name', 'federations'))
    else:
        return export_summary(export_format, objects[export],
                              'entity_set', '%s_summary' % export,
                              counters)
Example #7
0
def federation_view(request, federation_slug=None):
    federation = get_object_or_404(Federation, slug=federation_slug)

    entity_type = None
    if (request.GET and 'entity_type' in request.GET):
        entity_type = request.GET['entity_type']
        entities_id = federation._metadata.entities_by_type(entity_type)
        entities = Entity.objects.filter(entityid__in=entities_id)
    else:
        entities = Entity.objects.filter(federations__id=federation.id)

    if 'format' in request.GET:
        return export_query_set(request.GET.get('format'), entities,
                                'entities_search_result', ('', 'types', 'federations'))
    return render_to_response('metadataparser/federation_view.html',
            {'federation': federation,
             'entity_type': entity_type or 'All',
             'entities': entities,
             'show_filters': True,
            }, context_instance=RequestContext(request))
Example #8
0
def index(request):
    federations = Federation.objects.filter(is_interfederation=False)

    interfederations = Federation.objects.filter(is_interfederation=True)

    # Entities with count how many federations belongs to, and sorted by most first
    most_federated_entities = Entity.get_most_federated_entities(cache_expire=(24 * 60 * 60))

    export = request.GET.get('export', None)
    format = request.GET.get('format', None)
    if export and format:
        counters = (
                    ('all', {}),
                    ('IDPSSO', {'types__xmlname': 'IDPSSODescriptor'}),
                    ('SPSSO', {'types__xmlname': 'SPSSODescriptor'}),
                   )
        if export == 'interfederations':
            return export_summary(request.GET.get('format'), interfederations,
                                  'entity_set', 'interfederations_summary',
                                  counters)

        elif export == 'federations':
            return export_summary(request.GET.get('format'), federations,
                                  'entity_set', 'federations_summary',
                                  counters)
        elif export == 'most_federated_entities':
            return export_query_set(request.GET.get('format'), most_federated_entities,
                                'most_federated_entities', ('', 'types', 'federations'))
        else:
            return HttpResponseBadRequest('Not valid export query')

    return render_to_response('metadataparser/index.html', {
           'interfederations': interfederations,
           'federations': federations,
           'entities': Entity.objects.all(),
           'entity_types': DESCRIPTOR_TYPES,
           'most_federated_entities': most_federated_entities,
           }, context_instance=RequestContext(request))
Example #9
0
def search_entities(request):
    if request.method == 'POST':
        form = SearchEntitiesForm(request.POST)

        if form.is_valid():
            filters = {}
            args = ()

            entity_type = form.cleaned_data['entity_type']
            if entity_type and entity_type != 'All':
                filters['types__name'] = entity_type

            entity_category = form.cleaned_data['entity_category']
            if entity_category and entity_category != 'All':
                filters['entity_categories__category_id'] = entity_category

            federations = form.cleaned_data['federations']
            if federations and not 'All' in federations:
                q_list = [Q(federations__id=f) for f in federations]
                args = (reduce(operator.or_, q_list), )

            entity_id = form.cleaned_data['entityid']
            if entity_id and entity_id != '':
                filters['entityid__icontains'] = entity_id

            ob_entities = Entity.objects.all()
            if args:
                ob_entities = ob_entities.filter(*args)
            if filters:
                ob_entities = ob_entities.filter(**filters)

            ob_entities = ob_entities.prefetch_related('types', 'federations')
            pagination = _paginate_fed(ob_entities, form.cleaned_data['page'])

            entities = []
            for entity in pagination['objects']:
                entities.append({
                    'entityid':
                    entity.entityid,
                    'name':
                    entity.name,
                    'absolute_url':
                    entity.get_absolute_url(),
                    'types': [unicode(item) for item in entity.types.all()],
                    'federations':
                    [(unicode(item.name), item.get_absolute_url())
                     for item in entity.federations.all()],
                })

            export_format = form.cleaned_data['export_format']
            if export_format:
                return export_query_set(export_format, entities,
                                        'entities_search_result',
                                        ('entityid', 'types', 'federations'))

            return render_to_response('metadataparser/search_entities.html', {
                'settings': settings,
                'form': form,
                'object_list': entities,
                'show_filters': False,
                'pagination': pagination,
            },
                                      context_instance=RequestContext(request))

        else:
            messages.error(request,
                           _('Please correct the errors indicated'
                             ' below'))
    else:
        form = SearchEntitiesForm()

    return render_to_response('metadataparser/search_entities.html',
                              {'form': form},
                              context_instance=RequestContext(request))
Example #10
0
File: views.py Project: GEANT/met
def search_entities(request):
    if request.method == 'POST':
        form = SearchEntitiesForm(request.POST)

        if form.is_valid():
            filters = {}
            args = ()

            entity_type = form.cleaned_data['entity_type']
            if entity_type and entity_type != 'All':
                filters['types__name'] = entity_type

            federations = form.cleaned_data['federations']
            if federations and not 'All' in federations:
                q_list = [Q(federations__id=f) for f in federations]
                args = (reduce(operator.or_, q_list),)

            entity_id = form.cleaned_data['entityid']
            if entity_id and entity_id != '':
                filters['entityid__icontains'] = entity_id

            ob_entities = Entity.objects.all()
            if args:
                ob_entities = ob_entities.filter(*args)
            if filters:
                ob_entities = ob_entities.filter(**filters)

            entity_category = form.cleaned_data['entity_category']
            if entity_category and entity_category != 'All':
                eid_list = []

                for entity in ob_entities.all():
                    feds = Entity_Federations.objects.filter(entity=entity)

                    if federations and not 'All' in federations:
                        ec_list = [Q(federation__id=f) for f in federations]
                        ec_args = (reduce(operator.or_, ec_list),)
                        feds = feds.filter(*ec_args)

                    feds.prefetch_related('entity_categories')
                    feds = feds.filter(entity_categories__category_id=entity_category)
                    eid_list.extend([ Q(entityid=f.entity.entityid) for f in feds])

                eid_args = (reduce(operator.or_, eid_list),)
                ob_entities = ob_entities.filter(*eid_args)

            ob_entities = ob_entities.prefetch_related('types', 'federations')
            pagination = _paginate_fed(ob_entities, form.cleaned_data['page'])

            entities = []
            for entity in pagination['objects']:
                entities.append({
                    'entityid': entity.entityid,
                    'name': entity.name,
                    'absolute_url': entity.get_absolute_url(),
                    'types': [unicode(item) for item in entity.types.all()],
                    'federations': [(unicode(item.name), item.get_absolute_url()) for item in entity.federations.all()],
                })

            export_format = form.cleaned_data['export_format']
            if export_format:
                return export_query_set(export_format, entities,
                                        'entities_search_result', ('entityid', 'types', 'federations'))

            return render_to_response('metadataparser/search_entities.html',
                                      {'settings': settings,
                                       'form': form,
                                       'object_list': entities,
                                       'show_filters': False,
                                       'pagination': pagination,
                                      }, context_instance=RequestContext(request))

        else:
            messages.error(request, _('Please correct the errors indicated'
                                      ' below'))
    else:
        form = SearchEntitiesForm()

    return render_to_response('metadataparser/search_entities.html',
                              {'form': form},
                              context_instance=RequestContext(request))
Example #11
0
File: views.py Project: GEANT/met
def federation_view(request, federation_slug=None):
    if federation_slug:
        request.session['%s_process_done' % federation_slug] = False
        request.session['%s_num_entities' % federation_slug] = 0
        request.session['%s_cur_entities' % federation_slug] = 0
        request.session.save()

    federation = get_object_or_404(Federation, slug=federation_slug)
    if federation.registration_authority:
        categories = EntityCategory.objects.all().filter(
            Q(category_id__icontains=federation.registration_authority) |
            Q(category_id__icontains='http://refeds.org') |
            Q(category_id__icontains='http://www.geant.net'))
    else:
        categories = EntityCategory.objects.all().filter(
            Q(category_id__icontains='http://refeds.org') |
            Q(category_id__icontains='http://www.geant.net'))

    ob_entities = Entity.objects.filter(federations__id=federation.id)
    entity_type = None
    if request.GET and 'entity_type' in request.GET:
        entity_type = request.GET['entity_type']
        ob_entities = ob_entities.filter(types__xmlname=entity_type)
    
    entity_category = None
    if request.GET and 'entity_category' in request.GET:
        entity_category = request.GET['entity_category']

    ob_entities = ob_entities.prefetch_related('types', 'federations')
    pagination = _paginate_fed(ob_entities, request.GET.get('page'))

    entities = []
    for entity in pagination['objects']:
        entity.curfed = federation
        if entity_category is None or entity_category in [c.category_id for c in entity.entity_categories.all()]:
            entities.append({
                'entityid': entity.entityid,
                'name': entity.name,
                'absolute_url': entity.get_absolute_url(),
                'types': [unicode(item) for item in entity.types.all()],
                'federations': [(unicode(item.name), item.get_absolute_url()) for item in entity.federations.all()],
            })

    if 'format' in request.GET:
        return export_query_set(request.GET.get('format'), entities,
                                'entities_search_result', ('entityid', 'types', 'federations'))

    context = RequestContext(request)
    user = context.get('user', None)
    add_entity = user and user.has_perm('metadataparser.add_federation')
    pie_chart = fed_pie_chart(request, federation.id)

    return render_to_response('metadataparser/federation_view.html',
            {'settings': settings,
             'federation': federation,
             'entity_types': DESCRIPTOR_TYPES,
             'entity_type': entity_type or 'All',
             'fed_types': dict(FEDERATION_TYPES),
             'entities': entities,
             'categories': categories,
             'show_filters': True,
             'add_entity': add_entity,
             'lang': request.GET.get('lang', 'en'),
             'update_entities': request.GET.get('update', 'false'),
             'statcharts': [pie_chart],
             'pagination': pagination,
            }, context_instance=context)