def post(self, request, *args, **kwargs): from music.forms import TrackForm form_post = TrackForm(request.POST, request.FILES) if request.is_ajax() and form_post.is_valid(): track = form_post.save(commit=False) new_track = track.create_manager_track( creator=request.user, title=track.title, file=track.file, lists=request.POST.getlist("list")) return render_for_platform(request, 'user_music/new_track.html', {'object': new_track}) else: return HttpResponseBadRequest()
def post(self, request, *args, **kwargs): self.track = Music.objects.get(pk=self.kwargs["pk"]) form_post = TrackForm(request.POST, request.FILES, instance=self.track) if request.is_ajax() and form_post.is_valid(): _track = form_post.save(commit=False) new_doc = _track.edit_track( title=_track.title, file=_track.file, lists=request.POST.getlist("list"), is_public=request.POST.get("is_public")) return render_for_platform(request, 'user_music/new_track.html', {'object': self.track}) else: return HttpResponseBadRequest()
def get_context_data(self, **kwargs): from music.forms import TrackForm from lists.models import MediaList context = super(CreateManagerTrack, self).get_context_data(**kwargs) context["form_post"] = TrackForm() context["get_lists"] = MediaList.objects.filter(owner__isnull=True) return context
def track_add(request): if request.method == 'POST': form = TrackForm(request.POST) if form.is_valid(): form.save() return JsonResponse({'status': 'ok'}) else: form = TrackForm() return render(request, 'track_add.html', {'form': form})
def get_context_data(self, **kwargs): context = super(UserTrackEdit, self).get_context_data(**kwargs) context["form_post"] = TrackForm(instance=self.track) context["track"] = self.track return context
def get_context_data(self, **kwargs): context = super(UserTrackCreate, self).get_context_data(**kwargs) context["form_post"] = TrackForm() return context