Commit 411e1c54 authored by Jelle van der Waa's avatar Jelle van der Waa 🚧
Browse files

todolists: Add json endpoint for todo detail view

Add a /todo/$name/json endpoint which returns the json for a todo list
parent bf3e96dc
......@@ -27,3 +27,9 @@ def test_todolist_detail(self):
response = self.client.get(self.todolist.get_absolute_url())
self.assertEqual(response.status_code, 200)
self.assertIn(, response.content)
def test_todolist_json(self):
response = self.client.get(self.todolist.get_absolute_url() + 'json')
self.assertEqual(response.status_code, 200)
data = response.json()
from django.conf.urls import url
from django.contrib.auth.decorators import permission_required
from .views import (view_redirect, view, add, edit, flag,
from .views import (view_redirect, view, view_json, add, edit, flag,
list_pkgbases, DeleteTodolist, TodolistListView)
urlpatterns = [
......@@ -13,6 +13,7 @@
url(r'^(?P<slug>[-\w]+)/$', view),
url(r'^(?P<slug>[-\w]+)/json$', view_json),
......@@ -14,7 +14,7 @@
from main.models import Package, Repo
from main.utils import find_unique_slug
from packages.utils import attach_maintainers
from packages.utils import attach_maintainers, PackageJSONEncoder
from .models import Todolist, TodolistPackage
from .utils import get_annotated_todolists, attach_staging
......@@ -236,4 +236,23 @@ def send_todolist_emails(todo_list, new_packages):
class TodoListJSONEncoder(PackageJSONEncoder):
def default(self, obj):
if isinstance(obj, Todolist):
return {
'description': obj.description,
'packages': [pkg.pkg for pkg in obj.packages()],
return super(TodoListJSONEncoder, self).default(obj)
def view_json(request, slug):
todolist = get_object_or_404(Todolist, slug=slug)
to_json = json.dumps(todolist, ensure_ascii=False, cls=TodoListJSONEncoder)
return HttpResponse(to_json, content_type='application/json')
# vim: set ts=4 sw=4 et:
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment