コード例 #1
0
 def test_format_users_week(self):
     """Test format users week works."""
     TaskRunFactory.create()
     active_users_week()
     res = format_users_week()
     assert len(res['labels']) == 1
     day = datetime.utcnow().strftime('%Y-%m-%d')
     assert res['labels'][0] == day
     assert len(res['series']) == 1
     assert res['series'][0][0] == 1, res['series'][0][0]
コード例 #2
0
 def test_format_users_week_empty(self, db_mock):
     """Test format users week empty works."""
     db_mock.slave_session.execute.return_value = []
     AnonymousTaskRunFactory.create()
     active_users_week()
     res = format_users_week()
     assert len(res['labels']) == 1
     day = datetime.utcnow().strftime('%Y-%m-%d')
     assert res['labels'][0] == day
     assert len(res['series']) == 1
     assert res['series'][0][0] == 0, res['series'][0][0]
コード例 #3
0
ファイル: admin.py プロジェクト: fiorda/pybossa
def dashboard():
    """Show PYBOSSA Dashboard."""
    try:
        if request.args.get('refresh') == '1':
            db_jobs = get_dashboard_jobs()
            for j in db_jobs:
                DASHBOARD_QUEUE.enqueue(j['name'])
            msg = gettext('Dashboard jobs enqueued,'
                          ' refresh page in a few minutes')
            flash(msg)
        active_users_last_week = dashb.format_users_week()
        active_anon_last_week = dashb.format_anon_week()
        draft_projects_last_week = dashb.format_draft_projects()
        published_projects_last_week = dashb.format_published_projects()
        update_projects_last_week = dashb.format_update_projects()
        new_tasks_week = dashb.format_new_tasks()
        new_task_runs_week = dashb.format_new_task_runs()
        new_users_week = dashb.format_new_users()
        returning_users_week = dashb.format_returning_users()
        update_feed = get_update_feed()

        response = dict(
            template='admin/dashboard.html',
            title=gettext('Dashboard'),
            active_users_last_week=active_users_last_week,
            active_anon_last_week=active_anon_last_week,
            draft_projects_last_week=draft_projects_last_week,
            published_projects_last_week=published_projects_last_week,
            update_projects_last_week=update_projects_last_week,
            new_tasks_week=new_tasks_week,
            new_task_runs_week=new_task_runs_week,
            new_users_week=new_users_week,
            returning_users_week=returning_users_week,
            update_feed=update_feed,
            wait=False)
        return handle_content_type(response)
    except ProgrammingError as e:
        response = dict(template='admin/dashboard.html',
                        title=gettext('Dashboard'),
                        wait=True)
        return handle_content_type(response)
    except Exception as e:  # pragma: no cover
        current_app.logger.error(e)
        return abort(500)