Exemplo n.º 1
0
def _show_own_profile(user, form, can_update):
    user_dict = cached_users.get_user_summary(user.name)
    rank_and_score = cached_users.rank_and_score(user.id)
    user.rank = rank_and_score['rank']
    user.score = rank_and_score['score']
    user.total = cached_users.get_total_users()
    projects_contributed = cached_users.public_projects_contributed_cached(
        user.id)
    projects_published, projects_draft = _get_user_projects(user.id)
    cached_users.get_user_summary(user.name)

    response = dict(template='account/profile.html',
                    title=gettext("Profile"),
                    projects_contrib=projects_contributed,
                    projects_published=projects_published,
                    projects_draft=projects_draft,
                    user=user_dict,
                    form=form,
                    can_update=can_update,
                    private_instance=bool(data_access_levels),
                    upref_mdata_enabled=bool(app_settings.upref_mdata))

    response = make_response(handle_content_type(response))
    response.headers['Cache-Control'] = 'no-store'
    response.headers['Pragma'] = 'no-cache'
    return response
Exemplo n.º 2
0
    def test_rank_and_score(self):
        """Test CACHE USERS rank_and_score returns the correct rank and score"""
        i = 0
        project = ProjectFactory.create()
        tasks = TaskFactory.create_batch(4, project=project)
        users = UserFactory.create_batch(4)
        for user in users:
            i += 1
            taskruns = TaskRunFactory.create_batch(i, user=user, task=tasks[i - 1])

        first_in_rank = cached_users.rank_and_score(users[3].id)
        last_in_rank = cached_users.rank_and_score(users[0].id)
        print first_in_rank
        assert first_in_rank['rank'] == 1, first_in_rank['rank']
        assert first_in_rank['score'] == 4, first_in_rank['score']
        assert last_in_rank['rank'] == 4, last_in_rank['rank']
        assert last_in_rank['score'] == 1, last_in_rank['score']
Exemplo n.º 3
0
    def test_rank_and_score(self):
        """Test CACHE USERS rank_and_score returns the correct rank and score"""
        i = 0
        project = ProjectFactory.create()
        tasks = TaskFactory.create_batch(4, project=project)
        users = UserFactory.create_batch(4)
        for user in users:
            i += 1
            taskruns = TaskRunFactory.create_batch(i, user=user, task=tasks[i-1])

        first_in_rank = cached_users.rank_and_score(users[3].id)
        last_in_rank = cached_users.rank_and_score(users[0].id)
        print first_in_rank
        assert first_in_rank['rank'] == 1, first_in_rank['rank']
        assert first_in_rank['score'] == 4, first_in_rank['score']
        assert last_in_rank['rank'] == 4, last_in_rank['rank']
        assert last_in_rank['score'] == 1, last_in_rank['score']
Exemplo n.º 4
0
def _show_own_profile(user):
    rank_and_score = cached_users.rank_and_score(user.id)
    user.rank = rank_and_score['rank']
    user.score = rank_and_score['score']
    user.total = cached_users.get_total_users()
    apps_contrib = cached_users.apps_contributed(user.id)
    apps_published, apps_draft = _get_user_apps(user.id)
    apps_published.extend(cached_users.hidden_apps(user.id))

    return render_template('account/profile.html', title=gettext("Profile"),
                          apps_contrib=apps_contrib,
                          apps_published=apps_published,
                          apps_draft=apps_draft)#,
Exemplo n.º 5
0
def _show_own_profile(user):
    rank_and_score = cached_users.rank_and_score(user.id)
    user.rank = rank_and_score['rank']
    user.score = rank_and_score['score']
    user.total = cached_users.get_total_users()
    projects_contributed = cached_users.projects_contributed_cached(user.id)
    projects_published, projects_draft = _get_user_projects(user.id)
    cached_users.get_user_summary(user.name)

    return render_template('account/profile.html', title=gettext("Profile"),
                           projects_contrib=projects_contributed,
                           projects_published=projects_published,
                           projects_draft=projects_draft,
                           user=user)
Exemplo n.º 6
0
def render_survey():
    """ Renders appropriate survey for current user or redirects to home page if surveys are not applicable """
    if not current_user.is_anonymous():
        rank_and_score = cached_users.rank_and_score(current_user.id)
        survey_type = "INITIAL"
        if rank_and_score['score'] > current_app.config['GEOTAGX_FINAL_SURVEY_TASK_REQUIREMENTS'] and "geotagx_survey_status" in current_user.info.keys() and current_user.info['geotagx_survey_status'] == "AGREE_TO_PARTICIPATE" :
            survey_type = "FINAL"

        if "geotagx_survey_status" in current_user.info.keys() and current_user.info['geotagx_survey_status'] in ["DENY_TO_PARTICIPATE", "DENY_TO_PARTICIPATE_IN_FINAL_SURVEY", "ALL_SURVEYS_COMPLETE"]:
            survey_type = "NONE"

        return render_template('/geotagx/surveys/surveys.html', survey_type = survey_type, GEOTAGX_FINAL_SURVEY_TASK_REQUIREMENTS = current_app.config['GEOTAGX_FINAL_SURVEY_TASK_REQUIREMENTS'])
    else:
        return redirect(url_for('home.home'))
Exemplo n.º 7
0
def _show_own_profile(user):
    rank_and_score = cached_users.rank_and_score(user.id)
    user.rank = rank_and_score['rank']
    user.score = rank_and_score['score']
    user.total = cached_users.get_total_users()
    projects_contributed = cached_users.projects_contributed_cached(user.id)
    projects_published, projects_draft = _get_user_projects(user.id)
    cached_users.get_user_summary(user.name)

    return render_template('account/profile.html', title=gettext("Profile"),
                           projects_contrib=projects_contributed,
                           projects_published=projects_published,
                           projects_draft=projects_draft,
                           user=user)
Exemplo n.º 8
0
def _show_own_profile(user):
    rank_and_score = cached_users.rank_and_score(user.id)
    user.rank = rank_and_score['rank']
    user.score = rank_and_score['score']
    user.total = cached_users.get_total_users()
    apps_contrib = cached_users.apps_contributed(user.id)
    apps_published, apps_draft = _get_user_apps(user.id)
    apps_published.extend(cached_users.hidden_apps(user.id))

    return render_template('account/profile.html',
                           title=gettext("Profile"),
                           apps_contrib=apps_contrib,
                           apps_published=apps_published,
                           apps_draft=apps_draft)  #,
Exemplo n.º 9
0
def get_geotagx_survey_status():
    """ Get geotagx survey status  """
    """ Used by client side javascript code to determine rendering of the different surveys """
    if not current_user.is_anonymous():
        result = {}
        if "geotagx_survey_status" in current_user.info.keys():
            rank_and_score = cached_users.rank_and_score(current_user.id)
            result['geotagx_survey_status'] = current_user.info['geotagx_survey_status']
            result['task_runs'] = rank_and_score['score']
            result['final_survey_task_requirements'] = current_app.config['GEOTAGX_FINAL_SURVEY_TASK_REQUIREMENTS']
        else:
            result['geotagx_survey_status'] = "RESPONSE_NOT_TAKEN"

        return jsonify(result)
    else:
        return jsonify({'result':' -_- STOP SNOOPING AROUND -_- '})
Exemplo n.º 10
0
def _show_own_profile(user):
    user_dict = cached_users.get_user_summary(user.name)
    rank_and_score = cached_users.rank_and_score(user.id)
    user.rank = rank_and_score['rank']
    user.score = rank_and_score['score']
    user.total = cached_users.get_total_users()
    projects_contributed = cached_users.public_projects_contributed_cached(user.id)
    projects_published, projects_draft = _get_user_projects(user.id)
    cached_users.get_user_summary(user.name)

    response = dict(template='account/profile.html', title=gettext("Profile"),
                    projects_contrib=projects_contributed,
                    projects_published=projects_published,
                    projects_draft=projects_draft,
                    user=user_dict)

    return handle_content_type(response)
Exemplo n.º 11
0
def _show_own_profile(user):
    user_dict = cached_users.get_user_summary(user.name)
    rank_and_score = cached_users.rank_and_score(user.id)
    user.rank = rank_and_score['rank']
    user.score = rank_and_score['score']
    user.total = cached_users.get_total_users()
    projects_contributed = cached_users.public_projects_contributed_cached(user.id)
    projects_published, projects_draft = _get_user_projects(user.id)
    cached_users.get_user_summary(user.name)

    response = dict(template='account/profile.html', title=gettext("Profile"),
                    projects_contrib=projects_contributed,
                    projects_published=projects_published,
                    projects_draft=projects_draft,
                    user=user_dict)

    return handle_content_type(response)
Exemplo n.º 12
0
def _show_own_profile(user):
    rank_and_score = cached_users.rank_and_score(user.id)
    user.rank = rank_and_score['rank']
    user.score = rank_and_score['score']
    user.total = cached_users.get_total_users()
    user.valid_email = user.valid_email
    user.confirmation_email_sent = user.confirmation_email_sent
    apps_contributed = cached_users.apps_contributed_cached(user.id)
    apps_published, apps_draft = _get_user_apps(user.id)
    apps_published.extend(cached_users.hidden_apps(user.id))
    cached_users.get_user_summary(user.name)

    return render_template('account/profile.html',
                           title=gettext("Profile"),
                           apps_contrib=apps_contributed,
                           apps_published=apps_published,
                           apps_draft=apps_draft,
                           user=user)
Exemplo n.º 13
0
def home():
    """Render home page with the cached projects and users."""
    page = 1
    per_page = current_app.config.get('APPS_PER_PAGE', 5)

    # Add featured
    tmp_projects = cached_projects.get_featured('featured', page, per_page)
    if len(tmp_projects) > 0:
        data = dict(featured=rank(tmp_projects))
    else:
        data = dict(featured=[])
    # Add historical contributions
    historical_projects = []
    if current_user.is_authenticated:
        user_id = current_user.id
        historical_projects = cached_users.projects_contributed(user_id, order_by='last_contribution')[:3]
        data['historical_contributions'] = historical_projects
        rank_and_score = cached_users.rank_and_score(user_id)
        current_user.rank = rank_and_score['rank']
    response = dict(template='/home/index.html', **data)
    #return handle_content_type(response)
    return redirect('/project/category/mkplaygames', code=302)
Exemplo n.º 14
0
def index(window=0):
    """Get the last activity from users and projects."""
    if current_user.is_authenticated:
        user_id = current_user.id
        rank_and_score = cached_users.rank_and_score(user_id)
        current_user.rank = rank_and_score['rank']
    else:
        user_id = None

    if window >= 10:
        window = 10

    info = request.args.get('info')

    leaderboards = current_app.config.get('LEADERBOARDS')

    if info is not None:
        if leaderboards is None or info not in leaderboards:
            return abort(404)
        underscore = info.find("_")
        answer = info[underscore + 1:]
        dept = info[:underscore]
        if (current_user.info is None or current_user.info['container'] is None
                or current_user.info['container'].get(dept) is None
                or current_user.info['container'][dept] != answer):
            return abort(401)

    top_users = cached_users.get_leaderboard(current_app.config['LEADERBOARD'],
                                             user_id=user_id,
                                             window=window,
                                             info=info)

    response = dict(template='/stats/index.html',
                    title="Community Leaderboard",
                    top_users=top_users)
    return handle_content_type(response)