class UserPlaylistEdit(TemplateView): template_name = None form = None def get(self, request, *args, **kwargs): self.user = request.user self.template_name = get_small_template( "user_music/edit_list.html", request.user, request.META['HTTP_USER_AGENT']) return super(UserPlaylistEdit, self).get(request, *args, **kwargs) def get_context_data(self, **kwargs): context = super(UserPlaylistEdit, self).get_context_data(**kwargs) context["user"] = self.user context["list"] = SoundList.objects.get(uuid=self.kwargs["uuid"]) return context def post(self, request, *args, **kwargs): self.list = SoundList.objects.get(uuid=self.kwargs["uuid"]) self.form = PlaylistForm(request.POST, instance=self.list) if request.is_ajax() and self.form.is_valid(): list = self.form.save(commit=False) new_list = list.edit_list(name=list.name, description=list.description, order=list.order, is_public=request.POST.get("is_public")) return HttpResponse() else: return HttpResponseBadRequest() return super(UserPlaylistEdit, self).get(request, *args, **kwargs)
def post(self, request, *args, **kwargs): self.list = SoundList.objects.get(uuid=self.kwargs["uuid"]) self.form = PlaylistForm(request.POST, instance=self.list) if request.is_ajax() and self.form.is_valid(): list = self.form.save(commit=False) new_list = list.edit_list(name=list.name, description=list.description, order=list.order, is_public=request.POST.get("is_public")) return HttpResponse() else: return HttpResponseBadRequest() return super(UserPlaylistEdit, self).get(request, *args, **kwargs)
def post(self, request, *args, **kwargs): form_post = PlaylistForm(request.POST) if request.is_ajax() and form_post.is_valid(): new_list = form_post.save(commit=False) new_list.creator = request.user new_list.save() add_playlist(request.POST.get('permalink'), request.user, new_list) return render_for_platform( request, 'user_music/list.html', { 'playlist': new_list, 'object_list': new_list.playlist_too(), 'user': request.user }) else: return HttpResponseBadRequest()
def get(self, request, *args, **kwargs): context = self.get_context_data() context['form'] = PlaylistForm() context['playlists'] = requests.get(reverse("")) return render(request, self.template_name, context)
def post(self, request, *args, **kwargs): form_post = PlaylistForm(request.POST) if request.is_ajax() and form_post.is_valid(): list = form_post.save(commit=False) new_list = list.create_list( creator=request.user, name=list.name, description=list.description, order=list.order, community=None, is_public=request.POST.get("is_public")) return render_for_platform(request, 'user_music/list/my_list.html', { 'list': new_list, 'user': request.user }) else: return HttpResponseBadRequest()
def add_playlist(request): form = PlaylistForm(request.POST) if form.is_valid(): title = form.cleaned_data.get("title") try: existing_playlist = PlayList.objects.get(title=title) except PlayList.DoesNotExist: try: PlayList.objects.create(title=title, user=request.user) except Exception: resp = dict(result=API_FAILURE) else: resp = dict(result=API_SUCCESS) else: resp = dict(result=API_FAILURE) else: return HttpResponse(status=status.HTTP_400_BAD_REQUEST) return Response(resp, status=status.HTTP_200_OK, headers=NO_CACHE_HEADERS)
def get_context_data(self, **kwargs): context = super(UserSoundcloudSetCreate, self).get_context_data(**kwargs) context["form_post"] = PlaylistForm() return context