Beispiel #1
0
	def post(self, request, *args, **kwargs):

		d = {}
		alertMsg = '''We are facing some error in retriving  
					media info. Can you please try again later'''
		bstrpCls = 'alert-danger'
		if request.user.is_authenticated():
			songURL = request.POST.get('url', None)
			if songURL:
				title, views, likes, dislikes = return_song_details(songURL)
				if title:
					try:
						newsong = SongDetails.objects.get(url=songURL)
					except:
						newsong = SongDetails(
							url=songURL, name=title, views=views,
							dislikes=dislikes, likes=likes)
						newsong.save()
					mySongInPlaylist, created =  MySongModel.objects.get_or_create(
										song=newsong, owner=request.user)
					if not created:
						alertMsg = 'Looks like this song is already in your playlist'
						bstrpCls = 'alert-warning'
					else:
						alertMsg = mark_safe('''%s is now added in your playlist.''' % (
										title))
						bstrpCls = 'alert-info'
		d['alertMsg'] = alertMsg
		d['alrtBstrpCls'] = bstrpCls
		return HttpResponse(json.dumps(d))
Beispiel #2
0
	def post(self,request,*args,**kwargs):

		parseError 				= False
		alertMsg, alrtBstrpCls 	= [None]*2
		d 						= {}

		if request.user.is_authenticated():
			suggestedBy			= request.user
			songURL				= request.POST.get("songName",None)
			suggestedToId 		= request.POST.get("suggestedTo",None)
			suggestedTo 		= User.objects.get(id=suggestedToId)
			# print suggestedBy.id ,'suggesting to ', suggestedToId

			if songURL is not None:

				# before parinsg info for song, check if this song is already
				# suggested or not
				isSongPresent 		= SuggestedSongs.objects.filter(suggestedTo=suggestedToId,
										suggestedBy=suggestedBy.id,song__url=songURL)
				if isSongPresent:
					# means that the song is already suggested
					alertMsg 	= '''Oops!! Looks like you have already suggested  
									this song to {user}'''.format(user=suggestedTo.username)
					alrtBstrpCls = 'alert-info'

				else:

					title, views, likes, dislikes = return_song_details(songURL)

					if title is not None:
						newsong = SongDetails(
							url=songURL,name=title,views=views,
							dislikes=dislikes,likes=likes
							)
						newsong.save()
						suggestion = SuggestedSongs(suggestedTo=suggestedTo,
							suggestedBy=suggestedBy,song=newsong,isSeen=False)
						suggestion.save()
						# notify 
						senderEmail = suggestedBy.email
						senderName = suggestedBy.username
						recipientEmail = [suggestedTo.email]
						subject = '{0} has suggested you a song'.format(senderName)
						message = '{0} has suggested you {1}'.format(senderName, title)
						# dont delete this comment
						# custom_send_mail(recipientEmail, senderEmail, subject, message)

						alertMsg 	= mark_safe('''Your song is successfully suggested to %s. 
									What a %s suggestion''' % (
										suggestedTo.username,
										'<i class="glyphicon glyphicon-heart"></i>'
										))
						alrtBstrpCls = 'alert-info'
					
					else:
						alertMsg	 = '''We are facing some error in retriving  
										media info. Can you please try again later'''
						alrtBstrpCls  = 'alert-danger'

		d = {
			'alrtBstrpCls'	: alrtBstrpCls,
			'alertMsg'		: alertMsg
		}
		return HttpResponse(json.dumps(d))