本文整理汇总了Python中tardis.tardis_portal.models.ObjectACL.save方法的典型用法代码示例。如果您正苦于以下问题:Python ObjectACL.save方法的具体用法?Python ObjectACL.save怎么用?Python ObjectACL.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tardis.tardis_portal.models.ObjectACL
的用法示例。
在下文中一共展示了ObjectACL.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from tardis.tardis_portal.models import ObjectACL [as 别名]
# 或者: from tardis.tardis_portal.models.ObjectACL import save [as 别名]
def setUp(self):
super(MyTardisResourceTestCase, self).setUp()
self.username = 'mytardis'
self.password = 'mytardis'
self.user = User.objects.create_user(username=self.username,
password=self.password)
test_auth_service = AuthService()
test_auth_service._set_user_from_dict(
self.user,
user_dict={'first_name': 'Testing',
'last_name': 'MyTardis API',
'email': '[email protected]'},
auth_method="None")
self.user.user_permissions.add(
Permission.objects.get(codename='change_dataset'))
self.user.user_permissions.add(
Permission.objects.get(codename='add_dataset_file'))
self.user_profile = UserProfile(user=self.user).save()
self.testexp = Experiment(title="test exp")
self.testexp.approved = True
self.testexp.created_by = self.user
self.testexp.locked = False
self.testexp.save()
testacl = ObjectACL(
content_type=self.testexp.get_ct(),
object_id=self.testexp.id,
pluginId=django_user,
entityId=str(self.user.id),
canRead=True,
canWrite=True,
canDelete=True,
isOwner=True,
aclOwnershipType=ObjectACL.OWNER_OWNED)
testacl.save()
示例2: _create_test_experiment
# 需要导入模块: from tardis.tardis_portal.models import ObjectACL [as 别名]
# 或者: from tardis.tardis_portal.models.ObjectACL import save [as 别名]
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.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 experiment
示例3: setUp
# 需要导入模块: from tardis.tardis_portal.models import ObjectACL [as 别名]
# 或者: from tardis.tardis_portal.models.ObjectACL import save [as 别名]
def setUp(self):
# Create test owner without enough details
username, email, password = ("testuser", "[email protected]", "password")
user = User.objects.create_user(username, email, password)
# Need UserAuthentication
UserAuthentication(userProfile=user.userprofile, username=username, authenticationMethod="localdb").save()
# Create staging dir
from os import path, makedirs
staging_dir = path.join(settings.STAGING_PATH, username)
if not path.exists(staging_dir):
makedirs(staging_dir)
# Ensure that staging dir is set up properly
expect(get_full_staging_path(username)).to_be_truthy()
# 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 = ObjectACL(
pluginId=django_user,
entityId=str(user.id),
content_object=experiment,
canRead=True,
isOwner=True,
aclOwnershipType=ObjectACL.OWNER_OWNED,
)
acl.save()
self.dataset = Dataset(description="dataset description...")
self.dataset.save()
self.dataset.experiments.add(experiment)
self.dataset.save()
self.username, self.password = (username, password)
示例4: testRightsRequireValidOwner
# 需要导入模块: from tardis.tardis_portal.models import ObjectACL [as 别名]
# 或者: from tardis.tardis_portal.models.ObjectACL import save [as 别名]
def testRightsRequireValidOwner(self):
# Create test owner without enough details
username, email, password = ("testuser", "[email protected]", "password")
user = User.objects.create_user(username, email, password)
# 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 = ObjectACL(
pluginId=django_user,
entityId=str(user.id),
content_object=experiment,
canRead=True,
isOwner=True,
aclOwnershipType=ObjectACL.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)
示例5: _create_test_data
# 需要导入模块: from tardis.tardis_portal.models import ObjectACL [as 别名]
# 或者: from tardis.tardis_portal.models.ObjectACL import save [as 别名]
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
示例6: _get_experiment
# 需要导入模块: from tardis.tardis_portal.models import ObjectACL [as 别名]
# 或者: from tardis.tardis_portal.models.ObjectACL import save [as 别名]
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 = ObjectACL(content_object=experiment,
pluginId=django_user,
entityId=user.id,
canRead=True,
canWrite=True,
canDelete=True,
isOwner=True,
aclOwnershipType=ObjectACL.OWNER_OWNED)
acl.save()
return experiment
示例7: setUp
# 需要导入模块: from tardis.tardis_portal.models import ObjectACL [as 别名]
# 或者: from tardis.tardis_portal.models.ObjectACL import save [as 别名]
def setUp(self):
self.client = Client()
# old_user
user_old_username = 'tardis_user1'
# new_user
user_new_username = 'tardis_user2'
pwd = 'secret'
email = '[email protected]'
self.user_new = User.objects.create_user(user_new_username, email, pwd)
self.user_old = User.objects.create_user(user_old_username, email, pwd)
# create group
self.group = Group.objects.create(name='test group')
# add old user to group
self.group.user_set.add(self.user_old)
# add user auth
user_auth = UserAuthentication(userProfile=UserProfile.objects.get(user=self.user_old),
username= self.user_old.username,
authenticationMethod='localdb')
user_auth.save()
# add experiments
experiment = Experiment(title='Text Experiment',
institution_name='Test Uni',
created_by=self.user_old)
experiment.save()
acl = ObjectACL(
pluginId='django_user',
entityId=str(self.user_old.id),
content_object=experiment,
canRead=True,
isOwner=True,
aclOwnershipType=ObjectACL.OWNER_OWNED,
)
acl.save()
示例8: setUp
# 需要导入模块: from tardis.tardis_portal.models import ObjectACL [as 别名]
# 或者: from tardis.tardis_portal.models.ObjectACL import save [as 别名]
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 = ObjectACL(
pluginId='django_user',
entityId=str(user.id),
content_object=experiment,
canRead=True,
canWrite=True,
canDelete=True,
isOwner=True,
aclOwnershipType=ObjectACL.OWNER_OWNED)
acl.save()
dataset = Dataset(description='dataset description...')
dataset.save()
dataset.experiments.add(experiment)
dataset.save()
def create_datafile(filename):
testfile = path.join(path.dirname(__file__), 'fixtures',
filename)
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-grabber', 'url': base_url, 'type': 'external',
'priority': 10, 'transfer_provider': 'local'})
replica = Replica(datafile=datafile,
url='file://'+path.abspath(testfile),
protocol='file',
location=location)
replica.verify()
replica.save()
return Dataset_File.objects.get(pk=datafile.pk)
self.dataset = dataset
self.datafiles = [create_datafile('data_grabber_test1.admin'),
create_datafile('testfile.txt')
]
示例9: setUp
# 需要导入模块: from tardis.tardis_portal.models import ObjectACL [as 别名]
# 或者: from tardis.tardis_portal.models.ObjectACL import save [as 别名]
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).save()
self.test_dir = mkdtemp()
Location.force_initialize()
self.exp = Experiment(title='test exp1',
institution_name='monash', created_by=self.user)
self.exp.save()
acl = ObjectACL(
pluginId=django_user,
entityId=str(self.user.id),
content_object=self.exp,
canRead=True,
isOwner=True,
aclOwnershipType=ObjectACL.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')
示例10: add_epn_group_acl
# 需要导入模块: from tardis.tardis_portal.models import ObjectACL [as 别名]
# 或者: from tardis.tardis_portal.models.ObjectACL import save [as 别名]
def add_epn_group_acl(sender, **kwargs):
try:
par_name = ParameterName.objects.get(
name='EPN', schema=Schema.objects.get(
namespace='http://www.tardis.edu.au/schemas/as/'
'experiment/2010/09/21'))
except (ParameterName.DoesNotExist, Schema.DoesNotExist):
return
exp_par = kwargs['instance']
if exp_par.name != par_name:
return
exp = exp_par.parameterset.experiment
try:
epn = exp_par.string_value
# create vbl group
acl = ObjectACL.objects.filter(
content_type=exp.get_ct(),
object_id=exp.id,
pluginId='vbl_group',
entityId=epn,
canRead=True,
aclOwnershipType=ObjectACL.SYSTEM_OWNED)
if len(acl) == 0:
acl = ObjectACL(
content_type=exp.get_ct(),
object_id=exp.id,
pluginId='vbl_group',
entityId=epn,
canRead=True,
aclOwnershipType=ObjectACL.SYSTEM_OWNED)
acl.save()
except Exception:
logger.exception('trouble creating EPN ACL')
try:
beamline_group = "BEAMLINE_MX"
group, created = Group.objects.get_or_create(name=beamline_group)
# beamline group
ObjectACL.objects.get_or_create(
content_type=exp.get_ct(),
object_id=exp.id,
pluginId=django_group,
entityId=str(group.id),
canRead=True,
aclOwnershipType=ObjectACL.SYSTEM_OWNED)
# finally, always add acl for admin group
group, created = Group.objects.get_or_create(name='admin')
ObjectACL.objects.get_or_create(
content_type=exp.get_ct(),
object_id=exp.id,
pluginId=django_group,
entityId=str(group.id),
isOwner=True,
canRead=True,
aclOwnershipType=ObjectACL.SYSTEM_OWNED)
except Exception:
logger.exception('trouble creating beamline and admin ACLs')
示例11: setUp
# 需要导入模块: from tardis.tardis_portal.models import ObjectACL [as 别名]
# 或者: from tardis.tardis_portal.models.ObjectACL import save [as 别名]
def setUp(self):
# Create test owner without enough details
username, email, password = ('testuser',
'[email protected]',
'password')
user = User.objects.create_user(username, email, password)
# 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 = ObjectACL(
pluginId='django_user',
entityId=str(user.id),
content_object=experiment,
canRead=True,
isOwner=True,
aclOwnershipType=ObjectACL.OWNER_OWNED,
)
acl.save()
dataset = Dataset(description='dataset description...')
dataset.save()
dataset.experiments.add(experiment)
dataset.save()
base_path = path.join(path.dirname(__file__), 'fixtures')
s_box = StorageBox.get_default_storage(location=base_path)
def create_datafile(index):
testfile = path.join(base_path, 'middleware_test%d.txt' % index)
size, sha512sum = get_size_and_sha512sum(testfile)
datafile = DataFile(dataset=dataset,
filename=path.basename(testfile),
size=size,
sha512sum=sha512sum)
datafile.save()
dfo = DataFileObject(
datafile=datafile,
storage_box=s_box,
uri=path.basename(testfile))
dfo.save()
if index != 1:
dfo.verified = False
dfo.save(update_fields=['verified'])
return DataFile.objects.get(pk=datafile.pk)
self.dataset = dataset
self.datafiles = [create_datafile(i) for i in (1, 2)]
示例12: create_experiment
# 需要导入模块: from tardis.tardis_portal.models import ObjectACL [as 别名]
# 或者: from tardis.tardis_portal.models.ObjectACL import save [as 别名]
def create_experiment(request,
template_name='tardis_portal/create_experiment.html'):
"""Create a new experiment view.
:param request: a HTTP Request instance
:type request: :class:`django.http.HttpRequest`
:param template_name: the path of the template to render
:type template_name: string
:rtype: :class:`django.http.HttpResponse`
"""
c = {
'subtitle': 'Create Experiment',
'user_id': request.user.id,
}
if request.method == 'POST':
form = ExperimentForm(request.POST)
if form.is_valid():
full_experiment = form.save(commit=False)
# group/owner assignment stuff, soon to be replaced
experiment = full_experiment['experiment']
experiment.created_by = request.user
full_experiment.save_m2m()
# add defaul ACL
acl = ObjectACL(content_object=experiment,
pluginId=django_user,
entityId=str(request.user.id),
canRead=True,
canWrite=True,
canDelete=True,
isOwner=True,
aclOwnershipType=ObjectACL.OWNER_OWNED)
acl.save()
request.POST = {'status': "Experiment Created."}
return HttpResponseSeeAlso(reverse('tardis_portal.view_experiment',
args=[str(experiment.id)]) + "#created")
c['status'] = "Errors exist in form."
c["error"] = 'true'
else:
form = ExperimentForm(extra=1)
c['form'] = form
c['default_institution'] = settings.DEFAULT_INSTITUTION
return HttpResponse(render_response_index(request, template_name, c))
示例13: test_urls_with_some_content
# 需要导入模块: from tardis.tardis_portal.models import ObjectACL [as 别名]
# 或者: from tardis.tardis_portal.models.ObjectACL import save [as 别名]
def test_urls_with_some_content(self):
# Things that might tend to be in a real live system
user = 'testuser'
pwd = User.objects.make_random_password()
user = User.objects.create(username=user,
email='[email protected]',
first_name="Test", last_name="User")
user.set_password(pwd)
user.save()
experiment = Experiment.objects.create(
title="Test Experiment",
created_by=user,
public_access=Experiment.PUBLIC_ACCESS_FULL)
experiment.save()
acl = ObjectACL(pluginId=django_user,
entityId=str(user.id),
content_object=experiment,
canRead=True,
canWrite=True,
canDelete=True,
isOwner=True)
acl.save()
dataset = Dataset(description="test dataset")
dataset.save()
dataset.experiments.add(experiment)
dataset.save()
# Test everything works
c = Client()
c.login(username=user, password=pwd)
urls = ['/about/', '/stats/']
urls += ['/experiment/list/%s' % part
for part in ('mine', 'shared', 'public')]
# urls += ['/experiment/%s/' % part
# for part in ('search',)]
urls += ['/experiment/view/%d/' % experiment.id]
urls += ['/ajax/experiment/%d/%s' % (experiment.id, tabpane)
for tabpane in ('description', 'datasets', 'rights')]
urls += ['/ajax/datafile_list/%d/' % dataset.id]
urls += ['/ajax/dataset_metadata/%d/' % dataset.id]
for u in urls:
response = c.get(u)
ensure(response.status_code, 200,
"%s should have returned 200 but returned %d"
% (u, response.status_code))
redirect_urls = ['/experiment/list', '/experiment/view/']
for u in redirect_urls:
response = c.get(u)
expect(response.status_code).to_equal(302)
示例14: setUp
# 需要导入模块: from tardis.tardis_portal.models import ObjectACL [as 别名]
# 或者: from tardis.tardis_portal.models.ObjectACL import save [as 别名]
def setUp(self):
# Load schemas for test
from django.core.management import call_command
call_command('loaddata', 'as_schemas')
self.client = Client()
self.experiments = []
try:
user = User.objects.get(username='test')
except User.DoesNotExist:
user = User.objects.create_user('test', '', 'test')
user.save()
self.userprofile = user.userprofile
# base_path = path.abspath(path.dirname(__file__))
experiment = Experiment(title='SAXS Test',
created_by=user)
experiment.save()
acl = ObjectACL(pluginId=django_user,
entityId=str(user.id),
content_object=experiment,
canRead=True,
canWrite=True,
canDelete=True,
isOwner=True)
acl.save()
self.experiments += [experiment]
schema = Schema.objects.get(type=Schema.DATAFILE, subtype='saxs')
parameter = ParameterName.objects.get(schema=schema, name='io')
parameter.is_searchable = True
parameter.save()
self.io_param_name = parameter.getUniqueShortName()
schema = Schema.objects.get(type=Schema.DATASET, subtype='saxs')
parameter = ParameterName.objects.get(schema=schema, name='frqimn')
parameter.is_searchable = True
parameter.save()
self.frqimn_param_name = parameter.getUniqueShortName()
new_schema = Schema()
new_schema.namespace = 'testschemawithduplicatename'
new_schema.save()
new_param = ParameterName(
schema=new_schema,
name='title',
full_name='Duplicate title parametername',
is_searchable=True)
new_param.save()
示例15: create_experiment
# 需要导入模块: from tardis.tardis_portal.models import ObjectACL [as 别名]
# 或者: from tardis.tardis_portal.models.ObjectACL import save [as 别名]
def create_experiment(i):
experiment = Experiment(title="Text Experiment #%d" % i, institution_name="Test Uni", created_by=user)
experiment.save()
acl = ObjectACL(
pluginId=django_user,
entityId=str(user.id),
content_object=experiment,
canRead=True,
isOwner=True,
aclOwnershipType=ObjectACL.OWNER_OWNED,
)
acl.save()
return experiment