예제 #1
0
파일: models.py 프로젝트: WB-Solutions/lab
 def _onoff(dt, week, sources, suffix):
     day = _day(week, dt)
     # print '_onoff', dt, week, day
     ok = False
     if day:
         dtdate = dt.date()
         dttime = dt.time()
         intime = False
         for time in day.times.all():
             if dttime >= time.start and dttime <= time.end:
                 intime = True
                 break
         if intime:
             sources = utils.list_compact(sources) # remove None's.
             def _get(prefix, cmp2, checkdate):
                 xn = utils.list_flatten(sources, lambda e: getattr(e, prefix + suffix).all())
                 # print '_onoff._get', cmp2, xn
                 def _filter(e):
                     return cmp2 >= e.start and cmp2 <= e.end and (not e.date or e.date == dtdate if checkdate else True)
                 return utils.list_last(sorted(
                     [ e for e in xn if _filter(e) ],
                     key = lambda e: e.start,
                 ))
             def _ison(pt):
                 return not pt or pt.on
             operiod = _get('onoffperiod', dtdate, False)
             if _ison(operiod):
                 otime = _get('onofftime', dttime, True)
                 if _ison(otime):
                     ok = True
     # if not ok: print '_onoff - FAILED', dt
     return ok
예제 #2
0
파일: api.py 프로젝트: WB-Solutions/lab
 def get_queryset(self):
     qset = super(AbstractView, self).get_queryset()
     for name, deep in [ ('incats', True), ('cats', False) ]:
         cats = self.request.QUERY_PARAMS.get(name)
         if cats:
             model = qset.model # self.get_serializer().opts.model
             field = model._meta.get_field('cats')
             if field:
                 cats = utils.str_ints(cats)
                 if cats:
                     if deep:
                         target = field.related.parent_model
                         cats = utils.list_compact([ utils.db_get(target, cat) for cat in cats ])
                         cats = utils.tree_all_downs(cats)
                     qset = qset.filter(cats__in=cats)
                     # print 'get_queryset', self, type(qset), model, cats
     return qset