示例#1
0
    def __init__(self,
                 creationMagic=False,
                 updateMagic=False,
                 date=True,
                 time=True,
                 localize=False,
                 *args,
                 **kwargs):
        """
			Initializes a new dateBone.

			:param creationMagic: Use the current time as value when creating an entity; ignoring this bone if the
				entity gets updated.
			:type creationMagic: bool
			:param updateMagic: Use the current time whenever this entity is saved.
			:type updateMagic: bool
			:param date: Should this bone contain a date-information?
			:type date: bool
			:param time: Should this bone contain time information?
			:type time: bool
			:param localize: Automatically convert this time into the users timezone? Only valid if this bone
                                contains date and time-information!
			:type localize: bool
		"""
        baseBone.__init__(self, *args, **kwargs)
        if creationMagic or updateMagic:
            self.readonly = True
        self.creationMagic = creationMagic
        self.updateMagic = updateMagic
        if not (date or time):
            raise ValueError(
                "Attempt to create an empty datebone! Set date or time to True!"
            )
        if localize and not (date and time):
            raise ValueError(
                "Localization is only possible with date and time!")
        if self.multiple and (creationMagic or updateMagic):
            raise ValueError(
                "Cannot be multiple and have a creation/update-magic set!")
        self.date = date
        self.time = time
        self.localize = localize
示例#2
0
    def __init__(self,
                 visible=False,
                 readOnly=True,
                 slices=2,
                 sliceSize=0.5,
                 *args,
                 **kwargs):
        """
			Initializes a new randomSliceBone.


		"""
        if visible or not readOnly:
            raise NotImplemented(
                "A RandomSliceBone must not visible and readonly!")
        baseBone.__init__(self,
                          indexed=True,
                          visible=False,
                          readOnly=True,
                          *args,
                          **kwargs)
        self.slices = slices
        self.sliceSize = sliceSize
示例#3
0
 def __init__(self, mode="rgb", *args, **kwargs):  # mode rgb/rgba
     baseBone.__init__(self, *args, **kwargs)
     assert mode in {"rgb", "rgba"}
     self.mode = mode
	def __init__(self, kind=None, module=None, refKeys=None, parentKeys=None, multiple=False, format="$(dest.name)",
				 using=None, updateLevel=0, consistency=RelationalConsistency.Ignore, *args, **kwargs):
		"""
			Initialize a new relationalBone.

			:param kind: KindName of the referenced property.
			:type kind: str
			:param module: Name of the module which should be used to select entities of kind "type". If not set,
				the value of "type" will be used (the kindName must match the moduleName)
			:type type: str
			:param refKeys: A list of properties to include from the referenced property. These properties will be
				available in the template without having to fetch the referenced property. Filtering is also only possible
				by properties named here!
			:type refKeys: list of str
			:param parentKeys: A list of properties from the current skeleton to include. If mixing filtering by
				relational properties and properties of the class itself, these must be named here.
			:type parentKeys: list of str
			:param multiple: If True, allow referencing multiple Elements of the given class. (Eg. n:n-relation.
				otherwise its n:1 )
			:type multiple: False
			:param format: Hint for the admin how to display such an relation. See admin/utils.py:formatString for
				more information
			:type format: str
			:type format: String
			:param updateLevel: level 0==always update refkeys (old behavior), 1==update refKeys only on
				rebuildSearchIndex, 2==update only if explicitly set
			:type updateLevel: int
		"""
		baseBone.__init__(self, *args, **kwargs)
		self.multiple = multiple
		self.format = format
		# self._dbValue = None #Store the original result fetched from the db here so we have that information in case a referenced entity has been deleted

		if kind:
			self.kind = kind

		if module:
			self.module = module
		elif self.kind:
			self.module = self.kind

		if self.kind is None or self.module is None:
			raise NotImplementedError("Type and Module of relationalbone's must not be None")

		if refKeys:
			if not "key" in refKeys:
				refKeys.append("key")
			self.refKeys = refKeys

		if parentKeys:
			if not "key" in parentKeys:
				parentKeys.append("key")
			self.parentKeys = parentKeys

		self.using = using
		self.updateLevel = updateLevel
		self.consistency = consistency

		if getSystemInitialized():
			from viur.core.skeleton import RefSkel, SkeletonInstance
			self._refSkelCache = RefSkel.fromSkel(self.kind, *self.refKeys)
			self._skeletonInstanceClassRef = SkeletonInstance