本文整理汇总了Python中tardis.tardis_portal.models.Schema类的典型用法代码示例。如果您正苦于以下问题:Python Schema类的具体用法?Python Schema怎么用?Python Schema使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Schema类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: save_rif_cs_profile
def save_rif_cs_profile(self, experiment, profile):
"""
Save selected profile choice as experiment parameter
"""
namespace = "http://monash.edu.au/rif-cs/profile/"
schema = None
try:
schema = Schema.objects.get(
namespace__exact=namespace)
except Schema.DoesNotExist:
logger.debug('Schema ' + namespace +
' does not exist. Creating.')
schema = Schema(namespace=namespace)
schema.save()
parametername = ParameterName.objects.get(
schema__namespace__exact=schema.namespace,
name="profile")
parameterset = None
try:
parameterset = \
ExperimentParameterSet.objects.get(\
schema=schema,
experiment=experiment)
except ExperimentParameterSet.DoesNotExist, e:
parameterset = ExperimentParameterSet(\
schema=schema,
experiment=experiment)
parameterset.save()
开发者ID:aaryani,项目名称:CoreTardis,代码行数:32,代码来源:__init__.py
示例2: get_schema
def get_schema(schema, name):
"""Return the schema object that the paramaterset will use.
"""
try:
return Schema.objects.get(namespace__exact=schema)
except Schema.DoesNotExist:
schema = Schema(namespace=schema, name=name, type=Schema.DATASET)
schema.save()
return schema
开发者ID:mytardis,项目名称:hpctardis,代码行数:9,代码来源:metadata.py
示例3: getSchema
def getSchema(self):
"""Returns the schema object that the parameter set will use.
"""
try:
return Schema.objects.get(namespace__exact=self.schema)
except Schema.DoesNotExist:
schema = Schema(namespace=self.schema, name=self.name, type=Schema.DATAFILE)
schema.save()
return schema
开发者ID:guillaumeprevost,项目名称:hiri-tardis-filter,代码行数:9,代码来源:flexstation.py
示例4: get_schema
def get_schema(self):
try:
schema = Schema.objects.get(
namespace=self.namespace)
except ObjectDoesNotExist:
schema = Schema()
schema.namespace = self.namespace
schema.save()
self.schema = schema
return schema
开发者ID:ANSTO,项目名称:mytardis,代码行数:10,代码来源:ParameterSetManager.py
示例5: get_schema
def get_schema(self):
from tardis.tardis_portal.models import Schema
try:
schema = Schema.objects.get(
namespace=self.namespace)
except ObjectDoesNotExist:
schema = Schema()
schema.namespace = self.namespace
schema.save()
self.schema = schema
return schema
开发者ID:keithschulze,项目名称:mytardis,代码行数:11,代码来源:ParameterSetManager.py
示例6: getSchema
def getSchema(self):
"""Return the schema object that the paramaterset will use.
"""
logger.error('Olympus-getSchema()')
try:
return Schema.objects.get(namespace__exact=self.schema)
except Schema.DoesNotExist:
schema = Schema(namespace=self.schema, name=self.name,
type=Schema.DATAFILE)
schema.save()
return schema
开发者ID:cyruskeong,项目名称:mytardis-olympus-oib-filter,代码行数:11,代码来源:olympusoibimage.py
示例7: setUp
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()
开发者ID:IntersectAustralia,项目名称:mytardis,代码行数:52,代码来源:tests.py
示例8: _get_schema
def _get_schema(schema,name):
"""Return the schema object that the paramaterset will use.
"""
try:
sch = Schema.objects.get(namespace__exact=schema)
logger.debug("found %s %s" % (sch.namespace, sch.name))
return sch
except Schema.DoesNotExist:
schema = Schema(namespace=schema, name=name,
type=Schema.DATASET)
schema.save()
logger.debug("creating %s %s " % (schema,name))
return schema
开发者ID:aaryani,项目名称:hpctardis,代码行数:13,代码来源:metadata.py
示例9: getSchema
def getSchema(self):
return Schema.objects.get(namespace='http://cai.uq.edu.au/schema/metadata/1')
# FIXME Ignoring this stuff... why would we dynamically create a Schema here?
"""Return the schema object that the paramaterset will use.
"""
try:
return Schema.objects.get(namespace__exact=self.schema)
except Schema.DoesNotExist:
schema = Schema(namespace=self.schema, name=self.name,
type=Schema.DATAFILE)
schema.save()
return schema
开发者ID:carlohamalainen,项目名称:cai-tmp,代码行数:13,代码来源:dicompng.py
示例10: setUp
def setUp(self):
"""
setting up essential objects, copied from tests above
"""
user = "tardis_user1"
pwd = "secret"
email = ""
self.user = User.objects.create_user(user, email, pwd)
self.userProfile = self.user.userprofile
self.exp = Experiment(title="test exp1", institution_name="monash", created_by=self.user)
self.exp.save()
self.acl = ObjectACL(
pluginId=django_user,
entityId=str(self.user.id),
content_object=self.exp,
canRead=True,
isOwner=True,
aclOwnershipType=ObjectACL.OWNER_OWNED,
)
self.acl.save()
self.dataset = Dataset(description="dataset description...")
self.dataset.save()
self.dataset.experiments.add(self.exp)
self.dataset.save()
self.datafile = DataFile(dataset=self.dataset, size=42, filename="foo", md5sum="junk")
self.datafile.save()
self.testschema = Schema(
namespace="http://test.com/test/schema", name="Test View", type=Schema.DATAFILE, hidden=True
)
self.testschema.save()
self.dfps = DatafileParameterSet(datafile=self.datafile, schema=self.testschema)
self.dfps.save()
开发者ID:grischa,项目名称:mytardis,代码行数:34,代码来源:test_views.py
示例11: _save_party_refs
def _save_party_refs(self, party, party_relation):
""" Save party and party relation information as parameters on the
experiment
"""
namespace = "http://rmit.edu.au/rif-cs/party/1.0/"
logger.debug("saving party")
schema = None
try:
schema = Schema.objects.get(
namespace__exact=namespace)
except Schema.DoesNotExist:
logger.debug('Schema ' + namespace +
' does not exist. Creating.')
schema = Schema(namespace=namespace)
schema.save()
exp = Experiment.objects.get(pk=self.experiment_id)
party_id_param = self._make_param(schema=schema,
name="party_id",
paramtype=ParameterName.NUMERIC)
relation_param = self._make_param(schema=schema,
name="relationtocollection_id",
paramtype=ParameterName.STRING)
parameterset = ExperimentParameterSet(schema=schema, experiment=exp)
parameterset.save()
ep = ExperimentParameter.objects.filter(name=party_id_param,
parameterset=parameterset,
parameterset__experiment=exp)
for p in ep:
p.delete()
ep = ExperimentParameter(
parameterset=parameterset,
name=party_id_param,
numerical_value=party.pk)
ep.save()
ep = ExperimentParameter.objects.filter(name=relation_param,
parameterset=parameterset,
parameterset__experiment=exp)
for p in ep:
p.delete()
ep = ExperimentParameter(
parameterset=parameterset,
name=relation_param,
string_value=party_relation)
ep.save()
开发者ID:aaryani,项目名称:hpctardis,代码行数:44,代码来源:rif_cs_PublishProvider.py
示例12: test_contextual_view
def test_contextual_view(self):
"""
Given schema on dataset, check that image file created
"""
user = _create_test_user()
license = _create_license()
exp = _create_test_experiment(user, license)
ds = Dataset(description='happy snaps of plumage')
ds.save()
ds = _create_test_dataset(ds, exp.id, {
"output.dat": 'test data\n',
"grexp.dat": '1 2\n2 3\n3 7\n',
"grfinal21.dat": '1 2\n 2 4\n4 9\n'})
sch = Schema(namespace=self.HRMCSCHEMA,
name="hrmc_views", type=Schema.DATASET)
sch.save()
param = ParameterName(schema=sch, name="plot",
full_name="scatterplot", units="image",
data_type=ParameterName.FILENAME
)
param.save()
dps = DatasetParameterSet(schema=sch, dataset=ds)
dps.save()
ds.experiments.add(exp)
ds.save()
client = Client()
response = client.get('/dataset/%s' % ds.id)
self.assertEqual(response.status_code, 200)
param_sets = get_param_sets(ds)
self.assertTrue(param_sets)
dp = DatasetParameter.objects.get(parameterset=param_sets[0],
name=param)
self.assertTrue(dp)
self.assertNotEquals(dp.string_value, "") # ie, it has a filename
开发者ID:bioscience-data-platform,项目名称:mytardis-app-hrmcoutput,代码行数:42,代码来源:test_view.py
示例13: __getFilteredExperiments
def __getFilteredExperiments(request, searchFilterData):
"""Filter the list of experiments using the cleaned up searchFilterData.
Arguments:
request -- the HTTP request
searchFilterData -- the cleaned up search experiment form data
Returns:
A list of experiments as a result of the query or None if the provided
search request is invalid
"""
experiments = authz.get_accessible_experiments(request)
if experiments is None:
return []
# search for the default experiment fields
if searchFilterData['title'] != '':
experiments = \
experiments.filter(title__icontains=searchFilterData['title'])
if searchFilterData['description'] != '':
experiments = \
experiments.filter(
description__icontains=searchFilterData['description'])
if searchFilterData['institutionName'] != '':
experiments = experiments.filter(
institution_name__icontains=searchFilterData['institutionName'])
if searchFilterData['creator'] != '':
experiments = experiments.filter(
experimentauthor__author__icontains=searchFilterData['creator'])
date = searchFilterData['date']
if date is not None:
experiments = \
experiments.filter(start_time__lt=date, end_time__gt=date)
# get all the experiment parameters
exp_schema_namespaces = Schema.getNamespaces(Schema.EXPERIMENT)
parameters = ParameterName.objects.filter(
schema__namespace__in=exp_schema_namespaces, is_searchable=True)
experiments = __filterParameters(
parameters, experiments,
searchFilterData, 'experimentparameterset__experimentparameter')
# let's sort it in the end
experiments = experiments.order_by('title')
return experiments
开发者ID:IntersectAustralia,项目名称:mytardis,代码行数:54,代码来源:utils.py
示例14: test_hrmc_filter
def test_hrmc_filter(self):
"""
Make an experiment, lood up grexp file and check
dataset schema missing, then loadup grfinal and check dataset schema
created
"""
user = _create_test_user()
license = _create_license()
exp = _create_test_experiment(user, license)
ds = Dataset(description='happy snaps of plumage')
ds.save()
_create_test_dataset(ds, exp.id,
{"output.dat": 'hello', "grexp.dat": '2 5\n6 15\n'})
ds.experiments.add(exp)
ds.save()
sch = Schema(namespace=self.HRMCSCHEMA,
name="hrmc_views", type=Schema.DATASET)
sch.save()
param = ParameterName(schema=sch, name="plot",
full_name="scatterplot", units="image",
data_type=ParameterName.FILENAME
)
param.save()
param_sets = get_param_sets(ds)
self.assertEquals(list(param_sets), [])
_create_test_dataset(ds, exp.id, {'grfinal21.dat': "1 3\n5 14\n"})
df2 = Dataset_File(dataset=ds, url='path/grfinal21.dat')
df2.save()
h = hrmc.HRMCOutput('HRMC', self.HRMCSCHEMA)
h(sender=Dataset_File, instance=df2)
param_sets = get_param_sets(ds)
self.assertEquals([x.schema.namespace for x in param_sets],
[self.HRMCSCHEMA])
开发者ID:bioscience-data-platform,项目名称:mytardis-app-hrmcoutput,代码行数:40,代码来源:test_view.py
示例15: ParameterSetManagerTestCase
class ParameterSetManagerTestCase(TestCase):
def setUp(self):
from django.contrib.auth.models import User
from tempfile import mkdtemp
user = 'tardis_user1'
pwd = 'secret'
email = ''
self.user = User.objects.create_user(user, email, pwd)
self.test_dir = mkdtemp()
self.exp = Experiment(title='test exp1',
institution_name='monash',
created_by=self.user)
self.exp.save()
self.dataset = Dataset(description="dataset description...")
self.dataset.save()
self.dataset.experiments.add(self.exp)
self.dataset.save()
self.datafile = DataFile(dataset=self.dataset,
filename="testfile.txt",
size="42", md5sum='bogus')
self.datafile.save()
self.dfo = DataFileObject(
datafile=self.datafile,
storage_box=self.datafile.get_default_storage_box(),
uri="1/testfile.txt")
self.dfo.save()
self.schema = Schema(
namespace="http://localhost/psmtest/df/",
name="Parameter Set Manager", type=3)
self.schema.save()
self.parametername1 = ParameterName(
schema=self.schema, name="parameter1",
full_name="Parameter 1")
self.parametername1.save()
self.parametername2 = ParameterName(
schema=self.schema, name="parameter2",
full_name="Parameter 2",
data_type=ParameterName.NUMERIC)
self.parametername2.save()
self.parametername3 = ParameterName(
schema=self.schema, name="parameter3",
full_name="Parameter 3",
data_type=ParameterName.DATETIME)
self.parametername3.save()
self.datafileparameterset = DatafileParameterSet(
schema=self.schema, datafile=self.datafile)
self.datafileparameterset.save()
self.datafileparameter1 = DatafileParameter(
parameterset=self.datafileparameterset,
name=self.parametername1, string_value="test1")
self.datafileparameter1.save()
self.datafileparameter2 = DatafileParameter(
parameterset=self.datafileparameterset,
name=self.parametername2, numerical_value=2)
self.datafileparameter2.save()
# Create a ParameterName and Parameter of type LINK to an experiment
self.parametername_exp_link = ParameterName(
schema=self.schema, name="exp_link",
full_name="This parameter is a experiment LINK",
data_type=ParameterName.LINK)
self.parametername_exp_link.save()
self.exp_link_param = DatafileParameter(
parameterset=self.datafileparameterset,
name=self.parametername_exp_link)
exp_url = self.exp.get_absolute_url() # /experiment/view/1/
self.exp_link_param.set_value(exp_url)
self.exp_link_param.save()
# Create a ParameterName and Parameter of type LINK to a dataset
self.parametername_dataset_link = ParameterName(
schema=self.schema, name="dataset_link",
full_name="This parameter is a dataset LINK",
data_type=ParameterName.LINK)
self.parametername_dataset_link.save()
self.dataset_link_param = DatafileParameter(
parameterset=self.datafileparameterset,
name=self.parametername_dataset_link)
dataset_url = self.dataset.get_absolute_url() # /dataset/1/
self.dataset_link_param.set_value(dataset_url)
self.dataset_link_param.save()
# Create a ParameterName type LINK to an unresolvable (non-URL)
# free-text value
#.........这里部分代码省略.........
开发者ID:IntersectAustralia,项目名称:mytardis,代码行数:101,代码来源:test_parametersetmanager.py
示例16: __call__
def __call__(self, sender, **kwargs):
"""post save callback entry point.
:param sender: The model class.
:param instance: The actual instance being saved.
:param created: A boolean; True if a new record was created.
:type created: bool
"""
instance = kwargs.get('instance')
created = kwargs.get('created')
if not created:
# Don't extract on edit
return
# schema = self.getSchema()
filepath = instance.get_absolute_filepath()
if not filepath:
# TODO log that exited early
return
# generate thumbnails for image file
try:
img = Image.open(filepath)
write_thumbnails(instance, img)
except IOError:
# file not an image file
pass
# ignore non-image file
if filepath[-4:].lower() != ".tif":
return
# Find instrument name in filepath
instr_name = None
import re
pathSep = re.compile(r'\\|\/')
for part in pathSep.split(filepath):
if part in self.instruments.keys():
instr_name = part
logger.debug("filepath=%s" % filepath)
logger.debug("instr_name=%s" % instr_name)
if (instr_name != None and len(instr_name) > 1):
logger.debug("instr_name %s" % instr_name)
exifs = self.getExif(filepath)
for exifTag in exifs:
logger.debug("exifTag=%s" % exifTag)
if exifTag == 'Image Tag 0x877A' or exifTag == 'Image Tag 0x8778':
tmpfile = "/tmp/workfile_%s" % random.randint(1, 9999)
f = open(tmpfile, 'w')
f.write(exifs[exifTag])
f.close()
x877a_tags = ConfigParser.RawConfigParser()
x877a_tags.read(tmpfile)
instrSchemas = self.instruments[instr_name]
# for each schema for this instrument
for sch in instrSchemas:
(schemaName,schemaSuffix,tagsToFind) = sch
logger.debug("schemaTuple %s = %s %s %s" %(sch,schemaName,schemaSuffix,tagsToFind))
# find values in tags
metadata = {}
detector_name = ""
pixel_width = 0
for tag in tagsToFind:
(section, option, fieldname, unit, multiplier) = tag
try:
# get values in detector section
if section == "Detector_Name" and detector_name != "":
section = detector_name
value = x877a_tags.get(section, option)
# convert value with specified multiplier
if multiplier:
value = float(value) * multiplier
# round values
if option in ["WorkingDistance", "Contrast", "Brightness"]:
value = round(float(value), 1)
if option in ["Magnification"]:
value = int(round(float(value)))
# get Chamber Pressure
if section == "Vacuum" and option.lower() == "chpressure":
value_in_torr = float(value) / 133.322368
value_in_mbar = float(value) / 100
value = "%.4G Torr (%.4G mbar)" % (value_in_torr, value_in_mbar)
# get metadata
metadata["[%s] %s" % (section, fieldname)] = [value, unit]
# get Detector Name
if section == "Detectors" and option == "Name":
detector_name = value
# get Pixel Width for calculating magnification
if section == "Scan" and option == "PixelWidth":
pixel_width = float(value)
except ConfigParser.NoSectionError:
pass
#.........这里部分代码省略.........
开发者ID:aaryani,项目名称:CoreTardis,代码行数:101,代码来源:exiftags.py
示例17: ContextualViewTest
class ContextualViewTest(TestCase):
def setUp(self):
"""
setting up essential objects, copied from tests above
"""
user = 'tardis_user1'
pwd = 'secret'
email = ''
self.user = User.objects.create_user(user, email, pwd)
self.userProfile = UserProfile(user=self.user).save()
self.exp = Experiment(title='test exp1',
institution_name='monash', created_by=self.user)
self.exp.save()
self.acl = ObjectACL(
pluginId=django_user,
entityId=str(self.user.id),
content_object=self.exp,
canRead=True,
isOwner=True,
aclOwnershipType=ObjectACL.OWNER_OWNED,
)
self.acl.save()
self.dataset = Dataset(description='dataset description...')
self.dataset.save()
self.dataset.experiments.add(self.exp)
self.dataset.save()
self.dataset_file = Dataset_File(dataset=self.dataset,
size=42, filename="foo",
md5sum="junk")
self.dataset_file.save()
self.testschema = Schema(namespace="http://test.com/test/schema",
name="Test View",
type=Schema.DATAFILE,
hidden=True)
self.testschema.save()
self.dfps = DatafileParameterSet(dataset_file=self.dataset_file,
schema=self.testschema)
self.dfps.save()
def tearDown(self):
self.user.delete()
self.exp.delete()
self.dataset.delete()
self.dataset_file.delete()
self.testschema.delete()
self.dfps.delete()
self.acl.delete()
def testDetailsDisplay(self):
"""
test display of view for an existing schema and no display for an undefined one.
"""
from tardis.tardis_portal.views import display_datafile_details
request = flexmock(user=self.user, groups=[("testgroup",flexmock())])
with self.settings(DATAFILE_VIEWS=[("http://test.com/test/schema", "/test/url"),
("http://does.not.exist", "/false/url")]):
response = display_datafile_details(request, dataset_file_id=self.dataset_file.id)
self.assertEqual(response.status_code, 200)
self.assertTrue("/ajax/parameters/" in response.content)
self.assertTrue("/test/url" in response.content)
self.assertFalse("/false/url" in response.content)
开发者ID:crawley,项目名称:mytardis,代码行数:64,代码来源:test_views.py
示例18: setUp
def setUp(self):
from django.contrib.auth.models import User
from tempfile import mkdtemp
user = 'tardis_user1'
pwd = 'secret'
email = ''
self.user = User.objects.create_user(user, email, pwd)
self.test_dir = mkdtemp()
self.exp = Experiment(title='test exp1',
institution_name='monash',
created_by=self.user)
self.exp.save()
self.dataset = Dataset(description="dataset description...")
self.dataset.save()
self.dataset.experiments.add(self.exp)
self.dataset.save()
self.datafile = DataFile(dataset=self.dataset,
filename="testfile.txt",
size="42", md5sum='bogus')
self.datafile.save()
self.dfo = DataFileObject(
datafile=self.datafile,
storage_box=self.datafile.get_default_storage_box(),
uri="1/testfile.txt")
self.dfo.save()
self.schema = Schema(
namespace="http://localhost/psmtest/df/",
name="Parameter Set Manager", type=3)
self.schema.save()
self.parametername1 = ParameterName(
schema=self.schema, name="parameter1",
full_name="Parameter 1")
self.parametername1.save()
self.parametername2 = ParameterName(
schema=self.schema, name="parameter2",
full_name="Parameter 2",
data_type=ParameterName.NUMERIC)
self.parametername2.save()
self.parametername3 = ParameterName(
schema=self.schema, name="parameter3",
full_name="Parameter 3",
data_type=ParameterName.DATETIME)
self.parametername3.save()
self.datafileparameterset = DatafileParameterSet(
schema=self.schema, datafile=self.datafile)
self.datafileparameterset.save()
self.datafileparameter1 = DatafileParameter(
parameterset=self.datafileparameterset,
name=self.parametername1, string_value="test1")
self.datafileparameter1.save()
self.datafileparameter2 = DatafileParameter(
parameterset=self.datafileparameterset,
name=self.parametername2, numerical_value=2)
self.datafileparameter2.save()
# Create a ParameterName and Parameter of type LINK to an experiment
self.parametername_exp_link = ParameterName(
schema=self.schema, name="exp_link",
full_name="This parameter is a experiment LINK",
data_type=ParameterName.LINK)
self.parametername_exp_link.save()
self.exp_link_param = DatafileParameter(
parameterset=self.datafileparameterset,
name=self.parametername_exp_link)
exp_url = self.exp.get_absolute_url() # /experiment/view/1/
self.exp_link_param.set_value(exp_url)
self.exp_link_param.save()
# Create a ParameterName and Parameter of type LINK to a dataset
self.parametername_dataset_link = ParameterName(
schema=self.schema, name="dataset_link",
full_name="This parameter is a dataset LINK",
data_type=ParameterName.LINK)
self.parametername_dataset_link.save()
self.dataset_link_param = DatafileParameter(
parameterset=self.datafileparameterset,
name=self.parametername_dataset_link)
dataset_url = self.dataset.get_absolute_url() # /dataset/1/
self.dataset_link_param.set_value(dataset_url)
self.dataset_link_param.save()
# Create a ParameterName type LINK to an unresolvable (non-URL)
# free-text value
self.parametername_unresolvable_link = ParameterName(
schema=self.schema, name="freetext_link",
#.........这里部分代码省略.........
开发者ID:IntersectAustralia,项目名称:mytardis,代码行数:101,代码来源:test_parametersetmanager.py
示例19: __getFilteredDatafiles
def __getFilteredDatafiles(request, searchQueryType, searchFilterData):
"""Filter the list of datafiles for the provided searchQueryType using the
cleaned up searchFilterData.
Arguments:
request -- the HTTP request
searchQueryType -- the type of query, 'mx' or 'saxs'
searchFilterData -- the cleaned up search form data
Returns:
A list of datafiles as a result of the query or None if the provided search
request is invalid
"""
datafile_results = authz.get_accessible_datafiles_for_user(request)
logger.info('__getFilteredDatafiles: searchFilterData {0}'.
format(searchFilterData))
# there's no need to do any filtering if we didn't find any
# datafiles that the user has access to
if not datafile_results:
logger.info("""__getFilteredDatafiles: user {0} doesn\'t have
access to any experiments""".format(request.user))
return datafile_results
q = {
'datafileparameterset__datafileparameter__name__schema__namespace__in':
Schema.getNamespaces(Schema.DATAFILE, searchQueryType)
}
datafile_results = datafile_results.filter(**q).distinct()
# if filename is searchable which i think will always be the case...
if searchFilterData['filename'] != '':
datafile_results = \
datafile_results.filter(
filename__icontains=searchFilterData['filename'])
# TODO: might need to cache the result of this later on
# get all the datafile parameters for the given schema
parameters = [p for p in
ParameterName.objects.filter(
schema__namespace__in=Schema.getNamespaces(
Schema.DATAFILE, searchQueryType))]
datafile_results = __filterParameters(
parameters, datafile_results,
searchFilterData, 'datafileparameterset__datafileparameter')
# get all the dataset parameters for given schema
parameters = [p for p in
ParameterName.objects.filter(
schema__namespace__in=Schema.getNamespaces(
Schema.DATASET, searchQueryType))]
datafile_results = __filterParameters(
parameters, datafile_results,
searchFilterData, 'dataset__datasetparameterset__datasetparameter')
# let's sort it in the end
if datafile_results:
datafile_results = datafile_results.order_by('filename')
logger.debug("results: {0}".format(datafile_results))
return datafile_results
开发者ID:IntersectAustralia,项目名称:mytardis,代码行数:65,代码来源:utils.py
注:本文中的tardis.tardis_portal.models.Schema类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论