Example #1
0
def comment(request):
    if request.is_ajax() and request.method == 'POST':
        song_id = request.POST.get('song_id')
        comment_content = request.POST.get('comment')
        reply_to_user = request.POST.get('reply_to_user')

        comment_song = Song.objects.get(id=song_id)
        comment_song.comments = comment_song.comments + 1
        comment_song.save()

        c = SongComment()
        c.song = comment_song
        c.user = request.user
        c.comment = comment_content

        if comment_song.user != request.user:
            c.read_by_owner = False
        else:
            c.read_by_owner = True

        if reply_to_user:
            c.reply_to_user = User.objects.get(id=reply_to_user)

        c.save()

        #发微博
        if request.POST.get('share_to_weibo') == 'true':
            current_site = get_current_site(request)

            domain = current_site.domain
            public_radio_url = reverse('songs.views.public_radio',
                                       args=(comment_song.id, ))

            from social.views import _post_weibo
            s_url = 'http://%s%s' % (domain, public_radio_url)
            msg = '[%s-%s]%s' % (comment_song.title, comment_song.singer,
                                 comment_content)
            _post_weibo(request, msg, s_url)

        jsonData = '{"commented": true, "comments_count": %s}' % comment_song.comments
        return HttpResponse(jsonData)
    else:
        return HttpResponse('{}')
Example #2
0
def comment(request):
    if request.is_ajax() and request.method == "POST":
        song_id = request.POST.get("song_id")
        comment_content = request.POST.get("comment")
        reply_to_user = request.POST.get("reply_to_user")

        comment_song = Song.objects.get(id=song_id)
        comment_song.comments = comment_song.comments + 1
        comment_song.save()

        c = SongComment()
        c.song = comment_song
        c.user = request.user
        c.comment = comment_content

        if comment_song.user != request.user:
            c.read_by_owner = False
        else:
            c.read_by_owner = True

        if reply_to_user:
            c.reply_to_user = User.objects.get(id=reply_to_user)

        c.save()

        # 发微博
        if request.POST.get("share_to_weibo") == "true":
            current_site = get_current_site(request)

            domain = current_site.domain
            public_radio_url = reverse("songs.views.public_radio", args=(comment_song.id,))

            from social.views import _post_weibo

            s_url = "http://%s%s" % (domain, public_radio_url)
            msg = "[%s-%s]%s" % (comment_song.title, comment_song.singer, comment_content)
            _post_weibo(request, msg, s_url)

        jsonData = '{"commented": true, "comments_count": %s}' % comment_song.comments
        return HttpResponse(jsonData)
    else:
        return HttpResponse("{}")
Example #3
0
    def save(self, request):
       
        song = Song()
        song.user =  request.user
        
        domain_name = ''
        if self.cleaned_data['audio_url']:
            domain_name = self.cleaned_data['audio_url'].split('/')
            song.audio_url = self.cleaned_data['audio_url']                
            
        if self.cleaned_data['vedio_url']:
            domain_name = self.cleaned_data['vedio_url'].split('/')
            song.vedio_url = self.cleaned_data['vedio_url']
            
        if self.cleaned_data['flash_url']:
            domain_name = self.cleaned_data['flash_url'].split('/')
            song.flash_url = self.cleaned_data['flash_url']
            
        if len(domain_name) >= 2:
            song.source = domain_name[2]
            if song.flash_url:
                s_size = _get_swf_size(song.source)
                song.flash_width = s_size[0]
                song.flash_height = s_size[1]
            
        song.title = self.cleaned_data['title']
        song.singer = self.cleaned_data['singer']
        song.album = self.cleaned_data['album']
        song.genre = SongGenre.objects.get(id=self.cleaned_data['genre'])
        if self.cleaned_data['song_cover_url'].find('images/artist.png') == -1:
            song.song_cover_url = self.cleaned_data['song_cover_url']
        song.intro = self.cleaned_data['intro']
        song.show_media = True
        
        #当链接是百度那个下载链接(但不能在线引用播放)时,转成flash
        if song.audio_url and song.audio_url.find('zhangmenshiting') != -1 and song.audio_url.find('baidu') != -1:
            song.audio_url = None
            m = {'artist' : song.singer, 'name' : song.title, }
            song.flash_url = 'http://box.baidu.com/widget/flash/mbsong.swf?%s' % (urllib.urlencode(m))
            song.flash_width = 400
            song.flash_height = 95
        
        song.save()

        #加入电台播放
        if song.audio_url and request.POST.get('add_to_playlist'):
            _add_to_playlist(song, request.user)

        #发布到新浪微博
        if (request.POST.get('share_swf_to_weibo') and song.flash_url) or (request.POST.get('share_to_weibo') and song.audio_url):

            current_site = get_current_site(request)

            domain = current_site.domain
            public_radio_url = reverse('songs.views.public_radio',args=(song.id,))

            from social.views import _post_weibo
            s_url = 'http://%s%s' % (domain, public_radio_url)
            msg = '[%s-%s]%s' %(song.title, song.singer, song.intro)
            _post_weibo(request, msg, s_url)

        request.user.get_profile()
        request.user.get_profile().songs = request.user.get_profile().songs + 1
        request.user.get_profile().save()