Changeset 1161


Ignore:
Timestamp:
11/29/06 18:08:08 (13 years ago)
Author:
vahur
Message:

getting historical value for one field only.
avoids RuntimeError?: maximum recursion depth exceeded in same rare cases

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/FieldsWidgets.py

    r1131 r1161  
    704704            return ObjectField.get(self,instance,**kwargs) 
    705705        # Get old data from history 
    706         fields = instance.getHistoricalFields(version) 
    707         value = fields[self.getName()] 
     706        #fields = instance.getHistoricalFields(version) 
     707        value = instance.getFieldHistory(self.getName(), version) 
     708        #value = fields[self.getName()] 
    708709        if type(value) != type([]): 
    709710            return [value,] 
  • trunk/Resources.py

    r1150 r1161  
    541541            entry[fieldname] = f.getRaw(self) 
    542542        return entry 
     543 
     544    def getFieldHistory(self, field, timestamp): 
     545        """ get ... """ 
     546        history = self.getHistory() 
     547        for x in history: 
     548            print "comparing..", float(x['_timestamp']), float(timestamp), float(x['_timestamp']) == float(timestamp) 
     549            timestamp = float(timestamp) 
     550            if round(x['_timestamp']) == round(timestamp): 
     551                try: 
     552                    return x[field] 
     553                except AttributeError: 
     554                    break 
     555        # there's nothing, scroll back in time 
     556        for x in history: 
     557            if float(timestamp) >= float(x['_timestamp']):  # scroll back in time 
     558                rec = 1 
     559            if not rec: continue 
     560            if x.has_key(field): return x[field] 
     561        return "get error, no history?" 
    543562 
    544563    def getDiffFields(self, old_version): 
Note: See TracChangeset for help on using the changeset viewer.