本文整理汇总了Python中tardis.tardis_portal.models.ExperimentACL类的典型用法代码示例。如果您正苦于以下问题:Python ExperimentACL类的具体用法?Python ExperimentACL怎么用?Python ExperimentACL使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ExperimentACL类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _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)
开发者ID:conkiztador,项目名称:mytardis,代码行数:30,代码来源:test_oai.py
示例2: _create_test_data
def _create_test_data():
user = User(username='tom',
first_name='Thomas',
last_name='Atkins',
email='[email protected]')
user.save()
UserProfile(user=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.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")
acl = ExperimentACL(experiment=experiment,
pluginId='django_user',
entityId=str(user.id),
isOwner=True,
canRead=True,
canWrite=True,
canDelete=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED)
acl.save()
return (user, experiment)
开发者ID:JMSS-IT-11-2012,项目名称:mytardis,代码行数:34,代码来源:test_oai.py
示例3: _get_experiment
def _get_experiment(self, entry, user):
experimentId, title, public_access = \
self._get_experiment_details(entry, user)
try:
try:
param_name = ParameterName.objects.\
get(name=self.PARAM_EXPERIMENT_ID, \
schema=AtomImportSchemas.get_schema(Schema.EXPERIMENT))
parameter = ExperimentParameter.objects.\
get(name=param_name, string_value=experimentId)
except ExperimentParameter.DoesNotExist:
raise Experiment.DoesNotExist
return parameter.parameterset.experiment
except Experiment.DoesNotExist:
experiment = Experiment(title=title,
created_by=user,
public_access=public_access)
experiment.save()
self._create_experiment_id_parameter_set(experiment, experimentId)
acl = ExperimentACL(experiment=experiment,
pluginId=django_user,
entityId=user.id,
canRead=True,
canWrite=True,
canDelete=True,
isOwner=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED)
acl.save()
return experiment
开发者ID:tjdett,项目名称:mytardis-app-atom,代码行数:29,代码来源:atom_ingest.py
示例4: setUp
def setUp(self):
from django.contrib.auth.models import User
from tardis.tardis_portal.models import Experiment
from tardis.tardis_portal.models import ExperimentACL
from tardis.tardis_portal.models import Dataset
from tardis.apps.mrtardis.mrtask import MRtask
user = 'tardis_user1'
pwd = 'secret'
email = ''
self.user = User.objects.create_user(user, email, pwd)
self.client = Client()
self.client.login(username=user, password=pwd)
self.experiment = Experiment(approved=True,
title="Test Experiment",
institution_name="Test Institution",
created_by=self.user,
public=False)
self.experiment.save()
acl = ExperimentACL(pluginId="django_user",
entityId="1",
experiment=self.experiment,
canRead=True,
canWrite=True,
canDelete=True,
isOwner=True)
acl.save()
self.test_dataset = Dataset(experiment=self.experiment,
description="test dataset")
self.test_dataset.save()
self.test_mrtask = MRtask(dataset=self.test_dataset)
开发者ID:aaryani,项目名称:aa-migration-test1,代码行数:30,代码来源:tests.py
示例5: createhpcexperiment
def createhpcexperiment(request, user, dl):
from django.contrib.auth.models import User
from tardis.tardis_portal.views import _registerExperimentDocument
import os
import tempfile
# TODO
temp = tempfile.TemporaryFile()
for chunk in dl.chunks():
temp.write(chunk)
temp.seek(0)
metadata = {}
for line in temp:
key, value = line.split("~")
metadata[key] = value
temp.close()
author = metadata["Name"]
title = metadata["Experiment"]
ds_desc = metadata["Facility"]
desc = metadata["Description"]
fname = metadata["FolderName"]
counter = metadata["Counter"]
package = metadata["Package"]
exp = Experiment(
title=title, institution_name="RMIT University", description=desc, created_by=User.objects.get(id=user.pk)
)
exp.save()
eid = exp.id
# Store the author for the dataset
ae = models.Author_Experiment(experiment=exp, author=author, order="1")
ae.save()
auth_key = settings.DEFAULT_AUTH
try:
e = Experiment.objects.get(pk=eid)
except Experiment.DoesNotExist:
logger.exception("Experiment for eid %i in CreateHPCExperiment does not exist" % eid)
acl = ExperimentACL(
experiment=e,
pluginId=django_user,
entityId=str(user.id),
canRead=True,
canWrite=True,
canDelete=True,
isOwner=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED,
)
acl.save()
folder_desc = "%s.%s.%s.%s" % (ds_desc.strip(), package.strip(), fname.strip(), counter.strip())
logger.debug("folder_desc = %s" % folder_desc)
return eid, exp, folder_desc
开发者ID:aaryani,项目名称:CoreTardis,代码行数:59,代码来源:views.py
示例6: setUp
def setUp(self):
from os import path, mkdir
from tempfile import mkdtemp
user = 'tardis_user1'
pwd = 'secret'
email = ''
self.user = User.objects.create_user(user, email, pwd)
self.userProfile = UserProfile(user=self.user)
self.test_dir = mkdtemp()
Location.force_initialize()
self.exp = Experiment(title='test exp1',
institution_name='monash', created_by=self.user)
self.exp.save()
acl = ExperimentACL(
pluginId=django_user,
entityId=str(self.user.id),
experiment=self.exp,
canRead=True,
isOwner=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED,
)
acl.save()
self.dataset = \
Dataset(description='dataset description...')
self.dataset.save()
self.dataset.experiments.add(self.exp)
self.dataset.save()
self.experiment_path = path.join(settings.FILE_STORE_PATH,
str(self.dataset.get_first_experiment().id))
self.dataset_path = path.join(self.experiment_path,
str(self.dataset.id))
if not path.exists(self.experiment_path):
mkdir(self.experiment_path)
if not path.exists(self.dataset_path):
mkdir(self.dataset_path)
# write test file
self.filename = 'testfile.txt'
self.f1 = open(path.join(self.test_dir, self.filename), 'w')
self.f1.write('Test file 1')
self.f1.close()
self.f1_size = path.getsize(path.join(self.test_dir,
self.filename))
self.f1 = open(path.join(self.test_dir, self.filename), 'r')
开发者ID:guillaumeprevost,项目名称:mytardis,代码行数:58,代码来源:test_views.py
示例7: setUp
def setUp(self):
# Create test owner without enough details
username, email, password = ('testuser',
'[email protected]',
'password')
user = User.objects.create_user(username, email, password)
profile = UserProfile(user=user, isDjangoAccount=True)
profile.save()
Location.force_initialize()
# Create test experiment and make user the owner of it
experiment = Experiment(title='Text Experiment',
institution_name='Test Uni',
created_by=user)
experiment.save()
acl = ExperimentACL(
pluginId='django_user',
entityId=str(user.id),
experiment=experiment,
canRead=True,
isOwner=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED,
)
acl.save()
dataset = Dataset(description='dataset description...')
dataset.save()
dataset.experiments.add(experiment)
dataset.save()
def create_datafile(index):
testfile = path.join(path.dirname(__file__), 'fixtures',
'middleware_test%d.txt' % index)
size, sha512sum = get_size_and_sha512sum(testfile)
datafile = Dataset_File(dataset=dataset,
filename=path.basename(testfile),
size=size,
sha512sum=sha512sum)
datafile.save()
base_url = 'file://' + path.abspath(path.dirname(testfile))
location = Location.load_location({
'name': 'test-middleware', 'url': base_url, 'type': 'external',
'priority': 10, 'transfer_provider': 'local'})
replica = Replica(datafile=datafile,
url='file://'+path.abspath(testfile),
protocol='file',
location=location)
if index == 1:
replica.verify()
replica.save()
return Dataset_File.objects.get(pk=datafile.pk)
self.dataset = dataset
self.datafiles = [create_datafile(i) for i in (1,2)]
开发者ID:guillaumeprevost,项目名称:mytardis,代码行数:57,代码来源:test_middleware.py
示例8: _get_experiment
def _get_experiment(self, entry, user):
'''
Finds the Experiment corresponding to this entry.
If it doesn't exist, a new Experiment is created and given
an appropriate ACL for the user.
'''
experimentId, title, public_access = self._get_experiment_details(entry, user)
if (experimentId, title) == (None, None):
return None
if experimentId:
try:
# Try and match ExperimentID if we have one.
param_name = ParameterName.objects.\
get(name=IngestOptions.PARAM_EXPERIMENT_ID, \
schema=AtomImportSchemas.get_schema(Schema.EXPERIMENT))
parameter = ExperimentParameter.objects.\
get(name=param_name, string_value=experimentId)
return parameter.parameterset.experiment
except ExperimentParameter.DoesNotExist:
pass
# Failing that, match ExperimentTitle if possible
if title:
try:
experiment = Experiment.objects.get(title=title, created_by=user)
return experiment
except Experiment.DoesNotExist:
pass
# No existing expriment - shall we create a new one?
if not IngestOptions.ALLOW_EXPERIMENT_CREATION:
logging.getLogger(__name__).info("Skipping dataset. ALLOW_EXPERIMENT_CREATION disabled, so ignoring (experimentId: {0}, title: {1}, user: {2})".format(
experimentId, title, user))
return None
experiment = Experiment(title=title, created_by=user, public_access=public_access)
experiment.save()
self._create_experiment_id_parameter_set(experiment, experimentId)
logging.getLogger(__name__).info("Created experiment {0} (title: {1}, user: {2}, experimentId: {3})".format(
experiment.id, experiment.title, experiment.created_by, experimentId))
acl = ExperimentACL(experiment=experiment,
pluginId=django_user,
entityId=user.id,
canRead=True,
canWrite=True,
canDelete=True,
isOwner=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED)
acl.save()
return experiment
开发者ID:grischa,项目名称:mytardis-app-atom,代码行数:50,代码来源:atom_ingest.py
示例9: create_experiment
def create_experiment(i):
experiment = Experiment(title='Text Experiment #%d' % i,
institution_name='Test Uni',
created_by=user)
experiment.save()
acl = ExperimentACL(
pluginId=django_user,
entityId=str(user.id),
experiment=experiment,
canRead=True,
isOwner=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED,
)
acl.save()
return experiment
开发者ID:guillaumeprevost,项目名称:mytardis,代码行数:15,代码来源:test_views.py
示例10: setUp
def setUp(self):
# Create test owner without enough details
username, email, password = ('testuser',
'[email protected]',
'password')
user = User.objects.create_user(username, email, password)
profile = UserProfile(user=user, isDjangoAccount=True)
profile.save()
# Create test experiment and make user the owner of it
experiment = Experiment(title='Text Experiment',
institution_name='Test Uni',
created_by=user)
experiment.save()
acl = ExperimentACL(
pluginId='django_user',
entityId=str(user.id),
experiment=experiment,
canRead=True,
isOwner=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED,
)
acl.save()
dataset = Dataset(description='dataset description...')
dataset.save()
dataset.experiments.add(experiment)
dataset.save()
def create_datafile(index):
testfile = path.join(path.dirname(__file__), 'fixtures',
'jeol_sem_test%d.txt' % index)
size, sha512sum = get_size_and_sha512sum(testfile)
datafile = Dataset_File(dataset=dataset,
filename=path.basename(testfile),
url='file://'+path.abspath(testfile),
protocol='file',
size=size,
sha512sum=sha512sum)
datafile.verify()
datafile.save()
return datafile
self.dataset = dataset
self.datafiles = [create_datafile(i) for i in (1,2)]
开发者ID:JMSS-IT-11-2012,项目名称:mytardis,代码行数:47,代码来源:test_jeolsem.py
示例11: test_publish
def test_publish(self):
""" Create an experiment and publish it as RIF-CS using RMITANDSService"""
login = self.client.login(username=self.username,
password=self.pwd)
self.assertTrue(login)
# Create simple experiment
exp = models.Experiment(title='test exp1',
institution_name='rmit',
created_by=self.user,
public=True
)
exp.save()
acl = ExperimentACL(
pluginId=django_user,
entityId=str(self.user.id),
experiment=exp,
canRead=True,
isOwner=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED,
)
acl.save()
self.assertEqual(exp.title, 'test exp1')
self.assertEqual(exp.url, None)
self.assertEqual(exp.institution_name, 'rmit')
self.assertEqual(exp.approved, False)
self.assertEqual(exp.handle, None)
self.assertEqual(exp.created_by, self.user)
self.assertEqual(exp.public, True)
self.assertEqual(exp.get_or_create_directory(),
path.join(settings.FILE_STORE_PATH, str(exp.id)))
self.experiment_path = path.join(settings.FILE_STORE_PATH, str(exp.id))
# publish
data = {'legal':'on',
'profile':'default.xml'}
response = self.client.post("/apps/hpctardis/publisher/1/", data)
logger.debug("response=%s" % response)
# check resulting rif-cs
response = self.client.post("/apps/hpctardis/rif_cs/")
self.assertTrue(_grep("test exp1",str(response)))
self.assertTrue(_grep("<key>http://www.rmit.edu.au/HPC/1</key>",str(response)))
self.assertTrue(_grep("""<addressPart type="text">rmit</addressPart>""",str(response)))
self.assertFalse(_grep("<key>http://www.rmit.edu.au/HPC/2</key>",str(response)))
logger.debug("response=%s" % response)
开发者ID:mytardis,项目名称:hpctardis,代码行数:45,代码来源:tests.py
示例12: generate_experiment
def generate_experiment(datasets=[], users=[]):
from tardis.tardis_portal.models import Experiment, ExperimentACL
experiment = Experiment(created_by=users[0])
experiment.save()
for ds in datasets:
ds.experiments.add(experiment)
ds.save()
for user in users:
acl = ExperimentACL(experiment=experiment,
pluginId='django_user',
entityId=str(user.id),
isOwner=True,
canRead=True,
canWrite=True,
canDelete=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED)
acl.save()
return experiment
开发者ID:guillaumeprevost,项目名称:mytardis,代码行数:18,代码来源:generate.py
示例13: setUp
def setUp(self):
user, client = _create_user_and_login()
experiment = Experiment(title='Norwegian Blue',
description='Parrot + 40kV',
created_by=user)
experiment.save()
acl = ExperimentACL(experiment=experiment,
pluginId='django_user',
entityId=str(user.id),
isOwner=False,
canRead=True,
canWrite=False,
canDelete=False,
aclOwnershipType=ExperimentACL.OWNER_OWNED)
acl.save()
self.client = client
self.experiment = experiment
开发者ID:JMSS-IT-11-2012,项目名称:mytardis,代码行数:18,代码来源:tests.py
示例14: 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 = ExperimentACL(experiment=experiment,
pluginId='django_user',
entityId=str(user.id),
isOwner=False,
canRead=True,
canWrite=True,
canDelete=False,
aclOwnershipType=ExperimentACL.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
expect(response.status_code).to_equal(201)
self.acl = acl
self.client = client
self.experiment = experiment
self.params = params
开发者ID:JMSS-IT-11-2012,项目名称:mytardis,代码行数:43,代码来源:test_oaipmh.py
示例15: testRightsRequireValidOwner
def testRightsRequireValidOwner(self):
# Create test owner without enough details
username, email, password = ('testuser',
'[email protected]',
'password')
user = User.objects.create_user(username, email, password)
profile = UserProfile(user=user, isDjangoAccount=True)
profile.save()
# Create test experiment and make user the owner of it
experiment = Experiment(title='Text Experiment',
institution_name='Test Uni',
created_by=user)
experiment.save()
acl = ExperimentACL(
pluginId=django_user,
entityId=str(user.id),
experiment=experiment,
canRead=True,
isOwner=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED,
)
acl.save()
# Create client and login as user
client = Client()
login = client.login(username=username, password=password)
self.assertTrue(login)
# Get "Choose Rights" page, and check that we're forbidden
rights_url = reverse('tardis.tardis_portal.views.choose_rights',
args=[str(experiment.id)])
response = client.get(rights_url)
expect(response.status_code).to_equal(403)
# Fill in remaining details
user.first_name = "Voltaire" # Mononymous persons are just fine
user.save()
# Get "Choose Rights" page, and check that we're now allowed access
response = client.get(rights_url)
expect(response.status_code).to_equal(200)
开发者ID:guillaumeprevost,项目名称:mytardis,代码行数:42,代码来源:test_views.py
示例16: _metadata_extract
def _metadata_extract(self,expname,files,ns,schname,results):
""" Check that we can create an VASP experiment and extract metadata from it"""
login = self.client.login(username=self.username,
password=self.pwd)
self.assertTrue(login)
exp = models.Experiment(title=expname,
institution_name='rmit',
created_by=self.user,
public=True
)
exp.save()
acl = ExperimentACL(
pluginId=django_user,
entityId=str(self.user.id),
experiment=exp,
canRead=True,
isOwner=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED,
)
acl.save()
self.assertEqual(exp.title, expname)
self.assertEqual(exp.url, None)
self.assertEqual(exp.institution_name, 'rmit')
self.assertEqual(exp.approved, False)
self.assertEqual(exp.handle, None)
self.assertEqual(exp.created_by, self.user)
self.assertEqual(exp.public, True)
self.assertEqual(exp.get_or_create_directory(),
path.join(settings.FILE_STORE_PATH, str(exp.id)))
self.experiment_path = path.join(settings.FILE_STORE_PATH, str(exp.id))
dataset = models.Dataset(description="dataset description...",
experiment=exp)
dataset.save()
for f in files:
self._make_datafile(dataset,
path.join(path.abspath(path.dirname(__file__)),f))
go()
self._test_metadata(ns,schname,dataset,results)
开发者ID:mytardis,项目名称:hpctardis,代码行数:41,代码来源:tests.py
示例17: _create_test_experiment
def _create_test_experiment(user, license_):
experiment = Experiment(title='Norwegian Blue',
description='Parrot + 40kV',
created_by=user)
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")
acl = ExperimentACL(experiment=experiment,
pluginId='django_user',
entityId=str(user.id),
isOwner=True,
canRead=True,
canWrite=True,
canDelete=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED)
acl.save()
return experiment
开发者ID:bioscience-data-platform,项目名称:mytardis-app-hrmcoutput,代码行数:23,代码来源:test_view.py
示例18: testCantEditPublicExperiment
def testCantEditPublicExperiment(self):
login = self.client3.login(username=self.user3.username, password='secret')
self.assertTrue(login)
# user3 has acl to write to experiment3
acl = ExperimentACL(
pluginId=django_user,
entityId=str(self.user3.id),
experiment=self.experiment3,
canRead=True,
canWrite=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED,
)
acl.save()
response = self.client3.get('/experiment/edit/%i/' % (self.experiment3.id))
self.assertEqual(response.status_code, 403)
response = self.client3.post('/experiment/edit/%i/' % (self.experiment3.id),
{'anything': True, })
self.assertEqual(response.status_code, 403)
acl.delete()
self.client3.logout()
开发者ID:aaryani,项目名称:aa-migration-test1,代码行数:24,代码来源:test_authorisation.py
示例19: _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 experiment
开发者ID:bioscience-data-platform,项目名称:mytardis-app-repos-producer,代码行数:50,代码来源:test_userinfo.py
示例20: _registerExperimentDocument
def _registerExperimentDocument(filename, created_by, expid=None,
owners=[], username=None):
'''
Register the experiment document and return the experiment id.
:param filename: path of the document to parse (METS or notMETS)
:type filename: string
:param created_by: a User instance
:type created_by: :py:class:`django.contrib.auth.models.User`
:param expid: the experiment ID to use
:type expid: int
:param owners: a list of owners
:type owner: list
:param username: **UNUSED**
:rtype: int
'''
f = open(filename)
firstline = f.readline()
f.close()
if firstline.startswith('<experiment'):
logger.debug('processing simple xml')
processExperiment = ProcessExperiment()
eid = processExperiment.process_simple(filename, created_by, expid)
else:
logger.debug('processing METS')
eid = parseMets(filename, created_by, expid)
# Create a DatasetWrapper for each Dataset
experiment = Experiment.objects.get(pk=eid)
sample = Sample(experiment=experiment, name="Default Sample",
description="A default sample for %s" % experiment.title)
sample.save()
_create_wrappers_for_datasets(sample, experiment)
# Create a Project to wraps the experiment, then create a Sample that
# points to the experiment
project = Project(experiment=experiment)
project.save()
auth_key = ''
try:
auth_key = settings.DEFAULT_AUTH
except AttributeError:
logger.error('no default authentication for experiment ownership set (settings.DEFAULT_AUTH)')
force_user_create = False
try:
force_user_create = settings.DEFAULT_AUTH_FORCE_USER_CREATE
except AttributeError:
pass
if auth_key:
for owner in owners:
logger.debug('** Owner : %s' %owner)
# for each PI
if not owner:
continue
owner_username = None
if '@' in owner:
logger.debug('** Email as username **')
owner_username = auth_service.getUsernameByEmail(auth_key,
owner)
if not owner_username:
logger.debug('** No existing user!! **')
owner_username = owner
owner_user = auth_service.getUser(auth_key, owner_username,
force_user_create=force_user_create)
if owner_user:
# if exist, create ACL
logger.debug('registering owner: ' + owner)
e = Experiment.objects.get(pk=eid)
acl = ExperimentACL(experiment=e,
pluginId=django_user,
entityId=str(owner_user.id),
canRead=True,
canWrite=True,
canDelete=True,
isOwner=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED)
acl.save()
# Also update email
if '@' in owner:
owner_user.email = owner
owner_user.save()
return eid
开发者ID:IntersectAustralia,项目名称:dc2c,代码行数:93,代码来源:views.py
注:本文中的tardis.tardis_portal.models.ExperimentACL类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论