Пример #1
0
 def __init__(self, **kwargs):
     super(Registrant, self).__init__()
     self.webinar = kwargs.get('webinar')
     self.session = kwargs.get('session')
     self.key = mget(kwargs, 'key', 'registrant_key', 'registrantKey')
     self.email = nlower(mget(kwargs, 'email', 'attendeeEmail'))
     self.first_name = mget(kwargs, 'first_name', 'firstName', 'first')
     self.last_name = mget(kwargs, 'last_name', 'lastName', 'last')
     if kwargs.get('name'): self.name = nstrip(kwargs.get('name'))
     self.registered_at = ntime(
         mget(kwargs, 'registered_at', 'registrationDate'))
     self.join_url = mget(kwargs, 'join_url', 'joinUrl')
     self.status = kwargs.get('status')
     self.viewings = kwargs.get('viewings', [])
     if not self.viewings and kwargs.get('attendance'):
         self.viewings = sort([(time(d['joinTime']), time(d['leaveTime']))
                               for d in kwargs['attendance']])
     if not self.viewings and (
             kwargs.get('duration') or kwargs.get('attendanceTimeInSeconds')
     ) and self.session and self.session.key and self.session.started_at:
         duration = kwargs.get(
             'duration') or kwargs.get('attendanceTimeInSeconds') and delta(
                 s=kwargs['attendanceTimeInSeconds'])
         self.viewings = [(self.session.started_at,
                           self.session.started_at + duration)]
Пример #2
0
 def webinars(self):
     webinars = {}
     for ex in Exchange.async_exchange([self._future_ex, self._past_ex, self._sessioned_ex]):
         for that in ex.result:
             this = webinars.get(that.key)
             if this: this.merge(that)
             else: webinars[that.key] = that
     return sort(webinars.values())
Пример #3
0
 def merge(self, other):
     self._merge_primitives(other, 'webinar', 'session', 'key', 'email', 'first_name', 'last_name', 'registered_at', 'join_url', 'status')
     viewings = []
     for v in sort(self.viewings + other.viewings):
         if viewings:
             last = viewings[-1]
             if v[0]<=last[-1]:
                 viewings[-1] = (min(v[0],last[0]),max(v[-1],last[-1]))
                 continue
         viewings.append(v)
     self.viewings = viewings
     return self
Пример #4
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)
Пример #5
0
 def merge(self, other):
     self._merge_primitives(other, 'webinar', 'session', 'key', 'email',
                            'first_name', 'last_name', 'registered_at',
                            'join_url', 'status')
     viewings = []
     for v in sort(self.viewings + other.viewings):
         if viewings:
             last = viewings[-1]
             if v[0] <= last[-1]:
                 viewings[-1] = (min(v[0], last[0]), max(v[-1], last[-1]))
                 continue
         viewings.append(v)
     self.viewings = viewings
     return self
Пример #6
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)
Пример #7
0
 def __init__(self, **kwargs):
     super(Registrant, self).__init__()
     self.webinar = kwargs.get('webinar')
     self.session = kwargs.get('session')
     self.key = mget(kwargs, 'key', 'registrant_key', 'registrantKey')
     self.email = nlower(mget(kwargs, 'email', 'attendeeEmail'))
     self.first_name = mget(kwargs, 'first_name', 'firstName', 'first')
     self.last_name = mget(kwargs, 'last_name', 'lastName', 'last')
     if kwargs.get('name'): self.name = nstrip(kwargs.get('name'))
     self.registered_at = ntime(mget(kwargs, 'registered_at', 'registrationDate'))
     self.join_url = mget(kwargs, 'join_url', 'joinUrl')
     self.status = kwargs.get('status')
     self.viewings = kwargs.get('viewings',[])
     if not self.viewings and kwargs.get('attendance'):
         self.viewings = sort([(time(d['joinTime']),time(d['leaveTime'])) for d in kwargs['attendance']])
     if not self.viewings and (kwargs.get('duration') or kwargs.get('attendanceTimeInSeconds')) and self.session and self.session.key and self.session.started_at:
         duration = kwargs.get('duration') or kwargs.get('attendanceTimeInSeconds') and delta(s=kwargs['attendanceTimeInSeconds'])
         self.viewings = [(self.session.started_at, self.session.started_at+duration)]
Пример #8
0
 def process_data(self, data, response):
     return sort([
         Registrant(session=self.session,
                    webinar=self.session.webinar,
                    **kwargs) for kwargs in data
     ])
Пример #9
0
 def process_data(self, data, response): 
     return sort([Registrant(session=self.session,webinar=self.session.webinar,**kwargs) for kwargs in data])