Commit e9ca58ae authored by fred's avatar fred

make it possible to edit all custom metadata

parent 936ed488
......@@ -15,7 +15,7 @@ class UploadTracksForm(forms.Form):
nonstop_zone = forms.ChoiceField(choices=get_optional_nonstop_zones)
class NonstopZonesForm(forms.ModelForm):
class TrackMetaForm(forms.ModelForm):
class Meta:
model = Track
fields = ['nonstop_zones']
fields = ['language', 'instru', 'sabam', 'cfwb', 'nonstop_zones']
......@@ -75,6 +75,8 @@ class Track(models.Model):
return os.path.exists(self.nonstopfile_set.order_by('creation_timestamp').last().get_local_filepath())
def sync_nonstop_zones(self):
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()
......
......@@ -26,7 +26,7 @@
{% if object.file_exists %}
<form method="POST">
{% csrf_token %}
{{ zones_form.as_p }}
{{ metadata_form.as_p }}
<div class="buttons">
<button class="submit-button">{% trans "Update" %}</button>
</div>
......
......@@ -18,7 +18,7 @@ from django.views.generic.detail import DetailView
from django.views.generic.edit import FormView
from django.views.generic.list import ListView
from .forms import UploadTracksForm, NonstopZonesForm
from .forms import UploadTracksForm, TrackMetaForm
from .models import SomaLogLine, Track, Artist, NonstopFile
from emissions.models import Nonstop
......@@ -63,14 +63,14 @@ class TrackDetailView(DetailView):
def get_context_data(self, **kwargs):
ctx = super(TrackDetailView, self).get_context_data(**kwargs)
ctx['zones_form'] = NonstopZonesForm(instance=self.object)
ctx['metadata_form'] = TrackMetaForm(instance=self.object)
return ctx
def post(self, request, *args, **kwargs):
instance = self.get_object()
old_nonstop_zones = copy.copy(instance.nonstop_zones.all())
zones_form = NonstopZonesForm(request.POST, instance=instance)
zones_form.save()
form = TrackMetaForm(request.POST, instance=instance)
form.save()
new_nonstop_zones = self.get_object().nonstop_zones.all()
if set(old_nonstop_zones) != set(new_nonstop_zones):
instance.sync_nonstop_zones()
......
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