def expenses_details(request): data = request.data_manager period = request.session['expenses_period'] period = datetime.strptime(period[0:7], '%Y-%m') week_day, last_day = calendar.monthrange(period.year, period.month) from_date_dt = period to_date_dt = datetime(period.year, period.month, last_day) expenses = request.db.query(Expenses).filter( and_(Expenses.registry_date >= from_date_dt, Expenses.registry_date <= to_date_dt)) total = expenses.count() request.session['expenses_offset'] = request.session[ 'expenses_offset'] if request.session['expenses_offset'] < total else 0 expenses = expenses.order_by(desc('registry_date')).limit(LIMIT).offset( request.session['expenses_offset']) data['navbar_active'] = 'expenses' data['expenses'] = expenses data['offset'] = request.session['expenses_offset'] data['limit'] = LIMIT if LIMIT <= total else total + 1 data['total'] = total data['page'] = int((request.session['expenses_offset'] / LIMIT) + 1) data['pagination_ruler'] = pagination_ruler( LIMIT, total, request.session['expenses_offset']) data['total_pages'] = int((total / LIMIT) + 1) data['period'] = period data['offset_prefix'] = 'expenses' return data
def test_pagination_ruler_4(self): result = pagination_ruler(self.limit, self.total, 400) # ["page, current, offset, start_range, end_range"] expected = [(3, False, 200, 201, 300), (4, False, 300, 301, 400), (5, True, 400, 401, 500), (6, False, 500, 501, 600), (7, False, 600, 601, 700)] self.assertEqual(result, expected)
def test_pagination_ruler_6_bondary_upper_7(self): result = pagination_ruler(self.limit, self.total, 700) # ["page, current, offset, start_range, end_range"] expected = [(4, False, 300, 301, 400), (5, False, 400, 401, 500), (6, False, 500, 501, 600), (7, False, 600, 601, 700), (8, True, 700, 701, 721)] self.assertEqual(result, expected)
def test_pagination_ruler_3_bondary_bottom_2(self): result = pagination_ruler(self.limit, self.total, 0) # ["page, current, offset, start_range, end_range"] expected = [(1, True, 0, 1, 100), (2, False, 100, 101, 200), (3, False, 200, 201, 300), (4, False, 300, 301, 400), (5, False, 400, 401, 500)] self.assertEqual(result, expected)
def list_deposits(request): data = request.data_manager filter_pid_doi = request.GET.get('filter_pid_doi', None) to_date = request.session['filter_start_range'].split('-')[1].strip() to_date_dt = datetime.strptime( request.session['filter_start_range'].split('-')[1].strip(), '%m/%d/%Y') from_date = request.session['filter_start_range'].split('-')[0].strip() from_date_dt = datetime.strptime( request.session['filter_start_range'].split('-')[0].strip(), '%m/%d/%Y') total = 0 filter_string = [] if filter_pid_doi: filter_string.append('DOI/PID=%s' % filter_pid_doi) deposits = request.db.query(Deposit).filter( or_(Deposit.doi == filter_pid_doi, Deposit.pid == filter_pid_doi)) else: deposits = request.db.query(Deposit).filter( and_(Deposit.started_at >= from_date_dt, Deposit.started_at <= to_date_dt)) filter_string.append( 'processing_date between %s and %s' % (from_date_dt.isoformat()[:10], to_date_dt.isoformat()[:10])) if request.session['filter_feedback_status']: filter_string.append('feedback_status=%s' % request.session['filter_feedback_status']) deposits = deposits.filter(Deposit.feedback_status == request. session['filter_feedback_status']) if request.session['filter_submission_status']: filter_string.append('submission_status=%s' % request.session['filter_submission_status']) deposits = deposits.filter(Deposit.submission_status == request. session['filter_submission_status']) if request.session['filter_issn']: filter_string.append('issn=%s' % request.session['filter_issn']) deposits = deposits.filter( Deposit.issn == request.session['filter_issn']) if request.session['filter_prefix']: filter_string.append('prefix=%s' % request.session['filter_prefix']) deposits = deposits.filter( Deposit.prefix == request.session['filter_prefix']) if request.session['filter_journal_acronym']: filter_string.append('journal_acronym=%s' % request.session['filter_journal_acronym']) deposits = deposits.filter(Deposit.journal_acronym == request. session['filter_journal_acronym']) if request.session['filter_has_valid_references']: filter_string.append( 'has_valid_references=%s' % request.session['filter_has_valid_references']) deposits = deposits.filter( Deposit.has_submission_xml_valid_references == request.session['filter_has_valid_references']) total = deposits.count() request.session['deposits_offset'] = request.session[ 'deposits_offset'] if request.session['deposits_offset'] < total else 0 deposits = deposits.order_by(desc('started_at')).limit(LIMIT).offset( request.session['deposits_offset']) data['deposits'] = deposits data[ 'submission_status_to_template'] = template_choices.SUBMISSION_STATUS_TO_TEMPLATE data[ 'feedback_status_to_template'] = template_choices.FEEDBACK_STATUS_TO_TEMPLATE data['filter_from_date'] = from_date data['filter_to_date'] = to_date data['filter_feedback_status'] = request.session['filter_feedback_status'] data['filter_has_valid_references'] = request.session[ 'filter_has_valid_references'] data['filter_journal_acronym'] = request.session['filter_journal_acronym'] data['filter_submission_status'] = request.session[ 'filter_submission_status'] data['filter_issn'] = request.session['filter_issn'] data['filter_prefix'] = request.session['filter_prefix'] data['filter_string'] = filter_string data['offset'] = request.session['deposits_offset'] data['limit'] = LIMIT if LIMIT <= total else total + 1 data['total'] = total data['page'] = int((request.session['deposits_offset'] / LIMIT) + 1) data['pagination_ruler'] = pagination_ruler( LIMIT, total, request.session['deposits_offset']) data['total_pages'] = int((total / LIMIT) + 1) data['navbar_active'] = 'deposits' data['offset_prefix'] = 'deposits' return data