track changes also for users without Person objects; track creation of objects
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@2940 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
		
							parent
							
								
									d1dbe47d57
								
							
						
					
					
						commit
						31c4eae66f
					
				
					 2 changed files with 21 additions and 9 deletions
				
			
		| 
						 | 
				
			
			@ -50,14 +50,20 @@ class ChangeView(TrackView):
 | 
			
		|||
    @Lazy
 | 
			
		||||
    def user(self):
 | 
			
		||||
        uid = self.metadata['userName']
 | 
			
		||||
        return util.getObjectForUid(uid)
 | 
			
		||||
        if uid.isdigit():
 | 
			
		||||
            obj = util.getObjectForUid(uid)
 | 
			
		||||
            if obj is not None:
 | 
			
		||||
                return obj
 | 
			
		||||
        return uid
 | 
			
		||||
 | 
			
		||||
    @Lazy
 | 
			
		||||
    def userTitle(self):
 | 
			
		||||
        if isinstance(self.user, basestring):
 | 
			
		||||
            return self.user
 | 
			
		||||
        return getattr(self.user, 'title', getName(self.user))
 | 
			
		||||
 | 
			
		||||
    @Lazy
 | 
			
		||||
    def userUrl(self):
 | 
			
		||||
        user = self.user
 | 
			
		||||
        if user is not None:
 | 
			
		||||
            return '%s/@@SelectedManagementView.html' % absoluteURL(user, self.request)
 | 
			
		||||
        if user is not None and not isinstance(user, basestring):
 | 
			
		||||
            return '%s/@@introspector.html' % absoluteURL(user, self.request)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -59,7 +59,7 @@ class ChangeManager(object):
 | 
			
		|||
    def valid(self):
 | 
			
		||||
        return (not (self.context is None or
 | 
			
		||||
                    self.storage is None or
 | 
			
		||||
                    self.person is None)
 | 
			
		||||
                    self.personId is None)
 | 
			
		||||
                and 'changes' in self.options('organize.tracking', ()))
 | 
			
		||||
 | 
			
		||||
    @Lazy
 | 
			
		||||
| 
						 | 
				
			
			@ -74,18 +74,20 @@ class ChangeManager(object):
 | 
			
		|||
        return None
 | 
			
		||||
 | 
			
		||||
    @Lazy
 | 
			
		||||
    def person(self):
 | 
			
		||||
    def personId(self):
 | 
			
		||||
        principal = getCurrentPrincipal()
 | 
			
		||||
        if principal is not None:
 | 
			
		||||
            return getPersonForUser(self.context, principal=principal)
 | 
			
		||||
            person = getPersonForUser(self.context, principal=principal)
 | 
			
		||||
            if person is None:
 | 
			
		||||
                return principal.id
 | 
			
		||||
            return util.getUidForObject(person)
 | 
			
		||||
        return None
 | 
			
		||||
 | 
			
		||||
    def recordModification(self, action='modify', **kw):
 | 
			
		||||
        if not self.valid:
 | 
			
		||||
            return
 | 
			
		||||
        uid = util.getUidForObject(self.context)
 | 
			
		||||
        personUid = util.getUidForObject(self.person)
 | 
			
		||||
        last = self.storage.getLastUserTrack(uid, 0, personUid)
 | 
			
		||||
        last = self.storage.getLastUserTrack(uid, 0, self.personId)
 | 
			
		||||
        update = (last is not None and last.data.get('action') == action and
 | 
			
		||||
                  last.metadata['timeStamp'] >= getTimeStamp() - 5)
 | 
			
		||||
        data = dict(action=action)
 | 
			
		||||
| 
						 | 
				
			
			@ -96,7 +98,7 @@ class ChangeManager(object):
 | 
			
		|||
        if update:
 | 
			
		||||
            self.storage.updateTrack(last, data)
 | 
			
		||||
        else:
 | 
			
		||||
            self.storage.saveUserTrack(uid, 0, personUid, data, update)
 | 
			
		||||
            self.storage.saveUserTrack(uid, 0, self.personId, data, update)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class IChangeRecord(ITrack):
 | 
			
		||||
| 
						 | 
				
			
			@ -115,6 +117,10 @@ class ChangeRecord(Track):
 | 
			
		|||
def recordModification(obj, event):
 | 
			
		||||
    ChangeManager(obj).recordModification()
 | 
			
		||||
 | 
			
		||||
@adapter(ILoopsObject, IObjectCreatedEvent)
 | 
			
		||||
def recordModification(obj, event):
 | 
			
		||||
    ChangeManager(obj).recordModification('create')
 | 
			
		||||
 | 
			
		||||
@adapter(ILoopsObject, IAssignmentEvent)
 | 
			
		||||
def recordAssignment(obj, event):
 | 
			
		||||
    ChangeManager(obj).recordModification('assign', relation=event.relation)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue