當前位置: 首頁>>代碼示例>>Python>>正文


Python ExperimentParameterSet.delete方法代碼示例

本文整理匯總了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
#.........這裏部分代碼省略.........
開發者ID:aaryani,項目名稱:aa-migration-test1,代碼行數:103,代碼來源:embargo.py

示例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()
開發者ID:ANSTO,項目名稱:related_info,代碼行數:5,代碼來源:related_info.py


注:本文中的tardis.tardis_portal.models.ExperimentParameterSet.delete方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。