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