Exemplo n.º 1
0
    def get(self, request, format=None, **kwargs):
        import requests
        fullusername = None
        username = None
        if request.user.is_authenticated:
            fullusername = request.user.username
            username = fullusername[:fullusername.rfind("@")]

        if 'resourceid' in self.kwargs:
            try:
                localaccount = XSEDELocalUsermap.objects.get(
                    ResourceID=self.kwargs['resourceid'],
                    portal_login=username)
            except XSEDELocalUsermap.DoesNotExist:
                raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                                     detail='User not found in user database')
            try:
                objects = ComputingActivity.objects.filter(
                    ResourceID__exact=self.kwargs['resourceid']).filter(
                        EntityJSON__LocalOwner__exact=localaccount.
                        local_username)
            except ComputingActivity.DoesNotExist:
                raise MyAPIException(
                    code=status.HTTP_404_NOT_FOUND,
                    detail='ResourceID and LocalAccount not found')
        else:
            raise MyAPIException(code=status.HTTP_400_BAD_REQUEST,
                                 detail='Invalid request')
        serializer = ComputingActivity_Expand_Serializer(
            objects, many=True, context={'request': request})
        return MyAPIResponse({'result_set': serializer.data},
                             template_name='glue2_views_api/jobs.html')
Exemplo n.º 2
0
 def get(self, request, format=None, **kwargs):
     if 'id' in self.kwargs:
         try:
             objects = [XSEDEPerson.objects.get(pk=self.kwargs['id'])]
         except XSEDEPerson.DoesNotExist:
             raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                                  detail='Specified Person ID not found')
         except ValueError:
             raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                                  detail='Specified Person ID is not valid')
     elif 'portalid' in self.kwargs:
         try:
             objects = XSEDEPerson.objects.filter(
                 portal_login__exact=self.kwargs['portalid'])
         except XSEDEPerson.DoesNotExist:
             raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                                  detail='Specified Portal ID not found')
         if len(objects) > 1:
             raise MyAPIException(
                 code=status.HTTP_404_NOT_FOUND,
                 detail='Unexpected multiple Portal ID found')
     serializer = XSEDEPerson_Serializer(objects, many=True)
     response_obj = {'results': serializer.data}
     return MyAPIResponse(response_obj,
                          template_name='xdcdb/person_detail.html')
Exemplo n.º 3
0
    def get(self, request, format=None, **kwargs):
        arg_id = request.GET.get('id', kwargs.get('id', None))
        arg_affiliation = request.GET.get('affiliation',
                                          kwargs.get('affiliation', None))
        arg_localid = request.GET.get('localid', kwargs.get('localid', None))

        # Process optional arguments
        arg_fields = request.GET.get('fields', None)
        if arg_fields:
            want_fields = set(arg_fields.lower().split(','))
        else:
            want_fields = set()

        if arg_id:
            try:
                final_objects = [ResourceV2.objects.get(pk=arg_id)]
            except ResourceV2.DoesNotExist:
                raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                                     detail='Specified Global ID not found')
        elif arg_affiliation and arg_localid:
            try:
                final_objects = ResourceV2.objects.filter(
                    Affiliation__exact=arg_affiliation).filter(
                        LocalID__exact=arg_localid)
            except Exception as exc:
                raise MyAPIException(code=status.HTTP_400_BAD_REQUEST,
                                     detail='{}: {}'.format(
                                         type(exc).__name__, exc.message))
        else:
            raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                                 detail='Missing selection arguments')

        assoc_resources = []  # Retrieve associated resources
        for each_object in final_objects:  # Loop forces evaluation, required in order to execute another Resources query
            assoc_ids = (each_object.Associations or '').split(',')
            assoc_res = ResourceV2.objects.filter(
                Affiliation__exact=each_object.Affiliation).filter(
                    LocalID__in=assoc_ids)
            for res in assoc_res:
                assoc_hash = {
                    'id': res.LocalID,
                    'resource_name': res.Name,
                    'resource_desc': res.Description,
                    'topics': res.Topics,
                }
                assoc_resources.append(assoc_hash)
            break  # breaking because we should have only have one item processed by this loop

        context = {
            'associated_resources': assoc_resources,
            'fields': want_fields
        }
        serializer = Resource_Detail_Serializer(final_objects,
                                                context=context,
                                                many=True)
        response_obj = {'results': serializer.data}
        return MyAPIResponse(response_obj,
                             template_name='resource_v2/resource_detail.html')
Exemplo n.º 4
0
 def get(self, request, format=None, **kwargs):
     if 'id' in self.kwargs:
         try: #uri_to_iri(
             object = ProcessingRecord.objects.get(pk=self.kwargs['id'])
         except ProcessingRecord.DoesNotExist:
             raise MyAPIException(code=status.HTTP_404_NOT_FOUND, detail='Specified id not found')
     else:
         raise MyAPIException(code=status.HTTP_404_NOT_FOUND, detail='Not found')
     if request.accepted_renderer.format == 'html':
         return MyAPIResponse({'record_list': [object]}, template_name='processing_status/detail.html')
     serializer = ProcessingRecord_DbSerializer(object)
     return MyAPIResponse({'record_list': [serializer.data]})
Exemplo n.º 5
0
    def get(self, request, format=None, **kwargs):
        if 'id' in self.kwargs:
            try:
                object = PublisherInfo.objects.get(pk=uri_to_iri(self.kwargs['id']))
            except PublisherInfo.DoesNotExist:
                raise MyAPIException(code=status.HTTP_404_NOT_FOUND, detail='ID parameter is not valid')
        else:
            raise MyAPIException(code=status.HTTP_404_NOT_FOUND, detail='ID not found')

        if request.accepted_renderer.format == 'html':
            return MyAPIResponse({'record_list': [object]}, template_name='processing_status/publisher_detail.html')
        serializer = PublisherInfo_DbSerializer(object)
        return MyAPIResponse({'record_list': [serializer.data]})
Exemplo n.º 6
0
 def get(self, request, format=None, **kwargs):
     if 'id' in self.kwargs:
         try:
             object = ComputingActivity.objects.get(pk=self.kwargs['id'])
         except ComputingActivity.DoesNotExist:
             raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                                  detail='ID not found')
     else:
         raise MyAPIException(code=status.HTTP_400_BAD_REQUEST,
                              detail='Invalid request')
     serializer = ComputingActivity_Expand_Serializer(object)
     return MyAPIResponse({'result_set': [serializer.data]},
                          template_name='glue2_views_api/job_detail.html')
Exemplo n.º 7
0
 def get(self, request, format=None, **kwargs):
     try:
         int(self.kwargs['id'])
         object = RDRResource.objects.get(pk=self.kwargs['id'])
     except ValueError:
         raise MyAPIException(code=status.HTTP_400_BAD_REQUEST,
                              detail='ID parameter is not valid')
     except RDRResource.DoesNotExist:
         raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                              detail='Specified ID not found')
     serializer = RDRResource_Serializer(object)
     return MyAPIResponse({'result_set': [serializer.data]},
                          template_name='rdr_db/detail.html')
Exemplo n.º 8
0
 def get(self, request, format=None, **kwargs):
     if 'about' in self.kwargs:
         try:
             object = ProcessingRecord.objects.filter(About__exact=uri_to_iri(self.kwargs['about'])).latest('ProcessingStart')
         except ProcessingRecord.DoesNotExist:
             raise MyAPIException(code=status.HTTP_404_NOT_FOUND, detail='Specified about not found')
     elif 'topic' in self.kwargs:
         try:
             object = ProcessingRecord.objects.filter(Topic__exact=uri_to_iri(self.kwargs['topic'])).latest('ProcessingStart')
         except ProcessingRecord.DoesNotExist:
             raise MyAPIException(code=status.HTTP_404_NOT_FOUND, detail='Specified topic not found')
     else:
         raise MyAPIException(code=status.HTTP_404_NOT_FOUND, detail='Not found')
     serializer = ProcessingRecord_DbSerializer(object)
     return MyAPIResponse({'record_list': [serializer.data]}, template_name='processing_status/detail.html')
Exemplo n.º 9
0
    def get(self, request, format=None, **kwargs):
        returnformat = request.query_params.get('format', 'json')
        if not 'id' in self.kwargs:
            raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                                 detail='Missing ID argument')

        try:
            objects = [XSEDEFos.objects.get(pk=self.kwargs['id'])]
        except XSEDEFos.DoesNotExist:
            raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                                 detail='Specified FOS ID not found')
        serializer = XSEDEFos_Serializer(objects, many=True)
        response_obj = {'results': serializer.data}
        return MyAPIResponse(response_obj,
                             template_name='xdcdb/fos_detail.html')
Exemplo n.º 10
0
 def delete(self, request, pk, format=None):
     try:
         object = AcceleratorEnvironment.objects.get(pk=uri_to_iri(pk))
     except AcceleratorEnvironment.DoesNotExist:
         raise MyAPIException(code=status.HTTP_404_NOT_FOUND, detail='Not found')
     object.delete()
     return MyAPIResponse(None, code=status.HTTP_204_NO_CONTENT)
Exemplo n.º 11
0
 def get(self, request, pk, format=None):
     try:
         object = AcceleratorEnvironment.objects.get(pk=uri_to_iri(pk)) # uri_to_iri translates %xx
     except AcceleratorEnvironment.DoesNotExist:
         raise MyAPIException(code=status.HTTP_404_NOT_FOUND, detail='Not found')
     serializer = AcceleratorEnvironment_DbSerializer(object)
     return MyAPIResponse({'results': [serializer.data]})
Exemplo n.º 12
0
 def get(self, request, format=None, **kwargs):
     if 'globalid' in self.kwargs:
         try:
             objects = AdminDomain.objects.filter(
                 EntityJSON__GlobalID__exact=self.kwargs['globalid'])
         except AdminDomain.DoesNotExist:
             raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                                  detail='Specified Global ID not found')
     if len(objects) > 1:
         raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                              detail='Unexpected multiple Global IDs found')
     serializer = SupportContacts_Serializer(objects,
                                             context={'request': request},
                                             many=True)
     response_obj = {'results': serializer.data}
     return MyAPIResponse(
         response_obj, template_name='xcsr_db/supportcontact_detail.html')
Exemplo n.º 13
0
    def get(self, request, format=None, **kwargs):
        if 'resourceid' in self.kwargs:
            try:
                objects = PublisherInfo.objects.filter(ResourceID__exact=uri_to_iri(self.kwargs['resourceid']))
            except PublisherInfo.DoesNotExist:
                raise MyAPIException(code=status.HTTP_404_NOT_FOUND, detail='Specified ResourceID not found')
        else:
            try:
                objects = PublisherInfo.objects.all()
            except PublisherInfo.DoesNotExist:
                raise MyAPIException(code=status.HTTP_404_NOT_FOUND, detail='No objects found')
        try:
            sort_by = request.GET.get('sort')
            objects_sorted = objects.order_by(sort_by)
        except:
            objects_sorted = objects

        serializer = PublisherInfo_DetailURL_DbSerializer(objects_sorted, context={'request': request}, many=True)
        return MyAPIResponse({'record_list': serializer.data}, template_name='processing_status/publisher_list.html')
Exemplo n.º 14
0
 def get(self, request, format=None, **kwargs):
     returnformat = request.query_params.get('format', 'json')
     if 'id' in self.kwargs:
         try:
             objects = [TGResource.objects.get(pk=self.kwargs['id'])]
         except TGResource.DoesNotExist:
             raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                                  detail='Specified Resource ID not found')
     elif 'resourceid' in self.kwargs:
         try:
             objects = TGResource.objects.filter(
                 info_resourceid__exact=self.kwargs['resourceid'])
         except TGResource.DoesNotExist:
             raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                                  detail='Specified Resource ID not found')
     serializer = XSEDEResource_Serializer(objects, many=True)
     response_obj = {'results': serializer.data}
     return MyAPIResponse(response_obj,
                          template_name='xdcdb/resource_detail.html')
Exemplo n.º 15
0
 def get(self, request, format=None, **kwargs):
     if 'id' in self.kwargs:
         try:
             objects = [TGResource.objects.get(pk=self.kwargs['id'])]
         except TGResource.DoesNotExist:
             raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                                  detail='Specified Resource ID not found')
         serializer = XSEDEResourcePublished_Serializer(objects, many=True)
         response_obj = {'results': serializer.data}
         return MyAPIResponse(response_obj,
                              template_name='xdcdb/resource_detail.html')
Exemplo n.º 16
0
 def get(self, request, format=None, **kwargs):
     if 'resourceid' in self.kwargs:
         try:
             objects = RDRResource.objects.filter(info_resourceid__exact=uri_to_iri(self.kwargs['resourceid'])).filter(rdr_type__in=['compute','storage'])
         except RDRResource.DoesNotExist:
             raise MyAPIException(code=status.HTTP_400_BAD_REQUEST)
     else:
         objects = RDR_Active_Resources(affiliation='XSEDE', allocated=False, type='SUB', result='OBJECTS')
     serializer = Resource_Batch_Status_Serializer(objects, context={'request': request}, many=True)
     response_obj = {'results': serializer.data}
     return MyAPIResponse(response_obj)
Exemplo n.º 17
0
    def get(self, request, format=None, **kwargs):
        search_strings = kwargs.get('search_strings',
                                    request.GET.get('search_strings', None))
        if search_strings is None or search_strings == '':
            raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                                 detail='Search string missing')
        sort_by = request.GET.get('sort', 'portal_login')
        match_mode = request.GET.get('match', 'any').lower()
        if match_mode == 'and':
            match_mode = 'all'
        elif match_mode == 'or':
            match_mode = 'any'

        try:
            query = None
            for word in search_strings.split():
                if not query:
                    query = (Q(portal_login__icontains=word)
                             | Q(last_name__icontains=word)
                             | Q(first_name__icontains=word)
                             | Q(emails__icontains=word))
                elif match_mode == 'all':
                    query = query & (Q(portal_login__icontains=word)
                                     | Q(last_name__icontains=word)
                                     | Q(first_name__icontains=word)
                                     | Q(emails__icontains=word))
                else:
                    query = query | (Q(portal_login__icontains=word)
                                     | Q(last_name__icontains=word)
                                     | Q(first_name__icontains=word)
                                     | Q(emails__icontains=word))
            objects = XSEDEPerson.objects.filter(query).order_by(sort_by)
        except XSEDEPerson.DoesNotExist:
            raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                                 detail='No persons match search string')
        serializer = XSEDEPerson_Serializer(objects,
                                            context={'request': request},
                                            many=True)
        response_obj = {'results': serializer.data}
        return MyAPIResponse(response_obj,
                             template_name='xdcdb/person_list.html')
Exemplo n.º 18
0
 def get(self, request, format=None, **kwargs):
     if 'id' in self.kwargs:
         try:
             objects = [ComputingActivity.objects.get(pk=self.kwargs['id'])]
         except ComputingActivity.DoesNotExist:
             raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                                  detail='ID not found')
     elif 'resourceid' in self.kwargs and 'queue' in self.kwargs:
         try:
             objects = ComputingActivity.objects.filter(
                 ResourceID__exact=self.kwargs['resourceid']).filter(
                     EntityJSON__Queue__exact=self.kwargs['queue'])
         except ComputingActivity.DoesNotExist:
             raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                                  detail='ResourceID and Queue not found')
     elif 'resourceid' in self.kwargs and 'localaccount' in self.kwargs:
         try:
             objects = ComputingActivity.objects.filter(
                 ResourceID__exact=self.kwargs['resourceid']).filter(
                     EntityJSON__LocalOwner__exact=self.
                     kwargs['localaccount'])
         except ComputingActivity.DoesNotExist:
             raise MyAPIException(
                 code=status.HTTP_404_NOT_FOUND,
                 detail='ResourceID and LocalAccount not found')
     elif 'resourceid' in self.kwargs:
         try:
             objects = ComputingActivity.objects.filter(
                 ResourceID__exact=self.kwargs['resourceid'])
         except ComputingActivity.DoesNotExist:
             raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                                  detail='ResourceID not found')
     else:
         raise MyAPIException(code=status.HTTP_400_BAD_REQUEST,
                              detail='Invalid request')
     serializer = ComputingActivity_Expand_Serializer(
         objects, many=True, context={'request': request})
     return MyAPIResponse({'result_set': serializer.data},
                          template_name='glue2_views_api/jobs.html')
Exemplo n.º 19
0
    def get(self, request, format=None, **kwargs):
        import requests
        fullusername = None
        username = None
        if request.user.is_authenticated:
            fullusername = request.user.username
            username = fullusername[:fullusername.rfind("@")]

            try:
                localaccounts = XSEDELocalUsermap.objects.filter(
                    portal_login=username)
            except XSEDELocalUsermap.DoesNotExist:
                raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                                     detail='User not found in user database')
            localusernames = []
            resourceusers = {}
            for account in localaccounts:
                localuser = account.local_username
                localusernames.append(localuser)
                resourceusers[account.ResourceID + localuser] = True
            try:
                objects = ComputingActivity.objects.filter(
                    EntityJSON__LocalOwner__in=localusernames)
            except ComputingActivity.DoesNotExist:
                raise MyAPIException(
                    code=status.HTTP_404_NOT_FOUND,
                    detail='ResourceID and LocalAccount not found')
            jobstoreturn = []
            for job in objects:
                if resourceusers.get(
                        job.ResourceID + job.EntityJSON['LocalOwner'], False):
                    jobstoreturn.append(job)
        else:
            raise MyAPIException(code=status.HTTP_400_BAD_REQUEST,
                                 detail='Invalid request')
        serializer = ComputingActivity_Expand_Serializer(
            jobstoreturn, many=True, context={'request': request})
        return MyAPIResponse({'result_set': serializer.data},
                             template_name='glue2_views_api/jobs.html')
Exemplo n.º 20
0
    def get(self, request, format=None, **kwargs):
        arg_id = request.GET.get('id', kwargs.get('id', None))
        arg_affiliation = request.GET.get('affiliation',
                                          kwargs.get('affiliation', None))
        arg_localid = request.GET.get('localid', kwargs.get('localid', None))

        # Process optional arguments
        arg_fields = request.GET.get('fields', None)
        if arg_fields:
            want_fields = set(arg_fields.lower().split(','))
        else:
            want_fields = set()

        if arg_id:
            try:
                final_objects = [ResourceV2Guide.objects.get(pk=arg_id)]
            except ResourceV2Guide.DoesNotExist:
                raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                                     detail='Specified Global ID not found')
        elif arg_affiliation and arg_localid:
            try:
                final_objects = ResourceV2Guide.objects.filter(
                    Affiliation__exact=arg_affiliation).filter(
                        LocalID__exact=arg_localid)
            except Exception as exc:
                raise MyAPIException(code=status.HTTP_400_BAD_REQUEST,
                                     detail='{}: {}'.format(
                                         type(exc).__name__, exc.message))
        else:
            raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                                 detail='Missing selection arguments')

        context = {'fields': want_fields}
        serializer = Guide_Detail_Serializer(final_objects,
                                             context=context,
                                             many=True)
        response_obj = {'results': serializer.data}
        return MyAPIResponse(response_obj,
                             template_name='resource_v2/guide_detail.html')
Exemplo n.º 21
0
    def get(self, request, format=None, **kwargs):
        if 'doctype' not in self.kwargs:
            raise MyAPIException(code=status.HTTP_404_NOT_FOUND, detail='Missing /doctype/.. argument')
        arg_doctype = kwargs['doctype']
        
        try:
            dt = request.GET.get('start_date', None)
            pdt = parse_datetime(dt)
            if pdt is None: # If it was only a date try adding the time
                pdt = parse_datetime(dt + 'T00:00:00.0+00:00')
            if pdt is None:
                raise Exception
            arg_startdate = pdt.astimezone(UTC).strftime('%Y-%m-%dT%H:%M:%S%z')
        except:
            arg_startdate = None
        
        try:
            dt = request.GET.get('end_date', None)
            pdt = parse_datetime(dt)
            if pdt is None: # If it was only a date try adding the time
                pdt = parse_datetime(dt + 'T23:59:59.0+00:00')
            if pdt is None:
                raise Exception
            arg_enddate = (pdt.astimezone(UTC) + timedelta(seconds=1)).strftime('%Y-%m-%dT%H:%M:%S%z')
        except:
            arg_enddate = None

        arg_resourceid = request.GET.get('resourceid', None)

        arg_fields = request.GET.get('fields', None)
        if arg_fields:
            want_fields = set(arg_fields.lower().split(','))
        else:
            want_fields = set()

        objects = EntityHistory.objects.filter(DocumentType=arg_doctype)

        if arg_resourceid:
            objects = objects.filter(ResourceID=arg_resourceid)             # String Comparison
        if arg_startdate:
            objects = objects.filter(ReceivedTime__gte=arg_startdate)       # String Comparison
        if arg_enddate:
            objects = objects.filter(ReceivedTime__lt=arg_enddate)         # String Comparison

        if '__usage__' in want_fields:
            serializer = EntityHistory_Usage_Serializer(objects, many=True)
        else:
            serializer = EntityHistory_DbSerializer(objects, many=True)
        response_obj = {'results': serializer.data}
        response_obj['total_results'] = len(objects)
        return MyAPIResponse(response_obj)
Exemplo n.º 22
0
 def get(self, request, format=None, **kwargs):
     if 'about' in self.kwargs:
         try:
             objects = ProcessingRecord.objects.filter(About__exact=uri_to_iri(self.kwargs['about']))
         except ProcessingRecord.DoesNotExist:
             raise MyAPIException(code=status.HTTP_404_NOT_FOUND, detail='Specified about not found')
     elif 'topic' in self.kwargs:
         try:
             objects = ProcessingRecord.objects.filter(Topic__exact=uri_to_iri(self.kwargs['topic']))
         except ProcessingRecord.DoesNotExist:
             raise MyAPIException(code=status.HTTP_404_NOT_FOUND, detail='Specified topic not found')
     else:
         try:
             objects = ProcessingRecord.objects.all()
         except ProcessingRecord.DoesNotExist:
             raise MyAPIException(code=status.HTTP_404_NOT_FOUND, detail='No objects found')
     try:
         sort_by = request.GET.get('sort')
         objects_sorted = objects.order_by(sort_by)
     except:
         objects_sorted = objects
     serializer = ProcessingRecord_DetailURL_DbSerializer(objects_sorted, context={'request': request}, many=True)
     return MyAPIResponse({'record_list': serializer.data}, template_name='processing_status/list.html')
Exemplo n.º 23
0
 def put(self, request, pk, format=None):
     try:
         object = AcceleratorEnvironment.objects.get(pk=uri_to_iri(pk))
     except AcceleratorEnvironment.DoesNotExist:
         raise MyAPIException(code=status.HTTP_404_NOT_FOUND, detail='Not found')
     serializer = AcceleratorEnvironment_DbSerializer(object, data=request.data)
     if serializer.is_valid():
         serializer.save()
         code = status.HTTP_201_CREATED
         data = serializer.data
     else:
         code = status.HTTP_400_BAD_REQUEST
         data = serializer.errors
     return MyAPIResponse({'results': data}, code=code)
Exemplo n.º 24
0
 def get(self, request, format=None, **kwargs):
     if 'ResourceID' in self.kwargs:
         try:
             objects = ProjectResource.objects.filter(
                 ResourceID=self.kwargs['ResourceID'])
         except ProjectResource.DoesNotExist:
             raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                                  detail='Allocation resources not found')
     elif 'project_number' in self.kwargs:
         try:
             objects = ProjectResource.objects.filter(
                 project_number=self.kwargs['project_number'])
         except ProjectResource.DoesNotExist:
             raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                                  detail='Allocation resources not found')
     else:
         objects = ProjectResource.objects.all()
     serializer = ProjectResource_Serializer(objects,
                                             context={'request': request},
                                             many=True)
     response_obj = {'results': serializer.data}
     return MyAPIResponse(
         response_obj,
         template_name='allocations/allocationresources_list.html')
Exemplo n.º 25
0
    def get(self, request, format=None, **kwargs):
        arg_affiliation = request.GET.get('affiliation',
                                          kwargs.get('affiliation', None))
        if arg_affiliation:
            want_affiliation = set(arg_affiliation.split(','))
        else:
            want_affiliation = set()

        arg_fields = request.GET.get('fields', None)
        if arg_fields:
            want_fields = set(arg_fields.lower().split(','))
        else:
            want_fields = set()

        page = request.GET.get('page', None)
        page_size = request.GET.get('results_per_page', 25)
        response_obj = {}

        try:
            if want_affiliation:
                objects = ResourceV2.objects.filter(
                    Affiliation__in=want_affiliation).values('Type').annotate(
                        count=Count('Type'))
            else:
                objects = ResourceV2.objects.all().values('Type').values(
                    'Type').annotate(count=Count('Type'))

            response_obj['total_results'] = len(objects)
            if page:
                paginator = Paginator(objects, page_size)
                final_objects = paginator.page(page)
                response_obj['page'] = int(page)
                response_obj['total_pages'] = paginator.num_pages
            else:
                final_objects = objects
        except Exception as exc:
            raise MyAPIException(code=status.HTTP_400_BAD_REQUEST,
                                 detail='{}: {}'.format(
                                     type(exc).__name__, exc.message))
        context = {'fields': want_fields}
        serializer = Resource_Types_Serializer(final_objects,
                                               context=context,
                                               many=True)
        response_obj['results'] = serializer.data
        return MyAPIResponse(response_obj,
                             template_name='resource_v2/types_list.html')
Exemplo n.º 26
0
 def get(self, request, format=None, **kwargs):
     if 'resourceid' in self.kwargs:
         try:
             objects = ComputingQueue.objects.filter(
                 ResourceID__exact=self.kwargs['resourceid'])
         except ComputingQueue.DoesNotExist:
             raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                                  detail='ResourceID not found')
     else:
         objects = ComputingQueue.objects.all()
     try:
         sort_by = request.GET.get('sort')
     except:
         sort_by = None
     serializer = ComputingQueue_Expand_Serializer(
         objects, many=True, context={'sort_by': sort_by})
     return MyAPIResponse({'result_set': serializer.data},
                          template_name='glue2_views_api/jobqueues.html')
Exemplo n.º 27
0
    def get(self, request, format=None, **kwargs):
        arg_affiliation = request.GET.get('affiliation',
                                          kwargs.get('affiliation', None))
        if arg_affiliation:
            want_affiliation = set(arg_affiliation.split(','))
        else:
            want_affiliation = set()

        arg_fields = request.GET.get('fields', None)
        if arg_fields:
            want_fields = set(arg_fields.lower().split(','))
        else:
            want_fields = set()

        arg_terms = request.GET.get('search_terms', None)
        if arg_terms:
            want_terms = set(arg_terms.replace(',', ' ').lower().split())
        else:
            want_terms = set()

        try:
            dt = request.GET.get('start_date', None)
            pdt = parse_datetime(dt)
            if pdt is None:  # If it was only a date try adding the time
                pdt = parse_datetime(dt + 'T00:00:00.0+00:00')
            if pdt is None:
                raise Exception
            arg_startdate = pdt.astimezone(UTC).strftime('%Y-%m-%dT%H:%M:%S%z')
        except:
            arg_startdate = timezone.now().astimezone(UTC).strftime(
                '%Y-%m-%dT%H:%M:%S%z')

        try:
            # Search for less than end_date + 1/second
            dt = request.GET.get('end_date', None)
            pdt = parse_datetime(dt)
            if pdt is None:  # If it was only a date try adding the time
                pdt = parse_datetime(dt + 'T23:59:59.9+00:00')
            if pdt is None:
                raise Exception
            arg_enddate = (
                pdt.astimezone(UTC) +
                timedelta(seconds=1)).strftime('%Y-%m-%dT%H:%M:%S%z')
        except:
            arg_enddate = (
                timezone.now().astimezone(UTC) +
                timedelta(days=365 * 10)).strftime('%Y-%m-%dT%H:%M:%S%z')

        page = request.GET.get('page', None)
        page_size = request.GET.get('results_per_page', 25)
        fields = request.GET.get('fields', None)
        response_obj = {}

        try:
            # Changed 2019-04-15 by JP per Alex Kuhl
            #            objects = Resource.objects.filter(Type__exact='Event').filter(EntityJSON__record_status__in=[1,2])
            objects = Resource.objects.filter(Type__exact='Event').filter(
                EntityJSON__record_status__exact=1)
            if want_affiliation:
                objects = objects.filter(Affiliation__in=want_affiliation)
            # resource.start_date_time <= end_date && resource.end_date_time >= start_date
            if arg_startdate:
                objects = objects.filter(
                    EntityJSON__end_date_time__gte=arg_startdate
                )  # String comparison
            if arg_enddate:
                objects = objects.filter(
                    EntityJSON__start_date_time__lt=arg_enddate
                )  # String comparison
            if want_terms:
                objects = resource_terms_filtersort(
                    objects, want_terms, sort_field='start_date_time')
            else:
                objects = objects.order_by(
                    RawSQL('"EntityJSON"->>\'{}\''.format('start_date_time'),
                           ()))
            response_obj['total_results'] = len(objects)
            if page:
                paginator = Paginator(objects, page_size)
                final_objects = paginator.page(page)
                response_obj['page'] = int(page)
                response_obj['total_pages'] = paginator.num_pages
            else:
                final_objects = objects
        except Exception as exc:
            raise MyAPIException(code=status.HTTP_400_BAD_REQUEST,
                                 detail='{}: {}'.format(
                                     type(exc).__name__, exc))

        context = {'fields': want_fields}
        serializer = Resource_Event_Serializer(final_objects,
                                               context=context,
                                               many=True)
        response_obj['results'] = serializer.data
        return MyAPIResponse(response_obj,
                             template_name='resource_cat/event_list.html')
Exemplo n.º 28
0
    def get(self, request, format=None, **kwargs):
        arg_affiliation = request.GET.get('affiliation',
                                          kwargs.get('affiliation', None))
        if arg_affiliation:
            want_affiliation = set(arg_affiliation.split(','))
        else:
            want_affiliation = set()

        arg_topics = request.GET.get('topics', None)
        if arg_topics:
            want_topics = set(arg_topics.split(','))
        else:
            want_topics = set()

        arg_fields = request.GET.get('fields', None)
        if arg_fields:
            want_fields = set(arg_fields.lower().split(','))
        else:
            want_fields = set()

        arg_terms = request.GET.get('search_terms', None)
        if arg_terms:
            want_terms = set(arg_terms.replace(',', ' ').lower().split())
        else:
            want_terms = set()

        arg_providers = request.GET.get('providers', None)
        # Search in ProviderID field if possible rather than Provider in JSONField
        if arg_providers:
            if set(arg_providers).issubset(set('0123456789,')):
                # Handle numeric providers for uiuc.edu
                if want_affiliation and len(want_affiliation) == 1:
                    this_affiliation = next(iter(want_affiliation))
                    want_providerids = [
                        'urn:glue2:GlobalResourceProvider:{}.{}'.format(
                            x.strip(), this_affiliation)
                        for x in arg_providers.split(',')
                    ]
                    want_providers = []
                else:
                    want_providerids = []
                    want_providers = [
                        int(x) for x in arg_providers.split(',')
                        if x.strip().isdigit()
                    ]
            else:
                want_providerids = set(arg_providers.split(','))
                want_providers = []
        else:
            want_providerids = []
            want_providers = []

        arg_topics = request.GET.get('topics', None)
        if arg_topics:
            want_topics = set(arg_topics.split(','))
        else:
            want_topics = set()

        try:
            dt = request.GET.get('start_date', None)
            pdt = parse_datetime(dt)
            if pdt is None:  # If it was only a date try adding the time
                pdt = parse_datetime(dt + 'T00:00:00.0+00:00')
            if pdt is None:
                raise Exception
            arg_startdate = pdt.astimezone(UTC).strftime('%Y-%m-%dT%H:%M:%S%z')
        except:
            arg_startdate = timezone.now().astimezone(UTC).strftime(
                '%Y-%m-%dT%H:%M:%S%z')

        try:
            # Search for less than end_date + 1/second
            dt = request.GET.get('end_date', None)
            pdt = parse_datetime(dt)
            if pdt is None:  # If it was only a date try adding the time
                pdt = parse_datetime(dt + 'T23:59:59.9+00:00')
            if pdt is None:
                raise Exception
            arg_enddate = (
                pdt.astimezone(UTC) +
                timedelta(seconds=1)).strftime('%Y-%m-%dT%H:%M:%S%z')
        except:
            arg_enddate = (
                timezone.now().astimezone(UTC) +
                timedelta(days=365 * 10)).strftime('%Y-%m-%dT%H:%M:%S%z')

        page = request.GET.get('page', None)
        page_size = request.GET.get('results_per_page', 25)
        fields = request.GET.get('fields', None)
        response_obj = {}

        try:
            # Changed 2019-04-15 by JP per Alex Kuhl
            #            objects = ResourceV2.objects.filter(Type__exact='Event').filter(EntityJSON__record_status__in=[1,2])
            objects = ResourceV2.objects.filter(Type__exact='Event').filter(
                EntityJSON__record_status__exact=1)
            if want_affiliation:
                objects = objects.filter(Affiliation__in=want_affiliation)
            if want_providerids:
                objects = objects.filter(ProviderID__in=want_providerids)
            elif want_providers:
                objects = objects.filter(
                    EntityJSON__provider__in=want_providers)
            # resource.start_date_time <= end_date && resource.end_date_time >= start_date
            if arg_startdate:
                objects = objects.filter(
                    EntityJSON__end_date_time__gte=arg_startdate
                )  # String comparison
            if arg_enddate:
                objects = objects.filter(
                    EntityJSON__start_date_time__lt=arg_enddate
                )  # String comparison

            if want_terms:
                objects = resource_terms_filtersort(
                    objects, want_terms, sort_field='start_date_time')
            else:
                objects = objects.order_by(
                    RawSQL('"EntityJSON"->>\'{}\''.format('start_date_time'),
                           ()))

            # These filters have to be handled by looping thru rows; they must be after the previous database filters
            if want_topics:
                objects = resource_topics_filter(objects, want_topics)

            response_obj['total_results'] = len(objects)
            if page:
                paginator = Paginator(objects, page_size)
                final_objects = paginator.page(page)
                response_obj['page'] = int(page)
                response_obj['total_pages'] = paginator.num_pages
            else:
                final_objects = objects
        except Exception as exc:
            raise MyAPIException(code=status.HTTP_400_BAD_REQUEST,
                                 detail='{}: {}'.format(
                                     type(exc).__name__, str(exc)))

        context = {'fields': want_fields}
        serializer = Resource_Event_Serializer(final_objects,
                                               context=context,
                                               many=True)
        response_obj['results'] = serializer.data
        return MyAPIResponse(response_obj,
                             template_name='resource_v2/event_list.html')
Exemplo n.º 29
0
    def get(self, request, format=None, **kwargs):
        # Process optional arguments
        arg_affiliation = request.GET.get('affiliation',
                                          kwargs.get('affiliation', None))
        if arg_affiliation:
            want_affiliation = set(arg_affiliation.split(','))
        else:
            want_affiliation = set()

        arg_resource_groups = request.GET.get('resource_groups', None)
        if arg_resource_groups:
            want_resource_groups = set(arg_resource_groups.split(','))
        else:
            want_resource_groups = set()

        arg_terms = request.GET.get('search_terms', None)
        if arg_terms:
            want_terms = set(arg_terms.replace(',', ' ').lower().split())
        else:
            want_terms = set()

        arg_strings = request.GET.get('search_strings', None)
        if arg_strings:
            want_strings = set(arg_strings.replace(',', ' ').lower().split())
        else:
            want_strings = set()

        arg_topics = request.GET.get('topics', None)
        if arg_topics:
            want_topics = set(arg_topics.split(','))
        else:
            want_topics = set()

        arg_types = request.GET.get('types', None)
        if arg_types:
            want_types = set(arg_types.split(','))
        else:
            want_types = set()

        arg_providers = request.GET.get('providers', None)
        # Search in ProviderID field if possible rather than Provider in JSONField
        if arg_providers:
            if set(arg_providers).issubset(set('0123456789,')):
                # Handle numeric providers for uiuc.edu
                if want_affiliation and len(want_affiliation) == 1:
                    this_affiliation = next(iter(want_affiliation))
                    want_providerids = [
                        'urn:glue2:GlobalResourceProvider:{}.{}'.format(
                            x.strip(), this_affiliation)
                        for x in arg_providers.split(',')
                    ]
                    want_providers = []
                else:
                    want_providerids = []
                    want_providers = [
                        int(x) for x in arg_providers.split(',')
                        if x.strip().isdigit()
                    ]
            else:
                want_providerids = set(arg_providers.split(','))
                want_providers = []
        else:
            want_providerids = []
            want_providers = []

        arg_fields = request.GET.get('fields', None)
        if arg_fields:
            want_fields = set(arg_fields.lower().split(','))
        else:
            want_fields = set()

        sort = request.GET.get('sort', 'resource_name')
        page = request.GET.get('page', None)
        page_size = request.GET.get('results_per_page', 25)

        response_obj = {}
        try:
            # These filters are handled by the database; they are first
            RES = ResourceV2.objects.filter(EntityJSON__record_status__exact=1)
            if want_affiliation:
                RES = RES.filter(Affiliation__in=want_affiliation)
            if want_resource_groups:
                RES = RES.filter(ResourceGroup__in=want_resource_groups)
            if want_types:
                RES = RES.filter(Type__in=want_types)
            if want_providerids:
                RES = RES.filter(ProviderID__in=want_providerids)
            elif want_providers:
                RES = RES.filter(EntityJSON__provider__in=want_providers)
#            if not want_terms:                  # Becase terms search does its own ranked sort
#                local_global_map = {'resource_name': 'Name',
#                                    'resource_type': 'Type',
#                                    'resource_description': 'Description',
#                                    'id': 'LocalID'}
#                if sort in local_global_map:
#                    RES = RES.order_by(local_global_map[sort])
#                elif sort is not None:
#                    RES = RES.order_by(RawSQL('"EntityJSON"->>\'{}\''.format(sort), ()))

# These filters have to be handled with code; they must be after the previous database filters
            if want_topics:
                RES = resource_topics_filter(RES, want_topics)
            if want_terms:
                RES = resource_terms_filtersort(RES,
                                                want_terms,
                                                sort_field='name')
            elif want_strings:
                RES = resource_strings_filtersort(RES,
                                                  want_strings,
                                                  sort_field='name')
            RES = resource_oldevents_filter(RES)

            want_resources = set()
            for item in RES:
                want_resources.add(item.ID)

            want_guides = ResourceV2GuideResource.objects.filter(
                ResourceID__in=want_resources).order_by(
                    'CuratedGuideID').distinct('CuratedGuideID').values_list(
                        'CuratedGuideID', flat=True)

            objects = ResourceV2Guide.objects.filter(
                pk__in=want_guides).order_by('Name')
            response_obj['total_results'] = len(objects)

            if page:
                paginator = Paginator(objects, page_size)
                final_objects = paginator.page(page)
                response_obj['page'] = int(page)
                response_obj['total_pages'] = paginator.num_pages
            else:
                final_objects = objects
        except Exception as exc:
            if hasattr(exc, 'message'):
                raise MyAPIException(code=status.HTTP_400_BAD_REQUEST,
                                     detail='{}: {}'.format(
                                         type(exc).__name__, exc.message))
            else:
                raise MyAPIException(code=status.HTTP_400_BAD_REQUEST,
                                     detail='{}: {}'.format(
                                         type(exc).__name__, exc))

        context = {'fields': want_fields}
        serializer = Guide_Search_Serializer(final_objects,
                                             context=context,
                                             many=True)
        response_obj['results'] = serializer.data
        return MyAPIResponse(response_obj,
                             template_name='resource_v2/guide_list.html')
Exemplo n.º 30
0
    def get(self, request, format=None, **kwargs):
        arg_strings = request.GET.get('search_strings', None)
        if arg_strings:
            want_strings = list(arg_strings.replace(',', ' ').lower().split())
        else:
            want_strings = list()

        arg_hierarchy = request.GET.get('hierarchy', None)
        if arg_hierarchy and arg_hierarchy != '':
            want_hierarchy = True
        else:
            want_hierarchy = False

        arg_inactive = request.GET.get('inactive', None)
        if arg_inactive and arg_inactive != '':
            want_inactive = True
        else:
            want_inactive = False

        if 'parentid' in self.kwargs:
            try:
                objects = XSEDEFos.objects.filter(
                    parent_field_of_science_id__exact=self.kwargs['parentid'])
            except XSEDEFos.DoesNotExist:
                raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                                     detail='Specified Parent ID not found')
        elif want_strings:
            try:
                objects = XSEDEFos.objects.filter(
                    field_of_science_desc__icontains=want_strings[0])
                for another in want_strings[1:]:
                    objects = objects.filter(
                        field_of_science_desc__icontains=another)
            except:
                raise MyAPIException(
                    code=status.HTTP_404_NOT_FOUND,
                    detail='Unexpected error handling search_strings')
        else:
            try:
                objects = XSEDEFos.objects.all()
            except:
                raise MyAPIException(code=status.HTTP_404_NOT_FOUND,
                                     detail='Fields of Science not found')
        if not want_inactive:
            objects = objects.filter(is_active=True)

        sort_by = request.GET.get('sort')
        if sort_by:
            objects = objects.order_by(sort_by)

        serializer = XSEDEFos_DetailURL_Serializer(
            objects, context={'request': request}, many=True)

        reqformat = format or request.GET.get('format', None)
        if reqformat == 'xml' or reqformat == 'json' or sort_by or not want_hierarchy:
            response_obj = {'results': serializer.data}
            return MyAPIResponse(response_obj,
                                 template_name='xdcdb/fos_list.html')

        if not sort_by and want_hierarchy:
            # 1. Create description and parent lookup dictionaries
            desc_lookup = {}
            parent_lookup = {}
            for item in serializer.data:
                desc_lookup[item['field_of_science_id']] = item[
                    'field_of_science_desc']
                parent_lookup[item['field_of_science_id']] = item[
                    'parent_field_of_science_id']
            # 2. Create sort and depth lookup maps
            sort_map = {}  # The textual field we will sort by
            depth_map = {}  # Distance to an item without a parent
            for item in serializer.data:
                self.build_sort_depth(item['field_of_science_id'], sort_map,
                                      depth_map, desc_lookup, parent_lookup)

        response_list = list()
        for item in serializer.data:
            response_item = dict(item)
            response_item['sort'] = sort_map[item['field_of_science_id']]
            if depth_map[item['field_of_science_id']] == 0:
                prefix = ''
            else:
                prefix = (depth_map[item['field_of_science_id']] *
                          4) * '&nbsp;'
            response_item[
                'print_desc'] = prefix + item['field_of_science_desc']
            response_list.append(response_item)

        response_obj = {
            'results': sorted(response_list, key=lambda i: i['sort'])
        }
        return MyAPIResponse(response_obj, template_name='xdcdb/fos_list.html')