From d0ab1d8908cadac9f51a17e2fe9e1193f14e28cc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20St=C4=99pniowski?= Date: Thu, 28 Jan 2010 23:18:09 +0100 Subject: [PATCH] =?utf8?q?Dodanie=20API=20pozwalaj=C4=85cego=20na=20listow?= =?utf8?q?anie=20i=20wgrywanie=20ksi=C4=85=C5=BCek.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- scripts/test_api.py | 26 ++++++++++++++++++++++++++ wolnelektury/settings.py | 2 ++ wolnelektury/urls.py | 3 +++ 3 files changed, 31 insertions(+) create mode 100644 scripts/test_api.py diff --git a/scripts/test_api.py b/scripts/test_api.py new file mode 100644 index 000000000..41d3f3d98 --- /dev/null +++ b/scripts/test_api.py @@ -0,0 +1,26 @@ +import httplib2 +from poster.encode import multipart_encode +from poster.streaminghttp import register_openers +import sys +import getpass + +register_openers() + +datagen, headers = multipart_encode({'book_xml_file': open(sys.argv[1], "rb")}) +data = ''.join(list(datagen)) +for key, value in headers.items(): + headers[key] = str(value) + +password = getpass.getpass() + +h = httplib2.Http() +h.add_credentials('zuber', password) +h.follow_all_redirects = True + +resp, content = h.request( + 'http://localhost:8000/api/books.json', + 'POST', + body=data, + headers=headers +) +print resp, content \ No newline at end of file diff --git a/wolnelektury/settings.py b/wolnelektury/settings.py index 98fd9639d..b57599cf2 100644 --- a/wolnelektury/settings.py +++ b/wolnelektury/settings.py @@ -106,6 +106,8 @@ INSTALLED_APPS = [ 'compress', 'catalogue', 'lessons', + 'piston', + 'api', ] CACHE_BACKEND = 'locmem:///?max_entries=3000' diff --git a/wolnelektury/urls.py b/wolnelektury/urls.py index 4f49b9c5a..4f9d4ed73 100644 --- a/wolnelektury/urls.py +++ b/wolnelektury/urls.py @@ -39,6 +39,9 @@ urlpatterns = patterns('', url(r'^uzytkownicy/wyloguj/$', 'catalogue.views.logout_then_redirect', name='logout'), url(r'^uzytkownicy/utworz/$', 'catalogue.views.register', name='register'), + # API + (r'^api/', include('api.urls')), + # Static files url(r'^%s(?P.*)$' % settings.MEDIA_URL[1:], 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}), -- 2.20.1