def test_get_by_month(self): from pyvac.models import Request month = 8 year = 2011 country = u'fr' requests = Request.get_by_month(self.session, country, month, year) self.assertEqual(len(requests), 1)
def test_get_by_month(self): from pyvac.models import Request month = 8 year = 2011 country = u'fr' requests = Request.get_by_month(self.session, country, month, year) self.assertEqual(len(requests), 1)
def render(self): exported = {} if self.user.is_admin: requests = Request.get_by_month(self.session) data = [] header = '%s,%s,%s,%s,%s,%s' % ('#', 'user', 'from', 'to', 'number', 'type') data.append(header) for idx, req in enumerate(requests, start=1): data.append('%d,%s' % (idx, req.summarycsv)) exported = '\n'.join(data) return {u'exported': exported}
def render(self): exported = {} if self.user.is_admin: country = self.user.country month, year = self.request.params.get('month').split('/') requests = Request.get_by_month(self.session, country, int(month), int(year)) data = [] header = '%s,%s,%s,%s,%s,%s,%s' % ('#', 'lastname', 'firstname', 'from', 'to', 'number', 'type') data.append(header) for idx, req in enumerate(requests, start=1): data.append('%d,%s' % (idx, req.summarycsv)) exported = '\n'.join(data) return {u'exported': exported}
def render(self): exported = {} if self.user.is_admin: country = self.user.country month, year = self.request.params.get('month').split('/') sage_order = int(self.request.params.get('sage_order', 0)) log.info('exporting for: %d/%d' % (int(month), int(year))) all_reqs = Request.get_by_month(self.session, country, int(month), int(year), sage_order=sage_order) # filter request which overlap 2 months, only keep the ones which # are ending in the selected month requests = [] for req in all_reqs: if req.date_from.month != req.date_to.month: if req.date_to.month == int(month): log.info('using overlapping req: %r' % req.summary) requests.append(req) else: log.info('discarding overlapping req: %r' % req.summary) else: requests.append(req) data = [] header = ('%s,%s,%s,%s,%s,%s,%s,%s,%s,%s' % ('#', 'registration_number', 'lastname', 'firstname', 'from', 'to', 'number', 'type', 'label', 'message')) data.append(header) for idx, req in enumerate(requests, start=1): data.append('%d,%s' % (idx, req.summarycsv)) exported = '\n'.join(data) return {u'exported': exported}
def render(self): exported = {} if self.user.is_admin: country = self.user.country month, year = self.request.params.get('month').split('/') month = int(month) year = int(year) sage_order = int(self.request.params.get('sage_order', 0)) log.info('exporting for: %d/%d' % (int(month), int(year))) export_month = int(self.request.params.get('export_month', 0)) # noqa export_day = int(self.request.params.get('export_day', 0)) boundary_date = int(self.request.params.get('boundary_date', 0)) if export_day: last_month_date = datetime(year, month, boundary_date, 23, 59, 59) # noqa first_month_date = last_month_date - relativedelta(months=1) first_month_date = first_month_date.replace(day=boundary_date + 1, hour=0, minute=0, second=0, microsecond=0) log.info('exporting from %s -> %s' % (first_month_date, last_month_date)) all_reqs = Request.get_by_month( self.session, country, month, year, sage_order=sage_order, first_month_date=first_month_date, last_month_date=last_month_date) # filter requests which overlap the boundary date, only keep # the ones which are ending in the selected period requests = [] for req in all_reqs: if req.date_from < first_month_date <= req.date_to: log.info('using overlapping req: %r' % req.summary) requests.append(req) elif req.date_from <= last_month_date < req.date_to: log.info('discarding overlapping req: %r' % req.summary) else: requests.append(req) else: # assume it's export_month as it's a radio button choice all_reqs = Request.get_by_month(self.session, country, month, year, sage_order=sage_order) # filter request which overlap 2 months, only keep the ones # which are ending in the selected month requests = [] for req in all_reqs: if req.date_from.month != req.date_to.month: if req.date_to.month == int(month): log.info('using overlapping req: %r' % req.summary) requests.append(req) else: log.info('discarding overlapping req: %r' % req.summary) else: requests.append(req) data = [] header = ('%s,%s,%s,%s,%s,%s,%s,%s,%s,%s' % ('#', 'registration_number', 'lastname', 'firstname', 'from', 'to', 'number', 'type', 'label', 'message')) data.append(header) for idx, req in enumerate(requests, start=1): data.append('%d,%s' % (idx, req.summarycsv)) exported = '\n'.join(data) return {u'exported': exported}
def test_get_by_month(self): from pyvac.models import Request month = 3 requests = Request.get_by_month(self.session, month) self.assertEqual(len(requests), 2)