예제 #1
0
def index(request):
    chart_data = {
        'monthly': {
            'bugs': [],
            'features': [],
        },
        'daily': {
            'bugs': [],
            'features': [],
        },
    }

    one_year_ago = today() + relativedelta(months=-12)

    for i in range(12):
        one_year_ago = one_year_ago + relativedelta(months=+1)
        chart_data['monthly']['bugs'].append(
            get_model_count_for_date_range(
                BugWork, datetime_range(one_year_ago, 'month')))
        chart_data['monthly']['features'].append(
            get_model_count_for_date_range(
                FeatureWork, datetime_range(one_year_ago, 'month')))

    one_week_ago = today() + relativedelta(weeks=-1)

    for i in range(7):
        one_week_ago = one_week_ago + relativedelta(days=+1)
        chart_data['daily']['bugs'].append(
            get_model_count_for_date_range(BugWork,
                                           datetime_range(one_week_ago,
                                                          'day')))
        chart_data['daily']['features'].append(
            get_model_count_for_date_range(FeatureWork,
                                           datetime_range(one_week_ago,
                                                          'day')))

    bugs = Bug.objects.annotate(
        votecount=Count('bugvote')).order_by('-votecount')
    features = Feature.objects.annotate(
        votecount=Count('featurevote')).order_by('-votecount')
    mostvoted = {
        'bug': bugs[:1][0] if bugs.count() > 0 else [],
        'feature': features[:1][0] if features.count() > 0 else [],
    }
    return render(request, 'index.html', {
        'chart_data': json.dumps(chart_data),
        'mostvoted': mostvoted
    })
예제 #2
0
    def test_year_from_february(self):
        date = datetime.datetime(
            year=2019,
            month=2,
            day=17,
            hour=12,
            minute=25,
            second=45,
            microsecond=0
        )

        lower_date = date.replace(month=1, day=1, hour=0, minute=0, second=0, microsecond=0)
        upper_date = date.replace(month=12, day=31, hour=23, minute=59, second=59, microsecond=999999)

        self.assertEqual(
            datetime_range(date, 'year'),
            (
                self.tz.localize(lower_date),
                self.tz.localize(upper_date)
            )
        )
예제 #3
0
    def test_day(self):
        date = self.tz.localize(
            datetime.datetime(
                year=2019,
                month=7,
                day=17,
                hour=12,
                minute=25,
                second=45,
                microsecond=0
            )
        )

        lower_date = date.replace(hour=0, minute=0, second=0, microsecond=0)
        upper_date = date.replace(hour=23, minute=59, second=59, microsecond=999999)

        self.assertEqual(
            datetime_range(date, 'day'),
            (
                lower_date,
                upper_date
            )
        )