From 0ae3305a649ab5a0f76402f235f47c68ff49d304 Mon Sep 17 00:00:00 2001 From: Corentin Chary Date: Thu, 17 Nov 2011 14:37:59 +0100 Subject: [PATCH] euscanwww/api: clean and "document" euscan API Signed-off-by: Corentin Chary --- euscanwww/api/handlers.py | 4 ++-- euscanwww/api/urls.py | 19 ++++++++++--------- euscanwww/euscan/urls.py | 1 + euscanwww/euscan/views.py | 4 ++++ euscanwww/templates/_base.html | 1 + euscanwww/templates/euscan/api.html | 22 ++++++++++++++++++++++ 6 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 euscanwww/templates/euscan/api.html diff --git a/euscanwww/api/handlers.py b/euscanwww/api/handlers.py index 0b81e4c..7c43ba0 100644 --- a/euscanwww/api/handlers.py +++ b/euscanwww/api/handlers.py @@ -108,8 +108,8 @@ class PackagesHandler(AnonymousBaseHandler): herd = get_object_or_404(Herd, herd=kwargs['herd']) packages = Package.objects.filter(herds__id=herd.id) data = { 'herd' : herd, 'packages' : packages } - elif 'maintainer' in kwargs: - maintainer = get_object_or_404(Maintainer, id=kwargs['maintainer']) + elif 'maintainer_id' in kwargs: + maintainer = get_object_or_404(Maintainer, id=kwargs['maintainer_id']) packages = Package.objects.filter(maintainers__id=maintainer.id) data = { 'maintainer' : maintainer, 'packages' : packages } diff --git a/euscanwww/api/urls.py b/euscanwww/api/urls.py index 04dec20..089f52d 100644 --- a/euscanwww/api/urls.py +++ b/euscanwww/api/urls.py @@ -12,15 +12,16 @@ packages_handler = Resource(handler=PackagesHandler) package_handler = Resource(handler=PackageHandler) urlpatterns = patterns('api.views', - (r'^1.0/statistics\.(?P.+)$', statistics_handler), - (r'^1.0/herds\.(?P.+)$', herds_handler), - (r'^1.0/categories\.(?P.+)$', categories_handler), - (r'^1.0/maintainers\.(?P.+)$', maintainers_handler), + url(r'^1.0/statistics\.(?P.+)$', statistics_handler, name='api.views.statistics'), + url(r'^1.0/herds\.(?P.+)$', herds_handler, name='api.views.herds'), + url(r'^1.0/categories\.(?P.+)$', categories_handler, name='api.views.categories'), + url(r'^1.0/maintainers\.(?P.+)$', maintainers_handler, name='api.views.maintainers'), - (r'^1.0/packages/by-maintainer/(?P\d+)\.(?P.+)$', packages_handler), - (r'^1.0/packages/by-herd/(?P[\@\{\}\w+.-]*)\.(?P.+)?$', packages_handler), - (r'^1.0/packages/by-category/(?P[\w+][\w+.-]*)\.(?P.+)?$', packages_handler), - (r'^1.0/package/(?P[\w+][\w+.-]*)/(?P[\w+][\w+.-]*)\.(?P.+)$', package_handler), + url(r'^1.0/packages/by-maintainer/(?P\d+)\.(?P.+)$', packages_handler, name='api.views.packages'), + url(r'^1.0/packages/by-herd/(?P[\@\{\}\w+.-]*)\.(?P.+)?$', packages_handler, name='api.views.packages'), + url(r'^1.0/packages/by-category/(?P[\w+][\w+.-]*)\.(?P.+)?$', packages_handler, name='api.views.packages'), - (r'^1.0/api\.(?P.+)$', root_handler), + url(r'^1.0/package/(?P[\w+][\w+.-]*)/(?P[\w+][\w+.-]*)\.(?P.+)$', package_handler, name='api.views.package'), + + url(r'^1.0/api\.(?P.+)$', root_handler, name='api.views.root'), ) diff --git a/euscanwww/euscan/urls.py b/euscanwww/euscan/urls.py index d66e7a1..30ce1a0 100644 --- a/euscanwww/euscan/urls.py +++ b/euscanwww/euscan/urls.py @@ -32,6 +32,7 @@ urlpatterns = patterns('euscan.views', (r'^$', 'index'), url(r'^feed/$', GlobalFeed(), name='global_feed'), (r'^about/$', 'about'), + (r'^about/api$', 'api'), (r'^statistics/$', 'statistics'), (r'^statistics/charts/(?P[\w\-]+).png$', 'chart'), (r'^world/$', 'world'), diff --git a/euscanwww/euscan/views.py b/euscanwww/euscan/views.py index e22a242..cca8694 100644 --- a/euscanwww/euscan/views.py +++ b/euscanwww/euscan/views.py @@ -123,6 +123,10 @@ def world_scan(request): def about(request): return {} +@render_to("euscan/api.html") +def api(request): + return {} + @render_to("euscan/statistics.html") def statistics(request): return {} diff --git a/euscanwww/templates/_base.html b/euscanwww/templates/_base.html index d995569..a69a4c3 100644 --- a/euscanwww/templates/_base.html +++ b/euscanwww/templates/_base.html @@ -46,6 +46,7 @@ {% endblock %}
  • ---
  • +
  • API
  • About
  • {% endblock %} diff --git a/euscanwww/templates/euscan/api.html b/euscanwww/templates/euscan/api.html new file mode 100644 index 0000000..2bbf5b6 --- /dev/null +++ b/euscanwww/templates/euscan/api.html @@ -0,0 +1,22 @@ +{% extends "_base.html" %} + +{% block content %} +

    API

    + +

    +

    + +Formats: xml, yaml and json +

    + +{% endblock %}