本文整理汇总了Python中tardis.tardis_portal.models.ExperimentParameterSet.delete方法的典型用法代码示例。如果您正苦于以下问题:Python ExperimentParameterSet.delete方法的具体用法?Python ExperimentParameterSet.delete怎么用?Python ExperimentParameterSet.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tardis.tardis_portal.models.ExperimentParameterSet
的用法示例。
在下文中一共展示了ExperimentParameterSet.delete方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: EmbargoHandler
# 需要导入模块: from tardis.tardis_portal.models import ExperimentParameterSet [as 别名]
# 或者: from tardis.tardis_portal.models.ExperimentParameterSet import delete [as 别名]
class EmbargoHandler(object):
def __init__(self, experiment_id, create=False):
self.experiment = Experiment.objects.get(pk=experiment_id)
parametersets = ExperimentParameterSet.objects.filter(
schema__namespace=NAMESPACE, experiment__id=experiment_id)
self.schema, _ = Schema.objects.get_or_create(namespace=NAMESPACE, name='Embargo Details')
self.expiry_date, _ = ParameterName.objects.get_or_create(schema=self.schema, name=EXPIRY_DATE_KEY, full_name='Expiry', immutable=True, data_type=ParameterName.DATETIME)
self.never_expire, _ = ParameterName.objects.get_or_create(schema=self.schema, name=NEVER_EXPIRE_KEY, full_name='Never Expires', immutable=True, data_type=ParameterName.STRING)
if len(parametersets) == 1:
self.parameterset = parametersets[0]
elif create:
self.parameterset = ExperimentParameterSet(experiment=self.experiment, schema=self.schema)
self.parameterset.save()
else:
self.parameterset = None
def never_expires(self):
never_expire = self._get_or_none(NEVER_EXPIRE_KEY)
if never_expire:
return True
expiry_date = self._get_or_none(EXPIRY_DATE_KEY)
if expiry_date:
return False
else:
return self.experiment.end_time == None
def has_any_expiry(self):
return not self.never_expires()
def can_be_defaulted(self):
expiry_date = self._get_or_none(EXPIRY_DATE_KEY)
never_expires = self._get_or_none(NEVER_EXPIRE_KEY)
return never_expires or expiry_date
def because_no_end_date(self):
if self._get_or_none(NEVER_EXPIRE_KEY):
return False
return self.experiment.end_time == None
def get_expiry_date(self):
''' returns calculated or explicit expiry or None '''
import datetime
if self.never_expires():
return None
explicit_expiry = self._get_or_none(EXPIRY_DATE_KEY)
if explicit_expiry:
return explicit_expiry.datetime_value
else:
return self.experiment.end_time + datetime.timedelta(settings.EMBARGO_DAYS)
def _get_or_none(self, name):
if not self.parameterset:
return None
params = self.parameterset.experimentparameter_set.filter(name__name=name)
if params.count() == 0:
return None
else:
return params[0]
def prevent_expiry(self):
# delete any current expiry dates
# set never_expires = True
logger.fatal('preventing expiry')
if not self.parameterset:
raise Exception('incorrectly initialised, call with create=True')
params = self.parameterset.experimentparameter_set
params.all().delete()
param = ExperimentParameter(name=self.never_expire, string_value='True', parameterset=self.parameterset)
param.save()
self.experiment.public = False
self.experiment.save()
def reset_to_default(self):
import datetime
if self.parameterset:
self.parameterset.delete()
expiry_date = self.get_expiry_date()
if expiry_date and expiry_date.date() < datetime.date.today():
self.experiment.public = True
else:
self.experiment.public = False
self.experiment.save()
else:
logger.warn('tried to delete parameterset that does not exist')
def set_expiry(self, date_string):
if not self.parameterset:
raise Exception('incorrectly initialised, call with create=True')
params = self.parameterset.experimentparameter_set
params.all().delete()
import datetime
#.........这里部分代码省略.........
示例2: delete_info
# 需要导入模块: from tardis.tardis_portal.models import ExperimentParameterSet [as 别名]
# 或者: from tardis.tardis_portal.models.ExperimentParameterSet import delete [as 别名]
def delete_info(self, parameterset_id):
eps = ExperimentParameterSet(experiment_id=self.experiment_id, schema=self.schema, pk=parameterset_id)
eps.delete()