Change some URLs associated with subscriptions.

Put all the 'API'-ish URLs in the /json/ namespace so that
/subscriptions and /subscriptions/add, etc. can be real
user-facing URLs if we want them to be.

(imported from commit 1455a32d27e44547ab1874b6289243cb40c85dde)
This commit is contained in:
Waseem Daher 2012-09-21 17:22:15 -04:00
parent f4483832b2
commit f1aa17cf1d
5 changed files with 12 additions and 12 deletions

View File

@ -19,9 +19,9 @@ urlpatterns = patterns('',
url(r'^settings/manage/$', 'zephyr.views.manage_settings', name='manage_settings'),
url(r'^settings/change/$', 'zephyr.views.change_settings', name='change_settings'),
url(r'^subscriptions/$', 'zephyr.views.subscriptions', name='subscriptions'),
url(r'^json/subscriptions/$', 'zephyr.views.json_subscriptions', name='json_subscriptions'),
url(r'^subscriptions/remove$', 'zephyr.views.remove_subscription', name='remove_subscription'),
url(r'^subscriptions/add$', 'zephyr.views.add_subscription', name='add_subscription'),
url(r'^json/subscriptions/list$', 'zephyr.views.json_list_subscriptions', name='list_subscriptions'),
url(r'^json/subscriptions/remove$', 'zephyr.views.json_remove_subscription', name='remove_subscription'),
url(r'^json/subscriptions/add$', 'zephyr.views.json_add_subscription', name='add_subscription'),
url(r'^static/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': os.path.join(settings.SITE_ROOT, '..', 'zephyr', 'static/')}),
url(r'^subscriptions/exists/(?P<zephyr_class>.*)$', 'zephyr.views.class_exists', name='class_exists'),

View File

@ -4,11 +4,11 @@
<div class="row-fluid">
<h1>Subscriptions</h1>
<form id="add_new_subscription" action="/subscriptions/add" method="post" class="form-inline">{% csrf_token %}
<form id="add_new_subscription" action="/json/subscriptions/add" method="post" class="form-inline">{% csrf_token %}
<input type="text" name="new_subscription" id="new_subscription" placeholder="Stream name" value="" class="input-xlarge" />
<input type="submit" name="add_subscription" value="Subscribe" class="btn btn-primary" />
</form>
<form id="current_subscriptions" action="/subscriptions/remove" method="post" class="subscriptions">{% csrf_token %}
<form id="current_subscriptions" action="/json/subscriptions/remove" method="post" class="subscriptions">{% csrf_token %}
<table class="table table-condensed" id="subscriptions_table">
<tr></tr>
</table>

View File

@ -42,7 +42,7 @@ $(function () {
$('#sidebar a[href="#subscriptions"]').click(function () {
$.ajax({
type: 'GET',
url: 'json/subscriptions/',
url: 'json/subscriptions/list',
dataType: 'json',
timeout: 10*1000,
success: function (data) {
@ -85,7 +85,7 @@ $.ajaxSetup({
function sub(zephyr_class) {
// TODO: check the return value and handle an error condition
$.post('/subscriptions/add', {new_subscription: zephyr_class});
$.post('/json/subscriptions/add', {new_subscription: zephyr_class});
}
function compose_button() {

View File

@ -94,8 +94,8 @@ class PublicURLTest(TestCase):
"""
urls = {200: ["/accounts/home/", "/accounts/login/", "/accounts/logout/",
"/accounts/register/"],
302: ["/", "/zephyr/", "/subscriptions/",
"/subscriptions/remove", "/subscriptions/add"]
302: ["/", "/zephyr/", "/json/subscriptions/list",
"/json/subscriptions/remove", "/json/subscriptions/add"]
}
for status_code, url_set in urls.iteritems():
self.fetch(url_set, status_code)

View File

@ -304,14 +304,14 @@ def subscriptions(request):
context_instance=RequestContext(request))
@login_required
def json_subscriptions(request):
def json_list_subscriptions(request):
subs = gather_subscriptions(UserProfile.objects.get(user=request.user))
return HttpResponse(content=simplejson.dumps({"subscriptions": subs}),
mimetype='application/json', status=200)
@login_required
@require_post
def remove_subscription(request):
def json_remove_subscription(request):
user_profile = UserProfile.objects.get(user=request.user)
if 'subscription' not in request.POST:
return json_error("Missing subscriptions")
@ -329,7 +329,7 @@ def remove_subscription(request):
@login_required
@require_post
def add_subscription(request):
def json_add_subscription(request):
user_profile = UserProfile.objects.get(user=request.user)
if "new_subscription" not in request.POST: