round position to three digits before saving in database

This commit is contained in:
j 2012-06-16 11:00:45 +02:00
parent be6abcc4b7
commit a66ee51280
3 changed files with 8 additions and 7 deletions

View file

@ -34,7 +34,7 @@ class Sequence(models.Model):
objects = managers.SequenceManager() objects = managers.SequenceManager()
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
self.public_id = u"%s/%s-%s" % ( self.public_id = u"%s/%0.03f-%0.03f" % (
self.item.itemId, float(self.start), float(self.end) self.item.itemId, float(self.start), float(self.end)
) )
if self.item: if self.item:
@ -49,8 +49,8 @@ class Sequence(models.Model):
j = { j = {
'id': self.public_id, 'id': self.public_id,
'hash': self.hash, 'hash': self.hash,
'in': self.start, 'in': float('%0.03f' % self.start),
'out': self.end, 'out': float('%0.03f' % self.end),
} }
if keys: if keys:
for key in keys: for key in keys:

View file

@ -27,8 +27,8 @@ def get_sequences(itemId):
s = models.Sequence() s = models.Sequence()
s.item = i s.item = i
s.mode = mode s.mode = mode
s.start = seq['in'] s.start = float('%0.03f' % seq['in'])
s.end = seq['out'] s.end = float('%0.03f' % seq['out'])
s.hash = seq['hash'] s.hash = seq['hash']
s.save() s.save()

View file

@ -113,11 +113,12 @@ def getSequence(request):
''' '''
data = json.loads(request.POST['data']) data = json.loads(request.POST['data'])
response = json_response() response = json_response()
position = float('%0.03f' % data['position'])
qs = models.Sequence.objects.filter( qs = models.Sequence.objects.filter(
item__itemId=data['id'], item__itemId=data['id'],
mode=data['mode'], mode=data['mode'],
start__lte=data['position'], start__lte=position,
end__gt=data['position'] end__gt=position
).order_by('start', 'end') ).order_by('start', 'end')
for sequence in qs: for sequence in qs:
response['data'] = sequence.json() response['data'] = sequence.json()