Exemplo n.º 1
0
	def update(self, user, data, parent, comment = None):
		"""parent is a action that will be updated"""
		assert isinstance(user, User)
		assert isinstance(data, int) or isinstance(data, float) or isinstance(data, str) or isinstance(data, tuple) or isinstance(data, list) or isinstance(data, dict) or isinstance(data, set)
		assert isinstance(parent, tuple) or isinstance(parent, Action)
		assert comment is None or isinstance(comment, str) 

		if not self.isMember(user):
			raise NonMember()
		if isinstance(parent, tuple):
			parent = self.get(parent)
		self.versions[user.ID()] += 1
		no = self.versions[user.ID()]
		sign = user.encrypt(str(data))
		action = Action.new(self.getID(), user, no, Action.Update, data, comment, parent) 
		self.actions[action.ID()] = action
		latests = self.latests[action.root]
		for i in range(len(latests)):
			if latests[i] == parent:
				latests.pop(i)
		latests.insert(0, action)
		latests.sort(key=lambda x: x.time, reverse=True)

		self._save()

		return action.ID()
Exemplo n.º 2
0
	def put(self, user, data, comment = None):
		if not self.isMember(user):
			raise NonMember()
		self.versions[user.ID()] += 1
		no = self.versions[user.ID()]
		sign = user.encrypt(str(data))
		action = Action.new(self.getID(), user, no, Action.Insert, data, comment) 
		self.actions[action.ID()] = action
		self.latests[action.ID()] = [action]

		self._save()

		return action.ID()