本文整理汇总了Python中tardis.tardis_portal.models.License.get_none_option_license方法的典型用法代码示例。如果您正苦于以下问题:Python License.get_none_option_license方法的具体用法?Python License.get_none_option_license怎么用?Python License.get_none_option_license使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tardis.tardis_portal.models.License
的用法示例。
在下文中一共展示了License.get_none_option_license方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testGetRecord
# 需要导入模块: from tardis.tardis_portal.models import License [as 别名]
# 或者: from tardis.tardis_portal.models.License import get_none_option_license [as 别名]
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)
示例2: testListRecords
# 需要导入模块: from tardis.tardis_portal.models import License [as 别名]
# 或者: from tardis.tardis_portal.models.License import get_none_option_license [as 别名]
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: testListRecords
# 需要导入模块: from tardis.tardis_portal.models import License [as 别名]
# 或者: from tardis.tardis_portal.models.License import get_none_option_license [as 别名]
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)
示例4: _get_experiment_metadata
# 需要导入模块: from tardis.tardis_portal.models import License [as 别名]
# 或者: from tardis.tardis_portal.models.License import get_none_option_license [as 别名]
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
})
示例5: testListRecords
# 需要导入模块: from tardis.tardis_portal.models import License [as 别名]
# 或者: from tardis.tardis_portal.models.License import get_none_option_license [as 别名]
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)
示例6: testGetRecord
# 需要导入模块: from tardis.tardis_portal.models import License [as 别名]
# 或者: from tardis.tardis_portal.models.License import get_none_option_license [as 别名]
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)
示例7: _get_experiment_metadata
# 需要导入模块: from tardis.tardis_portal.models import License [as 别名]
# 或者: from tardis.tardis_portal.models.License import get_none_option_license [as 别名]
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
})
示例8: _get_experiment_metadata
# 需要导入模块: from tardis.tardis_portal.models import License [as 别名]
# 或者: from tardis.tardis_portal.models.License import get_none_option_license [as 别名]
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"]
try:
return dict(
[("id", ps.id)]
+ zip(parameter_names, (psm.get_param(k, True) for k in parameter_names)) # Use set ID
)
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.author_experiment_set.exclude(url="")
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": collectors,
"managers": experiment.get_owners(),
"related_info": related_info,
"subjects": subjects,
}
)
示例9: testGetRecord
# 需要导入模块: from tardis.tardis_portal.models import License [as 别名]
# 或者: from tardis.tardis_portal.models.License import get_none_option_license [as 别名]
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([{'notes': 'This is a note.', \
'identifier': 'https://www.example.com/', \
'type': 'website', \
'id': 1, \
'title': 'Google'}])
expect(len(metadata.getField('collectors')))\
.to_equal(2)
expect(about).to_equal(None)
示例10: process_form
# 需要导入模块: from tardis.tardis_portal.models import License [as 别名]
# 或者: from tardis.tardis_portal.models.License import get_none_option_license [as 别名]
#.........这里部分代码省略.........
institutions = '; '.join(
set([author['institution'] for author in form_state['authors']]))
publication.institution_name = institutions
# Attach the publication details schema
pub_details_schema = Schema.objects.get(
namespace=getattr(settings, 'PUBLICATION_DETAILS_SCHEMA',
default_settings.PUBLICATION_DETAILS_SCHEMA))
pub_details_parameter_set = ExperimentParameterSet(
schema=pub_details_schema,
experiment=publication)
pub_details_parameter_set.save()
# Add the acknowledgements
acknowledgements_parameter_name = ParameterName.objects.get(
schema=pub_details_schema,
name='acknowledgements')
ExperimentParameter(name=acknowledgements_parameter_name,
parameterset=pub_details_parameter_set,
string_value=form_state['acknowledgements']).save()
# Set the release date
set_embargo_release_date(
publication,
dateutil.parser.parse(
form_state[
'embargo']))
# Set the license
try:
publication.license = License.objects.get(
pk=form_state['selectedLicenseId'],
is_active=True,
allows_distribution=True)
except License.DoesNotExist:
publication.license = License.get_none_option_license()
publication.save()
# Send emails about publication in draft
subject, message_content = email_pub_requires_authorisation(
request.user.username,
request.build_absolute_uri(
reverse('tardis_portal.view_experiment',
args=(publication.id,))),
request.build_absolute_uri(
'/apps/publication-forms/approvals/'))
try:
send_mail(subject,
message_content,
getattr(
settings, 'PUBLICATION_NOTIFICATION_SENDER_EMAIL',
default_settings.PUBLICATION_NOTIFICATION_SENDER_EMAIL),
get_pub_admin_email_addresses(),
fail_silently=False)
subject, message_content = email_pub_awaiting_approval(
publication.title)
send_mail_to_authors(publication, subject, message_content,
fail_silently=False)
except Exception as e:
logger.error(
"failed to send publication notification email(s): %s" %
repr(e)
)
return HttpResponse(
json.dumps({
'error': 'Failed to send notification email - please '
'contact the %s administrator (%s), '
'or try again later. Your draft is saved.'
% (get_site_admin_email(),
getattr(settings, 'SITE_TITLE', 'MyTardis'))
}),
content_type="application/json")
# Remove the draft status
remove_draft_status(publication)
# Automatically approve publications if approval is not required
if not getattr(settings, 'PUBLICATIONS_REQUIRE_APPROVAL',
default_settings.PUBLICATIONS_REQUIRE_APPROVAL):
approve_publication(request, publication, message=None,
send_email=False)
# approve_publication will delete the form state, so don't
# bother saving is and return.
form_state['action'] = ''
return HttpResponse(json.dumps(form_state),
content_type="appication/json")
# Trigger publication record update
tasks.update_publication_records.delay()
# Clear the form action and save the state
form_state['action'] = ''
form_state_parameter.string_value = json.dumps(form_state)
form_state_parameter.save()
return HttpResponse(json.dumps(form_state), content_type="appication/json")