Ejemplo n.º 1
0
def bunch_create_tracks():
    """Feed the database with tracks from the .txt"""
    file_path = join(MEDIA_ROOT, 'setup/track_db.txt')
    with open(file_path, 'r') as f:
        for line in f:
            line_data = line.split("_")
            artist = line_data[0]
            name = line_data[1]
            url = line_data[2]
            sg = Song(url=url, artist=artist, name=name)
            sg.save()
Ejemplo n.º 2
0
def feed_db_track(request):
    if request.user.username == "hipmaster":
        file_path = join(MEDIA_ROOT, 'setup/track_db.txt')
        with open(file_path, 'r') as f:
            for line in f:
                line_data = line.split("_")
                artist = line_data[0]
                name = line_data[1]
                url = line_data[2]
                sg = Song(url=url, artist=artist, name=name)
                sg.save()

        return HttpResponseRedirect(reverse('hip_engine.views.people', args=(request.user.username,)))
    else:
        return HttpResponseRedirect(reverse('hip_engine.views.index'))
Ejemplo n.º 3
0
def reply_bundle(request, username, swap_id):

    userto = get_object_or_404(UserProfile,user__username=username)
    sw = get_object_or_404(Swap,pk=swap_id)

    if request.POST['url_1'] and request.POST['url_2'] and request.POST['url_3']:

        validate = URLValidator(verify_exists=True)
        try:
            validate(request.POST['url_1'])
            validate(request.POST['url_2'])
            validate(request.POST['url_3'])

            if request.POST['url_1']!=request.POST['url_2'] and request.POST['url_1']!=request.POST['url_3'] and request.POST['url_2']!=request.POST['url_3']:

                if request.POST['artist_1']and request.POST['name_1']:
                    sg1 = Song(url=request.POST['url_1'], artist=request.POST['artist_1'], name=request.POST['name_1'])
                elif request.POST['artist_1']:
                    sg1 = Song(url=request.POST['url_1'], artist=request.POST['artist_1'])
                else:
                    sg1 = Song(url=request.POST['url_1'])
                sg1.save()

                if request.POST['artist_2']and request.POST['name_2']:
                    sg2 = Song(url=request.POST['url_2'], artist=request.POST['artist_2'], name=request.POST['name_2'])
                elif request.POST['artist_2']:
                    sg1 = Song(url=request.POST['url_2'], artist=request.POST['artist_2'])
                else:
                    sg2 = Song(url=request.POST['url_2'])
                sg2.save()

                if request.POST['artist_3']and request.POST['name_3']:
                    sg3 = Song(url=request.POST['url_3'], artist=request.POST['artist_3'], name=request.POST['name_3'])
                elif request.POST['artist_3']:
                    sg1 = Song(url=request.POST['url_3'], artist=request.POST['artist_3'])
                else:
                    sg3 = Song(url=request.POST['url_3'])
                sg3.save()        

                if request.POST['title']:
                    b = Bundle(title=request.POST['title'] , pub_date=timezone.now(),song1=sg1, song2=sg2, song3=sg3)
                else:
                    b = Bundle(pub_date=timezone.now(),song1=sg1, song2=sg2, song3=sg3)
            
                b.save()
                sw.bundleback = b
                sw.edit_date = b.pub_date
                sw.save()

                if sw.userfrom.is_email_notified:
                    from django.core.mail import send_mail
                    send_mail(generate_header_bundleback(sw), generate_body_bundleback(sw), 'HipMe', [sw.userfrom.user.email])
                
                if request.POST['next']:
                    url = request.POST['next']
                    return HttpResponseRedirect(url)
                else:
                    return HttpResponseRedirect(reverse('hip_engine.views.index'))

            else:
                return render_to_response('hip_engine/bundleback.html', {'user_focused': userto, 'error_message': "Some track urls do matchs. Please put 3 differents tracks.",}, context_instance=RequestContext(request))

        except ValidationError, e:
            return render_to_response('hip_engine/new_bundle.html', {'user_focused': userto, 'error_message': "Some track urls are not valid. Please check the url fields.",}, context_instance=RequestContext(request))
Ejemplo n.º 4
0
def reply_bundle(request, username, swap_id):

    userto = get_object_or_404(UserProfile, user__username=username)
    sw = get_object_or_404(Swap, pk=swap_id)

    if request.POST["url_1"] and request.POST["url_2"] and request.POST["url_3"]:

        if (
            request.POST["url_1"] != request.POST["url_2"]
            and request.POST["url_1"] != request.POST["url_3"]
            and request.POST["url_2"] != request.POST["url_3"]
        ):

            if request.POST["artist_1"] and request.POST["name_1"]:
                sg1 = Song(url=request.POST["url_1"], artist=request.POST["artist_1"], name=request.POST["name_1"])
            elif request.POST["artist_1"]:
                sg1 = Song(url=request.POST["url_1"], artist=request.POST["artist_1"])
            else:
                sg1 = Song(url=request.POST["url_1"])
            sg1.save()

            if request.POST["artist_2"] and request.POST["name_2"]:
                sg2 = Song(url=request.POST["url_2"], artist=request.POST["artist_2"], name=request.POST["name_2"])
            elif request.POST["artist_2"]:
                sg1 = Song(url=request.POST["url_2"], artist=request.POST["artist_2"])
            else:
                sg2 = Song(url=request.POST["url_2"])
            sg2.save()

            if request.POST["artist_3"] and request.POST["name_3"]:
                sg3 = Song(url=request.POST["url_3"], artist=request.POST["artist_3"], name=request.POST["name_3"])
            elif request.POST["artist_3"]:
                sg1 = Song(url=request.POST["url_3"], artist=request.POST["artist_3"])
            else:
                sg3 = Song(url=request.POST["url_3"])
            sg3.save()

            if request.POST["title"]:
                b = Bundle(title=request.POST["title"], pub_date=timezone.now(), song1=sg1, song2=sg2, song3=sg3)
            else:
                b = Bundle(pub_date=timezone.now(), song1=sg1, song2=sg2, song3=sg3)

            b.save()
            sw.bundleback = b
            sw.edit_date = b.pub_date
            sw.save()

            if request.GET.get("next", ""):
                url = request.GET.get("next", "")
                return HttpResponseRedirect(url)
            else:
                return HttpResponseRedirect(reverse("hip_engine.views.index"))

        else:
            return render_to_response(
                "hip_engine/bundleback.html",
                {"user_focused": userto, "error_message": "Some track urls do matchs. Please put 3 differents tracks."},
                context_instance=RequestContext(request),
            )

    else:
        return render_to_response(
            "hip_engine/bundleback.html",
            {"user_focused": userto, "error_message": "Some urls are missing. Please fill all the urls fields."},
            context_instance=RequestContext(request),
        )
Ejemplo n.º 5
0
def send_bundle(request, username):

    userto = get_object_or_404(UserProfile, user__username=username)
    userfrom = get_object_or_404(UserProfile, user=request.user)

    if request.POST["url_1"] and request.POST["url_2"] and request.POST["url_3"]:

        if (
            request.POST["url_1"] != request.POST["url_2"]
            and request.POST["url_1"] != request.POST["url_3"]
            and request.POST["url_2"] != request.POST["url_3"]
        ):

            if request.POST["artist_1"] and request.POST["name_1"]:
                sg1 = Song(url=request.POST["url_1"], artist=request.POST["artist_1"], name=request.POST["name_1"])
            elif request.POST["artist_1"]:
                sg1 = Song(url=request.POST["url_1"], artist=request.POST["artist_1"])
            else:
                sg1 = Song(url=request.POST["url_1"])
            sg1.save()

            if request.POST["artist_2"] and request.POST["name_2"]:
                sg2 = Song(url=request.POST["url_2"], artist=request.POST["artist_2"], name=request.POST["name_2"])
            elif request.POST["artist_2"]:
                sg1 = Song(url=request.POST["url_2"], artist=request.POST["artist_2"])
            else:
                sg2 = Song(url=request.POST["url_2"])
            sg2.save()

            if request.POST["artist_3"] and request.POST["name_3"]:
                sg3 = Song(url=request.POST["url_3"], artist=request.POST["artist_3"], name=request.POST["name_3"])
            elif request.POST["artist_3"]:
                sg1 = Song(url=request.POST["url_3"], artist=request.POST["artist_3"])
            else:
                sg3 = Song(url=request.POST["url_3"])
            sg3.save()

            if request.POST["title"]:
                b = Bundle(title=request.POST["title"], pub_date=timezone.now(), song1=sg1, song2=sg2, song3=sg3)
            else:
                b = Bundle(pub_date=timezone.now(), song1=sg1, song2=sg2, song3=sg3)

            b.save()
            sw = Swap(userfrom=userfrom, userto=userto, bundlego=b, edit_date=b.pub_date)
            sw.save()

            if userto.is_email_notified:
                from django.core.mail import send_mail

                send_mail(
                    generate_header_new_bundle(userto.user, sw),
                    generate_body_new_bundle(userto.user, sw),
                    "HipMe",
                    [userto.user.email],
                )

            if request.GET.get("next", ""):
                url = request.GET.get("next", "")
                return HttpResponseRedirect(url)
            else:
                return HttpResponseRedirect(reverse("hip_engine.views.index"))

        else:
            return render_to_response(
                "hip_engine/new_bundle.html",
                {"user_focused": userto, "error_message": "Some track urls do matchs. Please put 3 differents tracks."},
                context_instance=RequestContext(request),
            )

    else:
        return render_to_response(
            "hip_engine/new_bundle.html",
            {"user_focused": userto, "error_message": "Some urls are missing. Please fill all the urls fields."},
            context_instance=RequestContext(request),
        )