Пример #1
0
    def download(self,
                 request,
                 pk=None,
                 download_key=None,
                 download_job_id=None):
        try:
            self.get_queryset().get(pk=pk)
        except QueryJob.DoesNotExist:
            raise NotFound

        download_config = get_download_config(download_key)
        if download_config is None:
            raise ValidationError({
                'download':
                'Download key "{}" is not supported.'.format(download_key)
            })

        download_job_model = import_class(download_config['model'])

        try:
            download_job = download_job_model.objects.get(query_job=pk,
                                                          pk=download_job_id)
        except download_job_model.DoesNotExist:
            raise NotFound

        if download_job.phase == download_job.PHASE_COMPLETED and request.GET.get(
                'download', True):
            return sendfile(request, download_job.file_path, attachment=True)
        else:
            return Response(download_job.phase)
Пример #2
0
    def create_download(self, request, pk=None, download_key=None):
        try:
            job = self.get_queryset().get(pk=pk)
        except QueryJob.DoesNotExist:
            raise NotFound

        download_config = get_download_config(download_key)
        if download_config is None:
            raise ValidationError({
                'download':
                'Download key "{}" is not supported.'.format(download_key)
            })

        download_job_model = import_class(download_config['model'])

        params = {
            param: request.data.get(param)
            for param in download_config.get('params', [])
        }

        try:
            download_job = download_job_model.objects.get(query_job=job,
                                                          **params)

            # check if the file was lost
            if download_job.phase == download_job.PHASE_COMPLETED and \
                    not os.path.isfile(download_job.file_path):

                # set the phase back to pending so that the file is recreated
                download_job.phase = download_job.PHASE_PENDING
                download_job.process()
                download_job.save()
                download_job.run()

        except download_job_model.DoesNotExist:
            download_job = download_job_model(
                job_type=QueryJob.JOB_TYPE_INTERFACE,
                owner=(None if self.request.user.is_anonymous else
                       self.request.user),
                client_ip=get_client_ip(self.request),
                query_job=job,
                **params)
            download_job.process()
            download_job.save()
            download_job.run()

        return Response({'id': download_job.id})
Пример #3
0
from django.views.generic import TemplateView

app_name = 'uws'

router = JobRouter(trailing_slash=False)
'''
add uws routes for the resources specified in the settings
resources need to be of the form
{
    'prefix': r'query',
    'viewset': 'daiquiri.query.viewsets.UWSQueryJobViewSet',
    'base_name': 'uws_query'
}
'''
try:
    resources = settings.UWS_RESOURCES
except AttributeError:
    pass
else:
    for resource in resources:
        router.register(resource['prefix'],
                        import_class(resource['viewset']),
                        basename=resource['base_name'])

urlpatterns = [
    re_path(r'^$',
            TemplateView.as_view(template_name='uws/root.html'),
            name='uws_root'),
    re_path(r'', include(router.urls)),
]
Пример #4
0
def CutOutAdapter():
    return import_class(settings.CUTOUT_ADAPTER)()
Пример #5
0
def DatalinkAdapter():
    return import_class(settings.DATALINK_ADAPTER)()
Пример #6
0
def get_resolver():
    if settings.SERVE_RESOLVER:
        return import_class(settings.SERVE_RESOLVER)()
    else:
        return None
Пример #7
0
def OaiAdapter():
    return import_class(settings.OAI_ADAPTER)()
Пример #8
0
 def get_renderer(self, metadata_prefix):
     renderer_class = next(
         metadata_format['renderer_class']
         for metadata_format in settings.OAI_METADATA_FORMATS
         if metadata_format['prefix'] == metadata_prefix)
     return import_class(renderer_class)()
Пример #9
0
def get_renderer(metadata_prefix):
    renderer_class = get_metadata_format(metadata_prefix)['renderer_class']
    return import_class(renderer_class)()