From c3d621350c549fd272af83dd6d38dd4301b7c072 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 21 Feb 2013 13:00:25 +0000 Subject: [PATCH] return editable, dont rename to empty string --- pandora/itemlist/models.py | 5 +++-- pandora/text/models.py | 7 ++++--- pandora/text/views.py | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pandora/itemlist/models.py b/pandora/itemlist/models.py index ff6957c6a..4748e736c 100644 --- a/pandora/itemlist/models.py +++ b/pandora/itemlist/models.py @@ -7,6 +7,7 @@ import subprocess from glob import glob from django.db import models +from django.db.models import Max from django.contrib.auth.models import User from django.conf import settings import ox @@ -156,9 +157,9 @@ class List(models.Model): self.status = value elif key == 'name': data['name'] = re.sub(' \[\d+\]$', '', data['name']).strip() + if not data['name']: + data['name'] = "Untitled" name = data['name'] - if not name: - name = "Untitled" num = 1 while List.objects.filter(name=name, user=self.user).exclude(id=self.id).count()>0: num += 1 diff --git a/pandora/text/models.py b/pandora/text/models.py index 585407005..a21a3b0da 100644 --- a/pandora/text/models.py +++ b/pandora/text/models.py @@ -8,6 +8,7 @@ from datetime import datetime from glob import glob from django.db import models +from django.db.models import Max from django.contrib.auth.models import User from django.conf import settings from django.db.models.signals import pre_delete @@ -114,9 +115,9 @@ class Text(models.Model): self.status = value elif key == 'name': data['name'] = re.sub(' \[\d+\]$', '', data['name']).strip() + if not data['name']: + data['name'] = "Untitled" name = data['name'] - if not name: - name = "Untitled" num = 1 while Text.objects.filter(name=name, user=self.user).exclude(id=self.id).count()>0: num += 1 @@ -128,7 +129,7 @@ class Text(models.Model): self.text = ox.sanitize_html(data['text']) if 'position' in data: - pos, created = Position.objects.get_or_create(text=text, user=user) + pos, created = Position.objects.get_or_create(text=self, user=user) pos.position = data['position'] pos.section = 'featured' if self.status == 'private': diff --git a/pandora/text/views.py b/pandora/text/views.py index 63aca5536..be621bea3 100644 --- a/pandora/text/views.py +++ b/pandora/text/views.py @@ -67,7 +67,7 @@ def addText(request): pos.position = qs.aggregate(Max('position'))['position__max'] + 1 pos.save() response = json_response(status=200, text='created') - response['data'] = text.json() + response['data'] = text.json(user=request.user) return render_to_json_response(response) actions.register(addText, cache=False) @@ -97,7 +97,7 @@ def getText(request): text = qs[0] else: text = get_text_or_404_json(data['id']) - response['data'] = text.json() + response['data'] = text.json(user=request.user) return render_to_json_response(response) actions.register(getText)