def get_data(self, session, country): now = datetime.now() th_trial, th_good = self.trial_thresholds[country] ldap = LdapCache() arrivals = ldap.list_arrivals_country(country) matched = [] for user_dn, dt in list(arrivals.items()): if not dt: continue dt_trial_threshold = dt + relativedelta(months=th_trial) dt_good = dt + relativedelta(months=th_good) if (now > dt_trial_threshold) and not (now > dt_good): matched.append((user_dn, dt)) datas = [] for user_dn, dt in matched: user = User.by_dn(session, user_dn) if not user: self.log.info('user not found: %s' % user_dn) continue if user.country not in self.countries: continue data = {'user_id': user.id} param = json.dumps(OrderedDict(data)) rem = CoreReminder.by_type_param(session, 'trial_threshold', param) if not rem: data['duration'] = th_trial data['subject'] = self.subject datas.append(data) return datas
def get_chapter_stats(self, target_chapter, users_entity): # retrieve chapter members users_per_id = {} for user_dn, chapters in users_entity.iteritems(): if target_chapter not in chapters: continue user = User.by_dn(self.session, user_dn) users_per_id[user.id] = user return self.get_users_stats(users_per_id)