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()
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)
)
if self.item:
@ -49,8 +49,8 @@ class Sequence(models.Model):
j = {
'id': self.public_id,
'hash': self.hash,
'in': self.start,
'out': self.end,
'in': float('%0.03f' % self.start),
'out': float('%0.03f' % self.end),
}
if keys:
for key in keys:

View file

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

View file

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