本文整理汇总了Python中tardis.tardis_portal.models.License类的典型用法代码示例。如果您正苦于以下问题:Python License类的具体用法?Python License怎么用?Python License使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了License类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_test_data
def _create_test_data():
user = User(username='tom',
first_name='Thomas',
last_name='Atkins',
email='[email protected]')
user.save()
license_ = License(name='Creative Commons Attribution-NoDerivs 2.5 Australia',
url='http://creativecommons.org/licenses/by-nd/2.5/au/',
internal_description='CC BY 2.5 AU',
allows_distribution=True)
license_.save()
experiment = Experiment(title='Norwegian Blue',
description='Parrot + 40kV',
created_by=user)
experiment.public_access = Experiment.PUBLIC_ACCESS_FULL
experiment.license = license_
experiment.save()
experiment.experimentauthor_set.create(order=0,
author="John Cleese",
url="http://nla.gov.au/nla.party-1")
experiment.experimentauthor_set.create(order=1,
author="Michael Palin",
url="http://nla.gov.au/nla.party-2")
acl = ObjectACL(content_object=experiment,
pluginId='django_user',
entityId=str(user.id),
isOwner=True,
canRead=True,
canWrite=True,
canDelete=True,
aclOwnershipType=ObjectACL.OWNER_OWNED)
acl.save()
return user, experiment
示例2: testListRecords
def testListRecords(self):
results = self._getProvider().listRecords('rif')
# Iterate through headers
for header, metadata, _ in results:
if header.identifier().startswith('experiment'):
expect(header.identifier()).to_contain(str(self._experiment.id))
expect(header.datestamp().replace(tzinfo=pytz.utc))\
.to_equal(get_local_time(self._experiment.update_time))
expect(metadata.getField('title'))\
.to_equal(str(self._experiment.title))
expect(metadata.getField('description'))\
.to_equal(str(self._experiment.description))
expect(metadata.getField('licence_uri'))\
.to_equal(License.get_none_option_license().url)
expect(metadata.getField('licence_name'))\
.to_equal(License.get_none_option_license().name)
else:
expect(header.identifier()).to_contain(str(self._user.id))
expect(header.datestamp().replace(tzinfo=pytz.utc))\
.to_equal(get_local_time(self._user.last_login))
expect(metadata.getField('id')).to_equal(self._user.id)
expect(metadata.getField('email'))\
.to_equal(str(self._user.email))
expect(metadata.getField('given_name'))\
.to_equal(str(self._user.first_name))
expect(metadata.getField('family_name'))\
.to_equal(str(self._user.last_name))
# There should only have been one
expect(len(results)).to_equal(2)
# Remove public flag
self._experiment.public_access = Experiment.PUBLIC_ACCESS_NONE
self._experiment.save()
headers = self._getProvider().listRecords('rif')
# Not public, so should not appear
expect(len(headers)).to_equal(0)
示例3: _create_license
def _create_license():
license_ = License(name='Creative Commons Attribution-NoDerivs 2.5 Australia',
url='http://creativecommons.org/licenses/by-nd/2.5/au/',
internal_description='CC BY 2.5 AU',
allows_distribution=True)
license_.save()
return license_
示例4: retrieve_licenses
def retrieve_licenses(request):
try:
type_ = int(request.REQUEST['public_access'])
licenses = License.get_suitable_licenses(type_)
except KeyError:
licenses = License.get_suitable_licenses()
return HttpResponse(json.dumps([model_to_dict(x) for x in licenses]))
示例5: testGetRecord
def testGetRecord(self):
header, metadata, about = self._getProvider().getRecord('rif',
_get_first_exp_id())
self.assertIn(str(self._experiment.id), header.identifier())
self.assertEqual(
header.datestamp().replace(tzinfo=pytz.utc),
get_local_time(self._experiment.update_time))
ns = 'http://ands.org.au/standards/rif-cs/registryObjects#relatedInfo'
ps_id = ExperimentParameterSet.objects\
.filter(experiment=self._experiment,schema__namespace=ns).first().id
self.assertEqual(
metadata.getField('id'), self._experiment.id)
self.assertEqual(
metadata.getField('title'), str(self._experiment.title))
self.assertEqual(
metadata.getField('description'),
str(self._experiment.description))
self.assertEqual(
metadata.getField('licence_uri'),
License.get_none_option_license().url)
self.assertEqual(
metadata.getField('licence_name'),
License.get_none_option_license().name)
self.assertEqual(
metadata.getField('related_info'),
[{'notes': 'This is a note.', \
'identifier': 'https://www.example.com/', \
'type': 'website', \
'id': ps_id, \
'title': 'Google'}])
self.assertEqual(
len(metadata.getField('collectors')), 2)
self.assertIsNone(about)
示例6: _create_test_data
def _create_test_data():
user = User(username='tom',
first_name='Thomas',
last_name='Atkins',
email='[email protected]')
user.save()
user2 = User(username='otheradmin', email='[email protected]')
user2.save()
map(lambda u: UserProfile(user=u).save(), [user, user2])
license_ = License(name='Creative Commons Attribution-NoDerivs 2.5 Australia',
url='http://creativecommons.org/licenses/by-nd/2.5/au/',
internal_description='CC BY 2.5 AU',
allows_distribution=True)
license_.save()
experiment = Experiment(title='Norwegian Blue',
description='Parrot + 40kV',
created_by=user)
experiment.public_access = Experiment.PUBLIC_ACCESS_FULL
experiment.license = license_
experiment.save()
acl = ExperimentACL(experiment=experiment,
pluginId='django_user',
entityId=str(user2.id),
isOwner=True,
canRead=True,
canWrite=True,
canDelete=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED)
acl.save()
return (user, experiment)
示例7: _create_test_data
def _create_test_data():
"""
Create Single experiment with two owners
"""
user1 = User(username='tom',
first_name='Thomas',
last_name='Atkins',
email='[email protected]')
user1.save()
UserProfile(user=user1).save()
user2 = User(username='joe',
first_name='Joe',
last_name='Bloggs',
email='[email protected]')
user2.save()
UserProfile(user=user2).save()
license_ = License(name='Creative Commons Attribution-NoDerivs '
+ '2.5 Australia',
url='http://creativecommons.org/licenses/by-nd/2.5/au/',
internal_description='CC BY 2.5 AU',
allows_distribution=True)
license_.save()
experiment = Experiment(title='Norwegian Blue',
description='Parrot + 40kV',
created_by=user1)
experiment.public_access = Experiment.PUBLIC_ACCESS_FULL
experiment.license = license_
experiment.save()
experiment.author_experiment_set.create(order=0,
author="John Cleese",
url="http://nla.gov.au/nla.party-1")
experiment.author_experiment_set.create(order=1,
author="Michael Palin",
url="http://nla.gov.au/nla.party-2")
acl1 = ExperimentACL(experiment=experiment,
pluginId='django_user',
entityId=str(user1.id),
isOwner=True,
canRead=True,
canWrite=True,
canDelete=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED)
acl1.save()
acl2 = ExperimentACL(experiment=experiment,
pluginId='django_user',
entityId=str(user2.id),
isOwner=True,
canRead=True,
canWrite=True,
canDelete=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED)
acl2.save()
return (user1, user2, experiment)
示例8: testListRecords
def testListRecords(self):
results = self._getProvider().listRecords('rif')
# Iterate through headers
for header, metadata, _ in results:
if header.identifier().startswith('experiment'):
e = self._experiment if header.identifier() == _get_first_exp_id() \
else self._experiment2
self.assertIn(str(e.id), header.identifier())
self.assertEqual(
header.datestamp().replace(tzinfo=pytz.utc),
get_local_time(e.update_time))
self.assertEqual(
metadata.getField('title'), str(e.title))
self.assertEqual(
metadata.getField('description'), str(e.description))
self.assertEqual(
metadata.getField('licence_uri'),
License.get_none_option_license().url)
self.assertEqual(
metadata.getField('licence_name'),
License.get_none_option_license().name)
if e == self._experiment:
ns = 'http://ands.org.au/standards/rif-cs/registryObjects#relatedInfo'
ps_id = ExperimentParameterSet.objects\
.filter(experiment=self._experiment,schema__namespace=ns).first().id
self.assertEqual(
metadata.getField('related_info'),
[{'notes': 'This is a note.', \
'identifier': 'https://www.example.com/', \
'type': 'website', \
'id': ps_id, \
'title': 'Google'}])
else:
self.assertEqual(
metadata.getField('related_info'), [{}])
else:
self.assertIn(str(self._user.id), header.identifier())
self.assertEqual(
header.datestamp().replace(tzinfo=pytz.utc),
get_local_time(self._user.last_login))
self.assertEqual(metadata.getField('id'), self._user.id)
self.assertEqual(
metadata.getField('email'), str(self._user.email))
self.assertEqual(
metadata.getField('given_name'),
str(self._user.first_name))
self.assertEqual(
metadata.getField('family_name'),
str(self._user.last_name))
# There should have been two
self.assertEqual(len(results), 2)
# Remove public flag on first experiment
self._experiment.public_access = Experiment.PUBLIC_ACCESS_NONE
self._experiment.save()
headers = self._getProvider().listRecords('rif')
# Should now be one
self.assertEqual(len(headers), 1)
示例9: _get_experiment_metadata
def _get_experiment_metadata(self, experiment, metadataPrefix):
license_ = experiment.license or License.get_none_option_license()
# Access Rights statement
if experiment.public_access == Experiment.PUBLIC_ACCESS_METADATA:
access = "Only metadata is publicly available online."+\
" Requests for further access should be directed to a"+\
" listed data manager."
else:
access = "All data is publicly available online."
def get_related_info(ps):
psm = ParameterSetManager(ps)
parameter_names = ['type','identifier','title','notes']
return dict([('id', ps.id)]+ # Use set ID
zip(parameter_names,
(psm.get_param(k, True) for k in parameter_names)))
ns = 'http://ands.org.au/standards/rif-cs/registryObjects#relatedInfo'
related_info = map(get_related_info, ExperimentParameterSet.objects\
.filter(experiment=experiment,
schema__namespace=ns))
return Metadata({
'_writeMetadata': self._get_experiment_writer_func(),
'id': experiment.id,
'title': experiment.title,
'description': experiment.description,
# Note: Property names are US-spelling, but RIF-CS is Australian
'licence_name': license_.name,
'licence_uri': license_.url,
'access': access,
'collectors': [experiment.created_by],
'managers': experiment.get_owners(),
'related_info': related_info
})
示例10: testListRecords
def testListRecords(self):
results = self._getProvider().listRecords('rif')
# Iterate through headers
for header, metadata, _ in results:
if header.identifier().startswith('experiment'):
e = self._experiment if header.identifier() == 'experiment/1' \
else self._experiment2
expect(header.identifier()).to_contain(str(e.id))
expect(header.datestamp().replace(tzinfo=pytz.utc))\
.to_equal(get_local_time(e.update_time))
expect(metadata.getField('title'))\
.to_equal(str(e.title))
expect(metadata.getField('description'))\
.to_equal(str(e.description))
expect(metadata.getField('licence_uri'))\
.to_equal(License.get_none_option_license().url)
expect(metadata.getField('licence_name'))\
.to_equal(License.get_none_option_license().name)
if e == self._experiment:
expect(metadata.getField('related_info'))\
.to_equal([{'notes': 'This is a note.', \
'identifier': 'https://www.example.com/', \
'type': 'website', \
'id': 1, \
'title': 'Google'}])
else:
expect(metadata.getField('related_info')).to_equal([{}])
else:
expect(header.identifier()).to_contain(str(self._user.id))
expect(header.datestamp().replace(tzinfo=pytz.utc))\
.to_equal(get_local_time(self._user.last_login))
expect(metadata.getField('id')).to_equal(self._user.id)
expect(metadata.getField('email'))\
.to_equal(str(self._user.email))
expect(metadata.getField('given_name'))\
.to_equal(str(self._user.first_name))
expect(metadata.getField('family_name'))\
.to_equal(str(self._user.last_name))
# There should have been two
expect(len(results)).to_equal(2)
# Remove public flag on first experiment
self._experiment.public_access = Experiment.PUBLIC_ACCESS_NONE
self._experiment.save()
headers = self._getProvider().listRecords('rif')
# Should now be one
expect(len(headers)).to_equal(1)
示例11: setUp
def setUp(self):
self.ns = {'r': 'http://ands.org.au/standards/rif-cs/registryObjects',
'o': 'http://www.openarchives.org/OAI/2.0/'}
user, client = _create_user_and_login()
license_ = License(name='Creative Commons Attribution-NoDerivs 2.5 Australia',
url='http://creativecommons.org/licenses/by-nd/2.5/au/',
internal_description='CC BY 2.5 AU',
allows_distribution=True)
license_.save()
experiment = Experiment(title='Norwegian Blue',
description='Parrot + 40kV',
created_by=user)
experiment.public_access = Experiment.PUBLIC_ACCESS_FULL
experiment.license = license_
experiment.save()
acl = ObjectACL(content_object=experiment,
pluginId='django_user',
entityId=str(user.id),
isOwner=False,
canRead=True,
canWrite=True,
canDelete=False,
aclOwnershipType=ObjectACL.OWNER_OWNED)
acl.save()
params = {'code': '010107',
'name': 'Mathematical Logic, Set Theory, Lattices and Universal Algebra',
'uri': 'http://purl.org/asc/1297.0/2008/for/010107'}
try:
response = client.post(\
reverse('tardis.apps.anzsrc_codes.views.'\
+'list_or_create_for_code',
args=[experiment.id]),
data=json.dumps(params),
content_type='application/json')
except: # no internet most likely
from nose.plugins.skip import SkipTest
raise SkipTest
# Check related info was created
expect(response.status_code).to_equal(201)
self.acl = acl
self.client = client
self.experiment = experiment
self.params = params
示例12: setUp
def setUp(self):
self.restrictiveLicense = License(name="Restrictive License",
url="http://example.test/rl",
internal_description="Description...",
allows_distribution=False)
self.restrictiveLicense.save()
self.permissiveLicense = License(name="Permissive License",
url="http://example.test/pl",
internal_description="Description...",
allows_distribution=True)
self.permissiveLicense.save()
self.inactiveLicense = License(name="Inactive License",
url="http://example.test/ial",
internal_description="Description...",
allows_distribution=True,
is_active=False)
self.inactiveLicense.save()
示例13: setUp
def setUp(self):
self.ns = {'r': 'http://ands.org.au/standards/rif-cs/registryObjects',
'o': 'http://www.openarchives.org/OAI/2.0/'}
user, client = _create_user_and_login()
license_ = License(name='Creative Commons Attribution-NoDerivs '
'2.5 Australia',
url='http://creativecommons.org/licenses/by-nd/'
'2.5/au/',
internal_description='CC BY 2.5 AU',
allows_distribution=True)
license_.save()
experiment = Experiment(title='Norwegian Blue',
description='Parrot + 40kV',
created_by=user)
experiment.public_access = Experiment.PUBLIC_ACCESS_FULL
experiment.license = license_
experiment.save()
acl = ObjectACL(content_object=experiment,
pluginId='django_user',
entityId=str(user.id),
isOwner=False,
canRead=True,
canWrite=True,
canDelete=False,
aclOwnershipType=ObjectACL.OWNER_OWNED)
acl.save()
params = {'type': 'website',
'identifier': 'https://www.google.com/',
'title': 'Google',
'notes': 'This is a note.'}
response = client.post(\
reverse('tardis.apps.related_info.views.' +
'list_or_create_related_info',
args=[experiment.id]),
data=json.dumps(params),
content_type='application/json')
# Check related info was created
self.assertEqual(response.status_code, 201)
self.acl = acl
self.client = client
self.experiment = experiment
self.params = params
示例14: testGetRecord
def testGetRecord(self):
header, metadata, about = self._getProvider().getRecord('rif',
'experiment/1')
expect(header.identifier()).to_contain(str(self._experiment.id))
expect(header.datestamp().replace(tzinfo=pytz.utc))\
.to_equal(get_local_time(self._experiment.update_time))
expect(metadata.getField('id')).to_equal(self._experiment.id)
expect(metadata.getField('title'))\
.to_equal(str(self._experiment.title))
expect(metadata.getField('description'))\
.to_equal(str(self._experiment.description))
expect(metadata.getField('licence_uri'))\
.to_equal(License.get_none_option_license().url)
expect(metadata.getField('licence_name'))\
.to_equal(License.get_none_option_license().name)
expect(metadata.getField('related_info'))\
.to_equal([])
expect(about).to_equal(None)
示例15: _get_experiment_metadata
def _get_experiment_metadata(self, experiment, metadataPrefix):
license_ = experiment.license or License.get_none_option_license()
# Access Rights statement
access_type = None
if experiment.public_access == Experiment.PUBLIC_ACCESS_METADATA:
access = "Only metadata is publicly available online." + \
" Requests for further access should be directed to a" + \
" listed data manager."
access_type = "restricted"
else:
access = "All data is publicly available online."
access_type = "open"
def get_related_info(ps):
psm = ParameterSetManager(ps)
parameter_names = ['type', 'identifier', 'title', 'notes']
try:
return dict([('id', ps.id)] + # Use set ID
zip(parameter_names,
(psm.get_param(k, True) \
for k in parameter_names)))
except ExperimentParameter.DoesNotExist:
return dict() # drop Related_Info record with missing fields
ns = 'http://ands.org.au/standards/rif-cs/registryObjects#relatedInfo'
related_info = map(
get_related_info,
ExperimentParameterSet.objects.filter(experiment=experiment,
schema__namespace=ns))
def get_subject(ps, type_):
psm = ParameterSetManager(ps)
return {'text': psm.get_param('code', True),
'type': type_}
ns = 'http://purl.org/asc/1297.0/2008/for/'
subjects = [get_subject(ps, 'anzsrc-for')
for ps in ExperimentParameterSet.objects.filter(
experiment=experiment, schema__namespace=ns)]
collectors = experiment.experimentauthor_set.exclude(url='')
return Metadata(
experiment,
{
'_writeMetadata': self._get_experiment_writer_func(),
'id': experiment.id,
'title': experiment.title,
'description': experiment.description,
# Note: Property names are US-spelling, but RIF-CS is Australian
'licence_name': license_.name,
'licence_uri': license_.url,
'access': access,
'access_type': access_type,
'collectors': collectors,
'managers': experiment.get_owners(),
'related_info': related_info,
'subjects': subjects
})