[snowy] Use a pre-save signal handler to set is_notebook
- From: Brad Taylor <btaylor src gnome org>
- To: svn-commits-list gnome org
- Subject: [snowy] Use a pre-save signal handler to set is_notebook
- Date: Tue, 19 May 2009 13:52:24 -0400 (EDT)
commit 2b25a12bb2e57e6b2fe3ac672b8f100848c7ca8d
Author: Brad Taylor <brad getcoded net>
Date: Tue May 19 13:51:57 2009 -0400
Use a pre-save signal handler to set is_notebook
---
api/handlers.py | 8 ++------
notes/models.py | 13 +++++++++++--
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/api/handlers.py b/api/handlers.py
index aacdde3..38c12c7 100644
--- a/api/handlers.py
+++ b/api/handlers.py
@@ -137,16 +137,12 @@ class NotesHandler(BaseHandler):
if c.has_key('open-on-startup'): note.open_on_startup = (c['open-on-startup'] == True)
if c.has_key('tags'):
note.tags.clear()
- for tagName in c['tags']:
- is_notebook = tagName.startswith('system:notebook:')
+ for tag_name in c['tags']:
tag, created = NoteTag.objects.get_or_create(author=user,
- name=tagName,
- is_notebook=is_notebook)
+ name=tag_name)
note.tags.add(tag)
note.last_sync_rev = new_sync_rev
-
- # TODO: tags
note.save()
profile = user.get_profile()
diff --git a/notes/models.py b/notes/models.py
index 44d747a..2276b60 100644
--- a/notes/models.py
+++ b/notes/models.py
@@ -15,9 +15,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-from django.db import models
+from django.db.models.signals import post_save, pre_save
from django.contrib.auth.models import User
-from django.db.models.signals import post_save
+from django.db import models
from autoslug.fields import AutoSlugField
@@ -86,6 +86,15 @@ class NoteTag(models.Model):
return self.name.split(':', 2)[-1]
return self.name
+def _update_is_notebook(sender, instance, **kwargs):
+ """
+ Update is_notebook based upon the NoteTag name.
+ """
+ instance.is_notebook = instance.name.startswith('system:notebook:')
+
+pre_save.connect(_update_is_notebook, sender=NoteTag,
+ dispatch_uid='snowy.notes.models.NoteTag')
+
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]