def to_python(self, value): """ db to code; int to Version """ if isinstance(value, Version): return value if isinstance(value, str): return Version(value) if value is None: return None return Version(Version.int_to_string(value))
def what_QVersionSerializerField_used_to_do(serialized_value): if isinstance(serialized_value, Version): return serialized_value.fully_specified() else: # TODO: JUST DOUBLE-CHECKING THINGS HERE, I'M NOT ENTIRELY CLEAR ON THE ORDER THAT THINGS GET SERIALIZED... # (it seems that it varies based on whether this is a new or existing model) assert isinstance(serialized_value, int) return Version.int_to_string(serialized_value)
def to_internal_value(self, data): # given a serialized representation of a version, return a Pythonic representation # (this should basically do the same thing as "QVersionField.to_python") if isinstance(data, Version): return data if isinstance(data, basestring): return Version(data) if data is None: return None return Version(Version.int_to_string(data))
def get_prep_value(self, value): """ code to db; Version to int """ if isinstance(value, str): return Version.string_to_int(value) if value is None: return None return int(value)
def get_prep_value(self, value): """ code to db; Version to int """ if isinstance(value, basestring): return Version.string_to_int(value) if value is None: return None return int(value)
def to_python(self, value): """ db to code; int to Version """ if isinstance(value, Version): return value if isinstance(value, basestring): return Version(value) if value is None: return None return Version(Version.int_to_string(value))
def get_name_and_version_from_key(key): """ given a string representing some QOntology key, splits it into its constituent parts: a name and a version note that the version in the key can be underspecified (for example, "1.10" should match "1.10.0" :param key: :return: """ match = re.match("^(.*)_(\d+\.\d+\.\d+|\d+\.\d+|\d+)$", key) # not the most elegant regex, but you get the point if not match: msg = "'{0}' is an invalid key; it should be of the format 'name_version'".format( key) raise QError(msg) name, underspecified_version = match.groups() version = Version(underspecified_version).fully_specified() return name, version