def _generate_seq(self, date, kinds, types, wards): date = time_to_normstr(date) latest = self.db.object_list.filterand(date=date, kinds=kinds, types=types, wards=wards).max('seq') return latest + 1 if latest else 1
def _generate_initial_object(self, date, kinds, types, wards, start_date, end_date, start_dt, end_dt, len_queryset): if set(types) <= type_reverbose.keys( ): # 쿼리 후의 컨텍스트는 한글로 되어있음, 일단 한글 types 를 vtypes 에 저장하고... vtypes = types types = list( map(type_reverbose.get, vtypes) ) # 슬러기 파이를 위해 다시 영어로 바꿔 줌(::IIS 에서 한글 주소 치면 하얀 화면만 나옴, IIS url에 한글 허용 X) else: vtypes = list(map(type_verbose.get, types)) vkinds = list(map(kind_verbose.get, kinds)) seq = self._generate_seq(date, kinds, types, wards) title = self._generate_title(date, kinds, types, seq, len_queryset) slug = self._generate_slug(date, kinds, types, wards, seq) timestamp = time_to_normstr(datetime.datetime.now(), to='datetime') context = { 'date': date, 'kinds': kinds, 'types': types, 'wards': wards, 'start_date': start_date, 'end_date': end_date, 'seq': seq, 'title': title, 'vtypes': vtypes, 'vkinds': vkinds, 'timestamp': timestamp, 'slug': slug, 'start_dt': start_dt, 'end_dt': end_dt } return context
def _today_last_dt(self, kinds): latest = self.collector.db.get_latest(date=self.TODAY, kinds=kinds, types=self.types, wards=self.wards) ret = latest.end_dt if latest else self.TODAY return time_to_normstr(ret, to='datetime')
def get_latest(self, **kwargs): latest = self.object_list for key, val in kwargs.items(): if key == 'date': date = time_to_normstr(val) latest = latest.filterand(date=date) elif key in ['types', 'kinds', 'wards']: latest = latest.filter(lambda row: set(row[key]) <= set(val)) latest = latest.top('seq') return latest
def set_form_initial(kinds, types, wards): fit = FormInitTime(types, wards) if kinds == ['LABEL']: initial = fit.label_init() elif kinds == ['NUT']: initial = fit.nut_init() elif kinds == ['INJ']: initial = fit.inj_init() else: initial = fit.get_default(kinds) initial['date'], initial['start_date'], initial[ 'end_date'] = time_to_normstr(initial['date'], initial['start_date'], initial['end_date']) initial['start_dt'], initial['end_dt'] = time_to_normstr( initial['start_dt'], initial['end_dt'], to='datetime') return json.dumps(initial)
def merge_object(self, *objects, commit=True): date = time_to_normstr(datetime.date.today()) timestamp = time_to_normstr(datetime.datetime.now(), to='datetime') concated = defaultdict(list) for object in objects: for key, val in object.items(): if key == 'queryset': concated[key] = Listorm(concated[key]) | Listorm(val) elif isinstance(val, list): concated[key] += val else: concated[key].append(val) merged = {} queryset = Listorm() for key, val in concated.items(): if key == 'kinds': merged[key] = sorted(set(val), key=lambda k: kind_order.get(k, k)) elif key == 'types': merged[key] = sorted(set(val), key=lambda t: type_order.get(t, t)) elif key == 'wards': merged[key] = sorted(set(val)) elif key in ['start_date', 'start_dt']: merged[key] = sorted(val)[0] elif key in ['end_date', 'end_dt']: merged[key] = sorted(val)[-1] elif key == 'queryset': queryset = val merged['len_queryset'] = len(val) elif key == 'date': merged[key] = date instance = self._generate_initial_object(**merged) instance['slug'] = instance['slug'] + "-MERGED" instance['title'] = instance['title'] + "(병합본)" instance['queryset'] = queryset self.db.save(instance, commit) return instance
def _generate_title(self, date, kinds, types, seq, count): types = '/'.join(map(lambda t: type_verbose.get(t, t), types)) kinds = '+'.join(map(lambda k: kind_verbose.get(k, k), kinds)) date = time_to_normstr(date) return "{} [{}]{}{}차({}건)".format(date, kinds, types, seq, count)
def _generate_slug(self, date, kinds, types, wards, seq): types = '-'.join(types) date = time_to_normstr(date) kinds = '-'.join(kinds) wards = '-'.join(wards) return "{}-{}-{}-{}-{}".format(types, date, kinds, wards, seq)