From 6f10b1a78a0843ba400af5ad1f825bde00b27634 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 28 Dec 2010 15:46:16 +0530 Subject: [PATCH] better __unicode__ names --- pandora/itemlist/models.py | 4 ++-- pandora/itemlist/views.py | 14 ++++++++------ pandora/user/models.py | 3 +++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/pandora/itemlist/models.py b/pandora/itemlist/models.py index b2a58bfa..e116efb6 100644 --- a/pandora/itemlist/models.py +++ b/pandora/itemlist/models.py @@ -47,7 +47,7 @@ class List(models.Model): self.ListItem.objects.all().filter(item=item, list=self).delete() def __unicode__(self): - return u'%s (%s)' % (self.title, unicode(self.user)) + return u'%s (%s)' % (self.title, self.user) def editable(self, user): #FIXME: make permissions work @@ -62,5 +62,5 @@ class ListItem(models.Model): item = models.ForeignKey('item.Item') def __unicode__(self): - return u'%s in %s' % (unicode(self.item), unicode(self.list)) + return u'%s in %s' % (self.item, self.list) diff --git a/pandora/itemlist/views.py b/pandora/itemlist/views.py index e2d6c70d..b2d534ef 100644 --- a/pandora/itemlist/views.py +++ b/pandora/itemlist/views.py @@ -25,9 +25,7 @@ import ox from api.actions import actions -''' - List API -''' + @login_required_json def addListItem(request): ''' @@ -45,7 +43,7 @@ def addListItem(request): item = get_object_or_404_json(models.Item, pk=data['item']) if list.editable(request.user): list.add(item) - response = json_response(status=200, text='item removed') + response = json_response(status=200, text='item added') else: response = json_response(status=403, text='not allowed') elif 'query' in data: @@ -98,7 +96,10 @@ def addList(request): list.save() response = json_response(status=200, text='created') else: - response = json_response(status=403, text='list name exists') + response = json_response(status=200, text='list already exists') + response['data']['errors'] = { + 'name': 'List already exists' + } return render_to_json_response(response) actions.register(addList) @@ -109,7 +110,8 @@ def editList(request): {key: value} keys: name, public return {'status': {'code': int, 'text': string}, - 'data': {}} + 'data': {} + } ''' data = json.loads(request.POST['data']) list = get_object_or_404_json(models.List, pk=data['list']) diff --git a/pandora/user/models.py b/pandora/user/models.py index 768f13b6..7a3d58e2 100644 --- a/pandora/user/models.py +++ b/pandora/user/models.py @@ -30,6 +30,9 @@ class Preference(models.Model): key = models.CharField(blank=True, max_length=255) value = models.TextField(blank=True) + def __unicode__(self): + return u"%s/%s=%s" % (self.user, self.key, self.value) + def get_user_json(user): json = {} for key in ('username', ):