예제 #1
0
def view_get_slack_dataset_info(dataset_id, **kwargs):

    citation_only = kwargs.get('citation', False)

    dsv = get_latest_dataset_version(dataset_id)
    if dsv is None:
        return "Sorry, no Dataset found for id: %s" % dataset_id

    dataset_dict = DatasetSerializer(dsv).as_json()

    ref_url = '%s/dataset.xhtml?id=%s' % (\
                    settings.DATAVERSE_INSTALLATION_URL,
                    dataset_id)

    if citation_only:
        citation_block = dataset_dict.get('metadata_blocks',
                                          {}).get('citation')

        return """%s\n\nreference: %s""" %\
            (json.dumps(citation_block, indent=4), ref_url)



    return """%s\n\nreference: %s""" %\
        (json.dumps(dataset_dict, indent=4), ref_url)
예제 #2
0
def view_single_dataset(request, dataset_id):
    """Dataset view test.  Given dataset id, get latest version"""

    dsv = get_latest_dataset_version(dataset_id)

    if dsv is None:
        raise Http404('dataset_id not found')

    return view_dataset_by_version(request, dsv.id)
예제 #3
0
def view_single_dataset(request, dataset_id):
    """Dataset view test.  Given dataset id, get latest version"""

    dsv = get_latest_dataset_version(dataset_id)

    if dsv is None:
        raise Http404('dataset_id not found')

    return view_dataset_by_version(request, dsv.id)
예제 #4
0
def view_dataset_by_persistent_id(request):

    persistent_id = request.GET.get('persistentId', None)
    if persistent_id is None:
        raise Http404('persistentId not found: %s' % persistent_id)

    ds = Dataset.get_dataset_by_persistent_id(persistent_id)
    if ds is None:
        raise Http404('persistentId not found: %s' % persistent_id)

    dsv = get_latest_dataset_version(ds.dvobject.id)

    if dsv is None:
        raise Http404('dataset_id not found')

    return view_dataset_by_version(request, dsv.id)
예제 #5
0
def view_dataset_by_persistent_id(request):

    persistent_id = request.GET.get('persistentId', None)
    if persistent_id is None:
        raise Http404('persistentId not found: %s' % persistent_id)

    ds = Dataset.get_dataset_by_persistent_id(persistent_id)
    if ds is None:
        raise Http404('persistentId not found: %s' % persistent_id)

    dsv = get_latest_dataset_version(ds.dvobject.id)

    if dsv is None:
        raise Http404('dataset_id not found')

    return view_dataset_by_version(request, dsv.id)
예제 #6
0
    def get_stats_result(self, request):
        """Return the StatsResult object for this statistic"""

        dv_id = self.kwargs.get('ds_id', None)
        if dv_id is None:
            return StatsResult.build_error_result("No Dataset id specified", 400)

        # Get the latest version
        dataset_version = get_latest_dataset_version(dv_id)

        if dataset_version is None:
            return StatsResult.build_error_result('No published Dataset with id: %s' % dv_id, 404)

        dataset_as_json = DatasetSerializer(dataset_version).as_json()

        return StatsResult.build_success_result(dataset_as_json)
예제 #7
0
    def get_stats_result(self, request):
        """Return the StatsResult object for this statistic"""

        dv_id = self.kwargs.get('ds_id', None)
        if dv_id is None:
            return StatsResult.build_error_result("No Dataset id specified",
                                                  400)

        # Get the latest version
        dataset_version = get_latest_dataset_version(dv_id)

        if dataset_version is None:
            return StatsResult.build_error_result(
                'No published Dataset with id: %s' % dv_id, 404)

        dataset_as_json = DatasetSerializer(dataset_version).as_json()

        return StatsResult.build_success_result(dataset_as_json)
예제 #8
0
    def get_stats_result(self, request):
        """Return the StatsResult object for this statistic"""
        persistent_id = request.GET.get('persistentId', None)
        if persistent_id is None:
            return StatsResult.build_error_result("No Dataset persistent id specified", 400)

        ds = Dataset.get_dataset_by_persistent_id(persistent_id)

        err_404 = 'No published dataset found for persistentId: %s' % persistent_id

        if ds is None or not ds.dvobject.publicationdate:
            return StatsResult.build_error_result(err_404, 404)


        # Get the latest version
        dataset_version = get_latest_dataset_version(ds.dvobject.id)

        if dataset_version is None:
            return StatsResult.build_error_result(err_404, 404)

        dataset_as_json = DatasetSerializer(dataset_version).as_json()

        return StatsResult.build_success_result(dataset_as_json)
예제 #9
0
    def get_stats_result(self, request):
        """Return the StatsResult object for this statistic"""
        persistent_id = request.GET.get('persistentId', None)
        if persistent_id is None:
            return StatsResult.build_error_result(
                "No Dataset persistent id specified", 400)

        ds = Dataset.get_dataset_by_persistent_id(persistent_id)

        err_404 = 'No published dataset found for persistentId: %s' % persistent_id

        if ds is None or not ds.dvobject.publicationdate:
            return StatsResult.build_error_result(err_404, 404)

        # Get the latest version
        dataset_version = get_latest_dataset_version(ds.dvobject.id)

        if dataset_version is None:
            return StatsResult.build_error_result(err_404, 404)

        dataset_as_json = DatasetSerializer(dataset_version).as_json()

        return StatsResult.build_success_result(dataset_as_json)
예제 #10
0
def view_get_slack_dataset_info(dataset_id, **kwargs):

    citation_only = kwargs.get('citation', False)

    dsv = get_latest_dataset_version(dataset_id)
    if dsv is None:
        return "Sorry, no Dataset found for id: %s" % dataset_id

    dataset_dict = DatasetSerializer(dsv).as_json()

    ref_url = '%s/dataset.xhtml?id=%s' % (\
                    settings.DATAVERSE_INSTALLATION_URL,
                    dataset_id)

    if citation_only:
        citation_block = dataset_dict.get('metadata_blocks', {}).get('citation')

        return """%s\n\nreference: %s""" %\
            (json.dumps(citation_block, indent=4), ref_url)



    return """%s\n\nreference: %s""" %\
        (json.dumps(dataset_dict, indent=4), ref_url)
예제 #11
0
    def make_json_files(self):

        # Set publication status
        #
        filters = {}
        if self.published_only:
            filters.update(query_helper.get_is_published_filter_param())

        # Query for dataset ids
        #
        ds_id_query = Dataset.objects.filter(**filters\
                            ).annotate(ds_id=F('dvobject__id')\
                            ).values_list('ds_id', flat=True\
                            ).order_by('ds_id')

        # Iterate through dataset ids
        #
        #start_time = datetime.now()
        start_time = int(time.time())  # epoch seconds

        cnt = 0
        no_versions_found_list = [45900]

        for ds_id in ds_id_query:
            cnt += 1
            msgt('(%d) Checking dataset id %s' % (cnt, ds_id))
            if ds_id < self.dataset_start_id:
                msg('skipping...(start at dataset id: %d)' %
                    self.dataset_start_id)
                continue

            # Create file name
            #
            fname = 'ds_%s.json' % (str(ds_id).zfill(8))
            full_fname = join(OUTPUT_DIR, fname)

            # Should we overwrite the existing file?
            #
            if isfile(full_fname) and not self.overwrite_existing_files:
                msg('skipping...file already exists')
                continue

            dataset_version = get_latest_dataset_version(ds_id)

            if dataset_version is None:
                msg("Could not find dataset_version!")
                no_versions_found_list.append(ds_id)
                continue

            dataset_as_json = DatasetSerializer(dataset_version).as_json()

            open(full_fname, 'w').write(json.dumps(dataset_as_json, indent=4))
            msg('File written: %s' % full_fname)

            if cnt % 500 == 0:
                self.show_elapsed_time(start_time)
            #if cnt > 10:
            #    self.show_elapsed_time(start_time)
            #    break

        self.show_elapsed_time(start_time)
        print 'no_versions_found_list: %s' % no_versions_found_list
예제 #12
0
def view_side_by_side1(request, dataset_id):

    dsv = get_latest_dataset_version(dataset_id)
    if dsv is None:
        raise Http404("No published datasets for id: %s" % dataset_id)

    template_basename = request.GET.get(PARAM_TEMPLATE_NAME,
                                        'title_citation.html')
    template_fname = path.join('dvobject_api', template_basename)

    try:
        template = get_template(template_fname)
    except TemplateDoesNotExist:
        raise Http404('Template does not exist: %s' % template_fname)

    #formatter = HtmlFormatter(linenos=True, cssclass="friendly")
    formatter = HtmlFormatter(linenos=False, cssclass="friendly")

    # -------------------------------
    # Format raw template
    # -------------------------------
    template_html = open(template.origin.name, 'r').read()
    django_lexer = get_lexer_by_name("django", stripall=True)
    template_snippet = highlight(template_html, django_lexer, formatter)
    template_name = path.basename(template.origin.name)

    # -------------------------------
    # Format Dataset JSON
    # -------------------------------
    dataset_dict = DatasetSerializer(dsv).as_json()

    citation_block = dataset_dict.get('metadata_blocks', {}).get('citation')
    #citation_dict = OrderedDict({'citation_block': citation_block})
    json_string = json.dumps(dataset_dict, indent=4)

    json_lexer = get_lexer_by_name("json", stripall=True)
    dataset_json_snippet = highlight(json_string, json_lexer, formatter)

    # -------------------------------
    # Format Dataverse JSON
    # -------------------------------
    dataverse_id = dataset_dict['ownerInfo']['id']
    try:
        dataverse = Dataverse.objects.select_related('dvobject')\
                    .get(dvobject__id=dataverse_id)
    except Dataverse.DoesNotExist:
        raise Http404('No Dataverse with id: %s' % dataverse_id)

    dataverse_dict = DataverseSerializer(dataverse).as_json()
    #dataset_json_snippet = highlight(json_string, json_lexer, formatter)

    # -------------------------------
    # Overall pygment css
    # -------------------------------
    pygment_css = formatter.get_style_defs('.friendly')

    # -------------------------------
    # API endpoint
    # -------------------------------
    swagger_base_url = '%s://%s' % (settings.SWAGGER_SCHEME,
                                    settings.SWAGGER_HOST)

    lu = dict(
        template_snippet=template_snippet,
        template_name=template_name,
        dataset_json_snippet=dataset_json_snippet,
        pygment_css=pygment_css,
        swagger_base_url=swagger_base_url,
        dataset_id=dataset_id,
        ds=dataset_dict,  # for rendering chosen template
        citation_block=citation_block,  # for rendering chosen template
    )

    lu['rendered_template'] = render_to_string(template_fname, lu)

    return render(request, 'composable/side_by_side.html', lu)
예제 #13
0
    def make_json_files(self):

        # Set publication status
        #
        filters = {}
        if self.published_only:
            filters.update(query_helper.get_is_published_filter_param())

        # Query for dataset ids
        #
        ds_id_query = Dataset.objects.filter(**filters\
                            ).annotate(ds_id=F('dvobject__id')\
                            ).values_list('ds_id', flat=True\
                            ).order_by('ds_id')

        # Iterate through dataset ids
        #
        #start_time = datetime.now()
        start_time = int(time.time()) # epoch seconds

        cnt = 0
        no_versions_found_list = [45900]

        for ds_id in ds_id_query:
            cnt += 1
            msgt('(%d) Checking dataset id %s' % (cnt, ds_id))
            if ds_id < self.dataset_start_id:
                msg('skipping...(start at dataset id: %d)' % self.dataset_start_id)
                continue

            # Create file name
            #
            fname = 'ds_%s.json' % (str(ds_id).zfill(8))
            full_fname = join(OUTPUT_DIR, fname)

            # Should we overwrite the existing file?
            #
            if isfile(full_fname) and not self.overwrite_existing_files:
                msg('skipping...file already exists')
                continue

            dataset_version = get_latest_dataset_version(ds_id)

            if dataset_version is None:
                msg("Could not find dataset_version!")
                no_versions_found_list.append(ds_id)
                continue

            dataset_as_json = DatasetSerializer(dataset_version).as_json()

            open(full_fname, 'w').write(json.dumps(dataset_as_json, indent=4))
            msg('File written: %s' % full_fname)

            if cnt % 500 == 0:
                self.show_elapsed_time(start_time)
            #if cnt > 10:
            #    self.show_elapsed_time(start_time)
            #    break

        self.show_elapsed_time(start_time)
        print 'no_versions_found_list: %s' % no_versions_found_list