コード例 #1
0
def project_dump(request, slug):
    #get the project by the project slug
    project = get_project(slug)
    project_urls = {}
    # Create dictionary from the URLs data pulled from all URLs entries
    project_urls = create_url_dump(project)
    response = HttpResponse(content_type = 'application/json; charset=utf-8')
    json.dump(project_urls, fp=response, sort_keys=True, indent=4, ensure_ascii=False)
    response['Content-Disposition'] = 'attachment; filename=' + slug + '_urls.json'
    return response
コード例 #2
0
    def test_returns_correct_attribute_with_new_value(self):
        project = factories.ProjectWithMetadataFactory(metadata2=None)
        attribute = project.metadata.all()[0].name
        url = factories.URLFactory(url_project=project, attribute=attribute)
        results = url_handler.create_url_dump(project)

        assert results == {
            url.entity: {
                'nominators': [],
                'nomination_count': 0,
                'nomination_score': 0,
                'attributes': {attribute: [url.value]},
            }
        }
コード例 #3
0
    def test_returns_correct_attribute(self):
        project = factories.ProjectWithMetadataFactory(metadata2=None)
        attribute = project.metadata.all()[0].name
        value = models.Metadata_Values.objects.filter(metadata__name__iexact=attribute)[0].value
        url = factories.URLFactory(url_project=project, attribute=attribute, value=value.key)
        results = url_handler.create_url_dump(project)

        assert results == {
            url.entity: {
                'nominators': [],
                'nomination_count': 0,
                'nomination_score': 0,
                'attributes': {attribute: [value.value]},
            }
        }
コード例 #4
0
    def test_returns_expected_with_surt(self):
        project = factories.ProjectFactory()
        surt = 'http://(com,example,www)'
        domain_surt = 'http://(com,example,'
        url = factories.SURTFactory(url_project=project, value=surt)
        results = url_handler.create_url_dump(project)

        assert results == {
            url.entity: {
                'nominators': [],
                'nomination_count': 0,
                'nomination_score': 0,
                'attributes': {},
                'surt': surt,
                'domain_surt': domain_surt
            }
        }
コード例 #5
0
    def test_returns_expected_with_nomination(self):
        project = factories.ProjectFactory()
        url = factories.NominatedURLFactory(url_project=project)
        nominator = url.url_nominator
        results = url_handler.create_url_dump(project)

        assert results == {
            url.entity: {
                'nominators': ['{0} - {1}'.format(
                    nominator.nominator_name,
                    nominator.nominator_institution
                )],
                'nomination_count': 1,
                'nomination_score': int(url.value),
                'attributes': {}
            }
        }