Skip to content

Commit

Permalink
Added missing resources in APIv3
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Greenfeld committed Mar 13, 2015
1 parent c4ea735 commit 94e4ca4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
7 changes: 6 additions & 1 deletion apiv3/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
view=views.grid_detail,
name="grid_detail",
),
url(
regex=r"^grids/(?P<slug>[-\w]+)/packages/$",
view=views.grid_packages_list,
name="grid_packages_list",
),
url(
regex=r"^packages/$",
view=views.package_list,
Expand Down Expand Up @@ -42,5 +47,5 @@
regex=r"^users/$",
view=views.user_list,
name="user_list"
)
),
)
20 changes: 20 additions & 0 deletions apiv3/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,26 @@ def user_detail(request, github_account):
list_packages = request.GET.get("list_packages", False)
return user_resource(profile, list_packages)

@json_view
def grid_packages_list(request, slug):
grid = get_object_or_404(Grid, slug=slug)
packages = Package.objects.filter(grid=grid)
count = packages.count()
limit = GET_int(request, "limit", 20)
offset = GET_int(request, "offset", 0)
# build the Data structure
data = {
"meta": {
"limit": limit,
"next": calc_next(request, limit, offset, count),
"offset": offset,
"previous": calc_previous(request, limit, offset, count),
"total_count": count
},
"grid": grid_resource(grid),
"objects": [package_resource(x) for x in packages[offset:offset + limit]]
}
return data

@json_view
def index(request):
Expand Down
25 changes: 23 additions & 2 deletions docs/apiv3_docs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ URI Resource Methods
/categories_/{slug}/ Category GET
/grids_/ Grid list GET
/grids_/{slug}/ Grid GET
/packages_/ Package list GET
/packages_/{slug}/ Package GET
/grid_/{slug}/packages_/ Grid Packages list GET
/packages_/ Package list GET
/packages_/{slug}/ Package GET
/users_/{slug}/ User GET
============================================== ======================= ==================

Resources
Expand Down Expand Up @@ -132,3 +134,22 @@ Representation:
"usage_count": 356
}
User
~~~~

Representation:

.. parsed-literal::
{
"username": "jezdez",
"last_login": "2014-09-21T07:37:17.619",
"date_joined": "2010-08-21T07:14:03",
"created": "2011-09-09T17:10:29.509",
"absolute_url": "/profiles/jezdez/",
"google_code_url": null,
"github_account": "jezdez",
"bitbucket_url": "jezdez",
"modified": "2014-09-21T07:37:17.598",
"resource_uri": "/api/v3/users/jezdez/"
}

0 comments on commit 94e4ca4

Please sign in to comment.