Example #1
0
def record(request, id):
    record_instance = common.models.Record.objects.get(pk=id)

    def get():
        return JsonResponse(serializers.serialize('json', record_instance))

    return resolve_http_method(request, [get])
Example #2
0
    def test_resolve_http_method_with_list(self):
        fake_request = FancyHash({"method":"GET"})
        def get():
            return HttpResponse("hello there")

        response = resolve_http_method(fake_request, [get])
        self.assertEqual(response.content, "hello there")
Example #3
0
def song(request, id):
    song_instance = common.models.Song.objects.get(pk=id)

    def get():
        return JsonResponse(serializers.serialize('json', song_instance))

    return resolve_http_method(request, [get])
Example #4
0
def author(request, id):
    author_instance = common.models.Author.objects.get(pk=id)

    def get():
        return JsonResponse(serializers.serialize('json', author_instance))

    return resolve_http_method(request, [get])
Example #5
0
    def test_resolve_http_method_with_list(self):
        fake_request = FancyHash({"method": "GET"})

        def get():
            return HttpResponse("hello there")

        response = resolve_http_method(fake_request, [get])
        self.assertEqual(response.content, "hello there")
Example #6
0
def search(request, id):

    search_instance = common.models.Search.objects.get(pk=id)

    def get(request):
        return JsonResponse(jsonify(search_instance))

    return resolve_http_method(request, [get])
Example #7
0
def upload(request):
    def post():
        uploaded = UploadedMedia.objects.create( 
                filename = "NA", 
                file = request.FILES['file'])

        return jsonify({"filename": uploaded.file.name, "filelink": uploaded.file.url})

    return resolve_http_method(request, [post])
Example #8
0
def upload(request):
    def post():
        uploaded = UploadedMedia.objects.create( 
                filename = "NA", 
                file = request.FILES['file'])

        return jsonify({"filename": uploaded.file.name, "filelink": uploaded.file.url})

    return resolve_http_method(request, [post])
Example #9
0
    def test_resolve_http_method_with_dict(self):
        fake_request = FancyHash({"method":"GET"})

        def get():
            return HttpResponse("hello there")
        def real_get():
            return HttpResponse("real hello there")

        response = resolve_http_method(fake_request, {"get":real_get})
        self.assertEqual(response.content, "real hello there")
Example #10
0
    def test_resolve_http_method_with_dict(self):
        fake_request = FancyHash({"method": "GET"})

        def get():
            return HttpResponse("hello there")

        def real_get():
            return HttpResponse("real hello there")

        response = resolve_http_method(fake_request, {"get": real_get})
        self.assertEqual(response.content, "real hello there")
Example #11
0
def searches(request):

    def post():
        s = common.models.Search(q=request.GET['q'])
        s.user = request.user
        s.save()

        return JsonResponse(jsonify(s.results()))

    def get():
        searches_by_user  = common.models.Search.filter(user = request.user)
        return JsonResponse(jsonify(searches_by_user))

    return resolve_http_method(request, [get, post])
Example #12
0
def register(request):
    new_user_form = UserRegistrationForm()
    c = { "registration_form": new_user_form }
    c.update(csrf(request))

    def get():
        return render(request, 'registration/register.html', c)

    def post():
        new_user_form = UserRegistrationForm(request.POST)
        c.update({ "registration_form": new_user_form })
        if new_user_form.is_valid():
            new_user_form.save()
            return redirect("login")
        return render(request, 'registration/register.html', c)

    return resolve_http_method(request, [get, post])
Example #13
0
def register(request):
    new_user_form = UserRegistrationForm()
    c = {"registration_form": new_user_form}
    c.update(csrf(request))

    def get():
        return render(request, 'registration/register.html', c)

    def post():
        new_user_form = UserRegistrationForm(request.POST)
        c.update({"registration_form": new_user_form})
        if new_user_form.is_valid():
            new_user_form.save()
            return redirect("login")

        return render(request, 'registration/register.html', c)

    return resolve_http_method(request, [get, post])
Example #14
0
def contact(request):
    c = standard_context()

    def get():
        c.update({'contact_form': ContactForm()})
        return render(request, 'pages/contact.html', c)

    def post():
        contact_form = ContactForm(request.POST)

        if contact_form.is_valid():
            contact_form.send_mail()
            messages.add_message(request, messages.SUCCESS, "Email Sent!")
            return redirect(request.path)

        c.update({'contact_form': contact_form})

        return render(request, 'pages/contact.html', c)

    return resolve_http_method(request, [get, post])
Example #15
0
 def test_resolve_http_method_returns_501_when_method_not_found(self):
     fake_request = FancyHash({"method":"GET"})
     response = resolve_http_method(fake_request, locals())
     self.assertEqual(response.status_code, 501)
Example #16
0
 def test_resolve_http_method_returns_501_when_method_not_found(self):
     fake_request = FancyHash({"method": "GET"})
     response = resolve_http_method(fake_request, locals())
     self.assertEqual(response.status_code, 501)