summaryrefslogtreecommitdiff
path: root/src/meetingtools/apps/room
diff options
context:
space:
mode:
authorLeif Johansson <leifj@sunet.se>2011-10-13 14:33:54 +0200
committerLeif Johansson <leifj@sunet.se>2011-10-13 14:33:54 +0200
commit81e609a599afa68a05f65cae708f4b11e0f329c2 (patch)
treef95e77efcd5938bdf8db21137b2ed0ef9bea01f0 /src/meetingtools/apps/room
parent88cd7db6af59c479993df74b3721c2a55a554025 (diff)
- lock rooms when cleaning
- send access to retry page when room locked - fall back to regular login-page if user-login fails
Diffstat (limited to 'src/meetingtools/apps/room')
-rw-r--r--src/meetingtools/apps/room/models.py34
-rw-r--r--src/meetingtools/apps/room/views.py19
2 files changed, 46 insertions, 7 deletions
diff --git a/src/meetingtools/apps/room/models.py b/src/meetingtools/apps/room/models.py
index 3190052..a85eba0 100644
--- a/src/meetingtools/apps/room/models.py
+++ b/src/meetingtools/apps/room/models.py
@@ -12,9 +12,28 @@ from django.contrib.auth.models import User
from meetingtools.apps.cluster.models import ACCluster
import time
import tagging
-from meetingtools.settings import BASE_URL
+from meetingtools.settings import BASE_URL, LOCK_DIR
from django.db.models.signals import post_save
from tagging.models import Tag
+import os
+
+class FileLock(object):
+
+ def __init__(self,obj):
+ self.obj = obj
+
+ def __get__(self):
+ return os.access(LOCK_DIR+os.sep+self.obj.__class__+"_"+self.obj.id+".lock",os.F_OK)
+ def __set__(self,value):
+ if not isinstance(value,bool):
+ raise AttributeError
+ if value:
+ f = open(LOCK_DIR+os.sep+self.obj.__class__+"_"+self.obj.id+".lock")
+ f.close()
+ else:
+ os.remove(LOCK_DIR+os.sep+self.obj.__class__+"_"+self.obj.id+".lock")
+ def __delete__(self):
+ raise AttributeError
class Room(models.Model):
creator = ForeignKey(User,editable=False)
@@ -39,6 +58,19 @@ class Room(models.Model):
def __unicode__(self):
return "%s (sco_id=%s,source_sco_id=%s,folder_sco_id=%s,urlpath=%s)" % (self.name,self.sco_id,self.source_sco_id,self.folder_sco_id,self.urlpath)
+ def _lockf(self):
+ return LOCK_DIR+os.sep+"room-"+self.id+".lock"
+
+ def lock(self):
+ f = open(self._lockf())
+ f.close()
+
+ def unlock(self):
+ os.remove(self._lockf())
+
+ def is_locked(self):
+ os.access(self._lockf(),os.F_OK)
+
def lastvisit(self):
if not self.lastvisited:
return 0
diff --git a/src/meetingtools/apps/room/views.py b/src/meetingtools/apps/room/views.py
index e490aa2..f4da0df 100644
--- a/src/meetingtools/apps/room/views.py
+++ b/src/meetingtools/apps/room/views.py
@@ -362,6 +362,9 @@ def _random_key(length=20):
return str().join(rg.choice(alphabet) for _ in range(length))
def _goto(request,room,clean=True,promote=False):
+ if room.is_locked():
+ return respond_to(request, {"text/html": "apps/room/retry.html"}, {'room': room, 'wait': 10})
+
api = ac_api_client(request, room.acc)
now = time.time()
lastvisit = room.lastvisit()
@@ -381,10 +384,12 @@ def _goto(request,room,clean=True,promote=False):
room.save()
if room.self_cleaning:
if (room.user_count == 0) and (abs(lastvisit - now) > GRACE):
+ room.lock()
room = _clean(request,room)
+ room.unlock()
- if room.host_count == 0 and room.allow_host:
- return respond_to(request, {"text/html": "apps/room/launch.html"}, {'room': room})
+ if room.host_count == 0 and room.allow_host:
+ return respond_to(request, {"text/html": "apps/room/launch.html"}, {'room': room})
else:
room.save()
@@ -401,10 +406,12 @@ def _goto(request,room,clean=True,promote=False):
r = api.request('sco-info',{'sco-id':room.sco_id},True)
urlpath = r.et.findtext('.//sco/url-path')
if key:
- user_client = ACPClient(room.acc.api_url, request.user.username, key, cache=False)
- return user_client.redirect_to(room.acc.url+urlpath)
- else:
- return HttpResponseRedirect(room.acc.url+urlpath)
+ try:
+ user_client = ACPClient(room.acc.api_url, request.user.username, key, cache=False)
+ return user_client.redirect_to(room.acc.url+urlpath)
+ except Exception,e:
+ pass
+ return HttpResponseRedirect(room.acc.url+urlpath)
## Tagging