Commit e739141b authored by fred's avatar fred

add timestamp of moment when the file is included in a nonstop zone

parent c2796785
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('nonstop', '0008_track_uploader'),
]
operations = [
migrations.AddField(
model_name='track',
name='added_to_nonstop_timestamp',
field=models.DateTimeField(null=True),
),
]
......@@ -5,6 +5,7 @@ import mutagen
from django.conf import settings
from django.core.urlresolvers import reverse
from django.db import models
from django.utils.timezone import now
from django.utils.translation import ugettext_lazy as _
REMOTE_BASE_PATH = '/srv/soma/nonstop/'
......@@ -58,6 +59,7 @@ class Track(models.Model):
nonstop_zones = models.ManyToManyField('emissions.Nonstop', blank=True)
creation_timestamp = models.DateTimeField(auto_now_add=True, null=True)
added_to_nonstop_timestamp = models.DateTimeField(null=True)
uploader = models.ForeignKey(settings.AUTH_USER_MODEL, null=True)
class Meta:
......@@ -80,11 +82,19 @@ class Track(models.Model):
return False
def sync_nonstop_zones(self):
current_zones = self.nonstop_zones.all()
if current_zones.count():
if not self.added_to_nonstop_timestamp:
self.added_to_nonstop_timestamp = now()
self.save()
else:
self.added_to_nonstop_timestamp = None
self.save()
if not self.file_exists():
return
nonstop_file = self.nonstopfile_set.order_by('creation_timestamp').last()
filename = nonstop_file.filename
current_zones = self.nonstop_zones.all()
from emissions.models import Nonstop
for zone in Nonstop.objects.all():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment