Beispiel #1
0
    def _merge_cached_exchange_collection(self, other, attr, keys=None, session_match=False):
        ex_attr = "_%s_ex" % attr
        if is_cached(other, ex_attr):
            setattr(self, ex_attr, getattr(other, ex_attr))
        if not is_cached(other, attr):
            return
        if not is_cached(self, attr):
            setattr(self, attr, getattr(other, attr))
            return

        if not isinstance(keys[0], tuple):
            keys = [(k,) for k in keys]

        this_list = getattr(self, attr)
        that_list = getattr(other, attr)
        this_set = set(this_list)
        that_set = set(that_list)

        that_dicts = {}
        for k in keys:
            that_dicts[k] = dict((mgetattr(item, k), item) for item in getattr(other, attr) if mgetattr(item, k, None))

        for this_item in this_list:
            that_item = None
            for k in keys:
                key_value = mgetattr(this_item, k, None)
                if key_value and that_dicts[k].has_key(key_value):
                    that_item = that_dicts[k][key_value]
                    break
            if that_item and that_item in that_set:
                this_item.merge(that_item)
                that_set.remove(that_item)
                this_set.remove(this_item)

        if session_match:
            for that_item in list(that_set):
                for this_item in list(this_set):
                    if this_item.overlaps(that_item):
                        this_item.merge(that_item)
                        that_set.remove(that_item)
                        this_set.remove(this_item)
                        break
            if len(that_set) == 1 and len(this_set) == 1:
                list(this_set)[0].merge(list(that_set)[0])
                that_set.clear()
            # else give up and just treat them all as different sessions
        this_list.extend(that_set)
        if session_match:
            for that in that_set:
                that.webinar = self

        setattr(self, attr, sort(this_list))
        return getattr(self, attr)
Beispiel #2
0
    def _merge_cached_exchange_collection(self, other, attr, keys=None, session_match=False):
        ex_attr = '_%s_ex'%attr
        if is_cached(other, ex_attr): setattr(self, ex_attr, getattr(other, ex_attr))
        if not is_cached(other, attr): 
            return
        if not is_cached(self, attr):
            setattr(self, attr, getattr(other, attr))
            return

        if not isinstance(keys[0], tuple): keys = [(k,) for k in keys]

        this_list = getattr(self, attr)
        that_list = getattr(other, attr)
        this_set = set(this_list)
        that_set = set(that_list)

        that_dicts = {}
        for k in keys:
            that_dicts[k] = dict((mgetattr(item,k),item) for item in getattr(other, attr) if mgetattr(item,k,None))

        for this_item in this_list:
            that_item = None
            for k in keys:
                key_value = mgetattr(this_item, k, None)
                if key_value and that_dicts[k].has_key(key_value):
                    that_item = that_dicts[k][key_value]
                    break
            if that_item and that_item in that_set:
                this_item.merge(that_item)
                that_set.remove(that_item)
                this_set.remove(this_item)

        if session_match:
            for that_item in list(that_set):
                for this_item in list(this_set):
                    if this_item.overlaps(that_item):
                        this_item.merge(that_item)
                        that_set.remove(that_item)
                        this_set.remove(this_item)
                        break;
            if len(that_set) == 1 and len(this_set) == 1:
                list(this_set)[0].merge(list(that_set)[0])
                that_set.clear()
            #else give up and just treat them all as different sessions
        this_list.extend(that_set)
        if session_match:
            for that in that_set: that.webinar = self

        setattr(self,attr,sort(this_list))
        return getattr(self,attr)
Beispiel #3
0
 def scope(self, **kwargs):
     for attr in ('sm','domains','all'):
         val = kwargs.get(attr,False)
         if is_cached(self,'_settings_ex') and getattr(self._settings_ex,attr) != val and val:
             self.refresh()
         setattr(self,attr,val)
     return self
Beispiel #4
0
 def __init__(self, organizer, **kwargs):
     super(Webinar, self).__init__()
     self.organizer = organizer
     self.key = mget(kwargs,'key','webinarKey')
     self.subject = mget(kwargs,'subject','name')
     self.description = kwargs.get('description')
     self.timezone = mget(kwargs, 'timezone', 'timeZone') or 'UTC'
     if kwargs.has_key('sessions'): self.sessions = kwargs['sessions']
     if kwargs.has_key('registrations'): self.registrations = kwargs['registrations']
     if kwargs.has_key('times') and not is_cached(self,'sessions'):
         extras = getdict(kwargs, 'scheduled','actual')
         self.sessions = [Session(webinar=self, **merge(span,extras)) for span in kwargs.get('times',[])]
Beispiel #5
0
 def __init__(self, organizer, **kwargs):
     super(Webinar, self).__init__()
     self.organizer = organizer
     self.key = mget(kwargs, 'key', 'webinarKey')
     self.subject = mget(kwargs, 'subject', 'name')
     self.description = kwargs.get('description')
     self.timezone = mget(kwargs, 'timezone', 'timeZone') or 'UTC'
     if kwargs.has_key('sessions'): self.sessions = kwargs['sessions']
     if kwargs.has_key('registrations'):
         self.registrations = kwargs['registrations']
     if kwargs.has_key('times') and not is_cached(self, 'sessions'):
         extras = getdict(kwargs, 'scheduled', 'actual')
         self.sessions = [
             Session(webinar=self, **merge(span, extras))
             for span in kwargs.get('times', [])
         ]
Beispiel #6
0
 def universal_key(self):
     if not self.webinar or not self.webinar.key or not is_cached(
             self.webinar, 'sessions') or self not in self.webinar.sessions:
         return None
     return "%s-%s" % (self.webinar.key,
                       self.webinar.sessions.index(self) + 1)
Beispiel #7
0
 def __delitem__(self, name):
     self.pending_deletes.add(name)
     self.pending_creates.pop(name,None)
     if is_cached(self,'_settings') and self._settings.get(name): del self._settings[name]
Beispiel #8
0
 def __setitem__(self, name, value): 
     setting = Setting(self, name=name, value=value)
     self.pending_creates[setting.name] = setting
     self.pending_deletes.discard(setting.name)
     if is_cached(self,'_settings'): self._settings[setting.name] = setting
Beispiel #9
0
 def universal_key(self):
     if not self.webinar or not self.webinar.key or not is_cached(self.webinar,'sessions') or self not in self.webinar.sessions: return None
     return "%s-%s" % (self.webinar.key, self.webinar.sessions.index(self)+1)