Ejemplo n.º 1
0
    def post(self, request):
      # create a form instance and populate it with data from the request:
      form = ClientUsernameForm(request.POST)
      # check whether it's valid:
      if form.is_valid():
          # process the data in form.cleaned_data as required
          # ...
          # redirect to a new URL:
          
          # Get information from username form
          username = form.cleaned_data["username"]
          client_name = form.cleaned_data["client"]

          # Client object and ID based on client chosen by user
          client = Client.objects.get(client_name=client_name)
          client_id = client.id

          # Check if the user has this a profile for this client, if not create it.
          try:
            client = current_user.clients.get(id=client_id)
            
          except client.DoesNotExist:
            new_client_profile = ClientProfile(user=current_user, client=client, username=username)
            new_client_profile.save()


          # Get user's playlists - Inside this helper function we will decide whether the data needs to be added to TuneBoss, updated or is already present.
          playlists = update_user_playlists(client, username, request)
          
          
          return HttpResponseRedirect('/home_view/')
Ejemplo n.º 2
0
def get_spotify_username(request):
    me = request.user
    context = {}
    if me.id is not None:
      access_token = me.access_token
      print access_token
      graph = OpenFacebook(access_token)
      if access_token is not None:
        listen_data = graph.get('me/music.listens')
        user_listens = []
        listens = listen_data['data']
        for listen in listens:
          tmp = []
          song_name = listen['data']['song']['title']
          client_url = listen['data']['song']['url']
          client_unique = re.search('track\/(.*)', client_url).group(1)
          tmp.append(song_name)
          tmp.append(client_unique)
          user_listens.append(tmp)

          print(json.dumps(song_name, sort_keys=True, indent=4, separators=(',', ': ')))
        context['user_listens'] = user_listens


    current_user = request.user
    print 'something'
    if current_user.id is not None:
      
      clientProfiles = current_user.clients.all()
      if clientProfiles:
        print clientProfiles
      else:
        print "clientProfiles"

    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = ClientUsernameForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            # process the data in form.cleaned_data as required
            # ...
            # redirect to a new URL:
            
            # Get information from username form
            username = form.cleaned_data["username"]
            client_name = form.cleaned_data["client"]

            # Client object and ID based on client chosen by user
            client = Client.objects.get(client_name=client_name)
            client_id = client.id

            # Check if the user has this a profile for this client, if not create it.
            try:
              client = current_user.clients.get(id=client_id)
              
            except client.DoesNotExist:
              new_client_profile = ClientProfile(user=current_user, client=client, username=username)
              new_client_profile.save()


            # Get user's playlists - Inside this helper function we will decide whether the data needs to be added to TuneBoss, updated or is already present.
            playlists = update_user_playlists(client, username, request)
            
            context = {}
            if current_user.id is not None:
              context['user_clientlists'] = current_user.member_clientlists.all()
            return render(request, 'home.html', context)

    # if a GET (or any other method) we'll create a blank form
    else: 
        form = ClientUsernameForm()

    
    
    if current_user.id is not None:
      print "current_user " + str(current_user.email)
      context['user_clientlists'] = current_user.member_clientlists.all()
    context['form'] = form
    return render(request, 'home.html', context)