From dfd3b9881900d2e99374c66b8f4d19abf0d9b6f8 Mon Sep 17 00:00:00 2001 From: Leif Johansson Date: Fri, 13 May 2011 14:29:49 +0200 Subject: magical tag in order to support listing self-cleaning rooms --- src/meetingtools/apps/room/models.py | 18 +++++++++++++++++- src/meetingtools/apps/room/views.py | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'src/meetingtools/apps') diff --git a/src/meetingtools/apps/room/models.py b/src/meetingtools/apps/room/models.py index aea4ba3..26d2566 100644 --- a/src/meetingtools/apps/room/models.py +++ b/src/meetingtools/apps/room/models.py @@ -13,6 +13,8 @@ from meetingtools.apps.cluster.models import ACCluster import time import tagging from meetingtools.settings import BASE_URL +from django.db.models.signals import post_save +from tagging.models import Tag class Room(models.Model): creator = ForeignKey(User,editable=False) @@ -56,4 +58,18 @@ class Room(models.Model): else: return self.user_count -tagging.register(Room) \ No newline at end of file +tagging.register(Room) + +def _magic_tags(sender,**kwargs): + room = kwargs['instance'] + if room.self_cleaning: + Tag.objects.add_tag(room, "cleaning") + else: + tags = Tag.objects.get_for_object(room) + ntags = [] + for tag in tags: + if tag.name != "cleaning": + ntags.append(tag.name) + Tag.objects.update_tags(room, ntags) + +post_save.connect(_magic_tags,sender=Room) \ No newline at end of file diff --git a/src/meetingtools/apps/room/views.py b/src/meetingtools/apps/room/views.py index 3bbc74a..97a487c 100644 --- a/src/meetingtools/apps/room/views.py +++ b/src/meetingtools/apps/room/views.py @@ -409,7 +409,7 @@ def list_by_tag(request,tn): {'title':title,'description':title ,'edit':False,'baseurl': BASE_URL,'tags': tn,'rooms':rooms.all()}) def _can_tag(request,tag): - if tag in ('selfcleaning','public','private'): + if tag in ('selfcleaning','cleaning','public','private'): return False,"'%s' is reserved" % tag # XXX implement access model for tags here soon return True,"" -- cgit v1.1