return editable, dont rename to empty string

This commit is contained in:
j 2013-02-21 13:00:25 +00:00
parent 32d7184758
commit c3d621350c
3 changed files with 9 additions and 7 deletions

View file

@ -7,6 +7,7 @@ import subprocess
from glob import glob from glob import glob
from django.db import models from django.db import models
from django.db.models import Max
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.conf import settings from django.conf import settings
import ox import ox
@ -156,9 +157,9 @@ class List(models.Model):
self.status = value self.status = value
elif key == 'name': elif key == 'name':
data['name'] = re.sub(' \[\d+\]$', '', data['name']).strip() data['name'] = re.sub(' \[\d+\]$', '', data['name']).strip()
if not data['name']:
data['name'] = "Untitled"
name = data['name'] name = data['name']
if not name:
name = "Untitled"
num = 1 num = 1
while List.objects.filter(name=name, user=self.user).exclude(id=self.id).count()>0: while List.objects.filter(name=name, user=self.user).exclude(id=self.id).count()>0:
num += 1 num += 1

View file

@ -8,6 +8,7 @@ from datetime import datetime
from glob import glob from glob import glob
from django.db import models from django.db import models
from django.db.models import Max
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.conf import settings from django.conf import settings
from django.db.models.signals import pre_delete from django.db.models.signals import pre_delete
@ -114,9 +115,9 @@ class Text(models.Model):
self.status = value self.status = value
elif key == 'name': elif key == 'name':
data['name'] = re.sub(' \[\d+\]$', '', data['name']).strip() data['name'] = re.sub(' \[\d+\]$', '', data['name']).strip()
if not data['name']:
data['name'] = "Untitled"
name = data['name'] name = data['name']
if not name:
name = "Untitled"
num = 1 num = 1
while Text.objects.filter(name=name, user=self.user).exclude(id=self.id).count()>0: while Text.objects.filter(name=name, user=self.user).exclude(id=self.id).count()>0:
num += 1 num += 1
@ -128,7 +129,7 @@ class Text(models.Model):
self.text = ox.sanitize_html(data['text']) self.text = ox.sanitize_html(data['text'])
if 'position' in data: 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.position = data['position']
pos.section = 'featured' pos.section = 'featured'
if self.status == 'private': if self.status == 'private':

View file

@ -67,7 +67,7 @@ def addText(request):
pos.position = qs.aggregate(Max('position'))['position__max'] + 1 pos.position = qs.aggregate(Max('position'))['position__max'] + 1
pos.save() pos.save()
response = json_response(status=200, text='created') response = json_response(status=200, text='created')
response['data'] = text.json() response['data'] = text.json(user=request.user)
return render_to_json_response(response) return render_to_json_response(response)
actions.register(addText, cache=False) actions.register(addText, cache=False)
@ -97,7 +97,7 @@ def getText(request):
text = qs[0] text = qs[0]
else: else:
text = get_text_or_404_json(data['id']) 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) return render_to_json_response(response)
actions.register(getText) actions.register(getText)