error strings, sort api in docs

This commit is contained in:
j 2010-12-24 15:44:13 +05:30
parent 31cf62c752
commit ae96cf86c7
2 changed files with 13 additions and 12 deletions

View file

@ -35,7 +35,7 @@ def api_login(request):
status: {'code': int, 'text': string} status: {'code': int, 'text': string}
data: { data: {
errors: { errors: {
username: 'Unknown User', username: 'Unknown Username',
password: 'Incorrect Password' password: 'Incorrect Password'
} }
user: { user: {
@ -50,7 +50,7 @@ def api_login(request):
if models.User.objects.filter(username=form.data['username']).count() == 0: if models.User.objects.filter(username=form.data['username']).count() == 0:
response = json_response({ response = json_response({
'errors': { 'errors': {
'username': 'Unknown User' 'username': 'Unknown Username'
} }
}) })
else: else:
@ -88,8 +88,9 @@ def api_logout(request):
status: {'code': int, 'text': string} status: {'code': int, 'text': string}
} }
''' '''
response = json_response(text='logged out') response = json_response(text='ok')
if request.user.is_authenticated(): if request.user.is_authenticated():
response = json_response(text='logged out')
logout(request) logout(request)
return render_to_json_response(response) return render_to_json_response(response)
actions.register(api_logout, 'logout') actions.register(api_logout, 'logout')
@ -111,7 +112,7 @@ def register(request):
status: {'code': int, 'text': string} status: {'code': int, 'text': string}
data: { data: {
errors: { errors: {
username: 'Unknown User', username: 'Unknown Username',
password: 'Incorrect Password' password: 'Incorrect Password'
} }
user: { user: {
@ -126,13 +127,13 @@ def register(request):
if models.User.objects.filter(username=form.data['username']).count() > 0: if models.User.objects.filter(username=form.data['username']).count() > 0:
response = json_response({ response = json_response({
'errors': { 'errors': {
'username': 'Username taken' 'username': 'Username already exists'
} }
}) })
elif models.User.objects.filter(email=form.data['email']).count() > 0: elif models.User.objects.filter(email=form.data['email']).count() > 0:
response = json_response({ response = json_response({
'errors': { 'errors': {
'email': 'Email is used by another account' 'email': 'Email address already exits'
} }
}) })
else: else:
@ -168,7 +169,7 @@ def api_recover(request):
status: {'code': int, 'text': string} status: {'code': int, 'text': string}
data: { data: {
errors: { errors: {
username_or_email: 'Username or email not found' username_or_email: 'Username or email address not found'
} }
} }
} }
@ -203,7 +204,7 @@ def api_recover(request):
else: else:
response = json_response({ response = json_response({
'errors': { 'errors': {
'username_or_email': 'Username or email not found' 'username_or_email': 'Username or email address not found'
} }
}) })
else: else:

View file

@ -60,16 +60,16 @@ function constructList() {
id: 'actionList', id: 'actionList',
request: function(data, callback) { request: function(data, callback) {
if(!data.keys) { if(!data.keys) {
app.api.apidoc(function(results) { app.api.api(function(results) {
var items = []; var items = [];
$.each(results.data.actions, function(k) {items.push({'name': k})}); $.each(results.data.actions, function(i, k) {items.push({'name': k})});
var result = {'data': {'items': items.length}}; var result = {'data': {'items': items.length}};
callback(result); callback(result);
}); });
} else { } else {
app.api.apidoc(function(results) { app.api.api(function(results) {
var items = []; var items = [];
$.each(results.data.actions, function(k) {items.push({'name': k})}); $.each(results.data.actions, function(i, k) {items.push({'name': k})});
var result = {'data': {'items': items}}; var result = {'data': {'items': items}};
callback(result); callback(result);
}); });