summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeif Johansson <leifj@sunet.se>2012-10-31 21:30:58 +0100
committerLeif Johansson <leifj@sunet.se>2012-10-31 21:30:58 +0100
commit20b3f0b2cd843803ab819b9a58eba2c419b3541a (patch)
treea2e5799bb9f54e70e51e2bb3355c3dda3bfada15
parent09b5b8ddcf892eb689f32a271fba11e142e82441 (diff)
filter on clusters
-rw-r--r--meetingtools/apps/room/management/commands/import_rooms.py10
-rw-r--r--meetingtools/apps/room/tasks.py21
-rw-r--r--meetingtools/apps/stats/management/commands/import_sessions.py10
3 files changed, 29 insertions, 12 deletions
diff --git a/meetingtools/apps/room/management/commands/import_rooms.py b/meetingtools/apps/room/management/commands/import_rooms.py
index abdc696..d5421e3 100644
--- a/meetingtools/apps/room/management/commands/import_rooms.py
+++ b/meetingtools/apps/room/management/commands/import_rooms.py
@@ -13,8 +13,16 @@ class Command(BaseCommand):
dest='since',
default=0,
help='Import all rooms modified <since> seconds ago'),
+ make_option('--cluster',
+ type='int',
+ dest='cluster',
+ default=0,
+ help='Import rooms from cluster <cluster> (id)'),
)
def handle(self, *args, **options):
- for acc in ACCluster.objects.all():
+ qs = ACCluster.objects
+ if options['cluster'] > 0:
+ qs = qs.filter(pk=options['cluster'])
+ for acc in qs.all():
import_acc(acc,since=options['since']) \ No newline at end of file
diff --git a/meetingtools/apps/room/tasks.py b/meetingtools/apps/room/tasks.py
index 0949d48..1e3e376 100644
--- a/meetingtools/apps/room/tasks.py
+++ b/meetingtools/apps/room/tasks.py
@@ -21,12 +21,13 @@ from django.contrib.humanize.templatetags import humanize
from django.conf import settings
from django.core.mail import send_mail
-def _owner_username(api,sco):
+def _owner_username(api,acc,sco):
logging.debug(sco)
- key = '_sco_owner_%s' % sco.get('sco-id')
+ key = 'ac:owner:%s/%s' % (acc,sco.get('sco-id'))
logging.debug(key)
try:
- if cache.get(key) is None:
+ name = cache.get(key)
+ if name is None:
fid = sco.get('folder-id')
if not fid:
logging.debug("No folder-id")
@@ -40,26 +41,26 @@ def _owner_username(api,sco):
parent = r.et.xpath("//sco")[0]
logging.debug("p %s",repr(parent))
logging.debug("r %s",etree.tostring(parent))
- name = None
if parent:
logging.debug("parent: %s" % parent)
if parent.findtext('name') == 'User Meetings':
name = sco.findtext('name')
else:
name = _owner_username(api,parent)
+
+ if name is not None:
+ cache.set(key,name,30)
- cache.set(key,name)
-
- return cache.get(key)
+ return name
except Exception,e:
logging.debug(e)
return None
-def _extended_info(api,sco_id):
+def _extended_info(api,acc,sco_id):
r = api.request('sco-info',{'sco-id':sco_id},False)
if r.status_code == 'no-data':
return None
- return r.et,_owner_username(api,r.et.xpath('//sco')[0])
+ return r.et,_owner_username(api,acc,r.et.xpath('//sco')[0])
def _import_one_room(acc,api,row):
sco_id = int(row.get('sco-id'))
@@ -93,7 +94,7 @@ def _import_one_room(acc,api,row):
#logging.debug("last %s" % last)
#logging.debug("lastupdated %s" % lastupdated)
if not room or lastupdated < last:
- (r,username) = _extended_info(api, sco_id)
+ (r,username) = _extended_info(api, acc, sco_id)
logging.debug("found room owned by %s. Time for an update" % username)
if username is None:
logging.warning("username not found for sco-id=%s while importing" % sco_id)
diff --git a/meetingtools/apps/stats/management/commands/import_sessions.py b/meetingtools/apps/stats/management/commands/import_sessions.py
index d98b081..d48c5d0 100644
--- a/meetingtools/apps/stats/management/commands/import_sessions.py
+++ b/meetingtools/apps/stats/management/commands/import_sessions.py
@@ -13,8 +13,16 @@ class Command(BaseCommand):
dest='since',
default=0,
help='Import all sessions <since> seconds ago'),
+ make_option('--cluster',
+ type='int',
+ dest='cluster',
+ default=0,
+ help='Import rooms from cluster <cluster> (id)'),
)
def handle(self, *args, **options):
- for acc in ACCluster.objects.all():
+ qs = ACCluster.objects
+ if options['cluster'] > 0:
+ qs = qs.filter(pk=options['cluster'])
+ for acc in qs.all():
import_acc_sessions(acc,since=options['since']) \ No newline at end of file