Ejemplo n.º 1
0
def applications(name):
    """
    List user's project list.

    Returns a Jinja2 template with the list of projects of the user.

    """
    try:
        session = get_session(db, bind='slave')
        user = session.query(User).filter_by(name=name).first()
        if not user:
            return abort(404)
        if current_user.name != name:
            return abort(403)

        user = db.session.query(model.user.User).get(current_user.id)
        apps_published, apps_draft = _get_user_apps(user.id)
        apps_published.extend(cached_users.hidden_apps(user.id))

        return render_template('account/applications.html',
                               title=gettext("Projects"),
                               apps_published=apps_published,
                               apps_draft=apps_draft)
    except:  # pragma: no cover
        session.rollback()
        raise
    finally:
        session.close()
Ejemplo n.º 2
0
def applications(name):
    """
    List user's project list.

    Returns a Jinja2 template with the list of projects of the user.

    """
    try:
        session = get_session(db, bind='slave')
        user = session.query(User).filter_by(name=name).first()
        if not user:
            return abort(404)
        if current_user.name != name:
            return abort(403)

        user = db.session.query(model.user.User).get(current_user.id)
        apps_published, apps_draft = _get_user_apps(user.id)
        apps_published.extend(cached_users.hidden_apps(user.id))

        return render_template('account/applications.html',
                               title=gettext("Projects"),
                               apps_published=apps_published,
                               apps_draft=apps_draft)
    except: # pragma: no cover
        session.rollback()
        raise
    finally:
        session.close()
Ejemplo n.º 3
0
    def test_hidden_apps_no_projects(self):
        """Test CACHE USERS hidden_apps returns empty list if the user has
        not created any hidden project"""
        user = UserFactory.create()

        hidden_projects = cached_users.hidden_apps(user.id)

        assert hidden_projects == [], hidden_projects
Ejemplo n.º 4
0
    def test_hidden_apps_no_projects(self):
        """Test CACHE USERS hidden_apps returns empty list if the user has
        not created any hidden project"""
        user = UserFactory.create()

        hidden_projects = cached_users.hidden_apps(user.id)

        assert hidden_projects == [], hidden_projects
Ejemplo n.º 5
0
    def test_hidden_apps_only_returns_hidden(self):
        """Test CACHE USERS hidden_apps does not return draft (even hidden)
        or another user's hidden projects"""
        user = UserFactory.create()
        another_user_hidden_project = AppFactory.create(hidden=1)
        TaskFactory.create(app=another_user_hidden_project)
        hidden_draft_project = AppFactory.create(owner=user, hidden=1, info={})

        hidden_projects = cached_users.hidden_apps(user.id)

        assert len(hidden_projects) == 0, hidden_projects
Ejemplo n.º 6
0
    def test_hidden_apps_only_returns_hidden(self):
        """Test CACHE USERS hidden_apps does not return draft (even hidden)
        or another user's hidden projects"""
        user = UserFactory.create()
        another_user_hidden_project = AppFactory.create(hidden=1)
        TaskFactory.create(app=another_user_hidden_project)
        hidden_draft_project = AppFactory.create(owner=user, hidden=1, info={})

        hidden_projects = cached_users.hidden_apps(user.id)

        assert len(hidden_projects) == 0, hidden_projects
Ejemplo n.º 7
0
    def test_hidden_apps_returns_hidden(self):
        """Test CACHE USERS hidden_apps returns a list with the user projects that
        are no drafts but are hidden"""
        user = UserFactory.create()
        hidden_project = AppFactory.create(owner=user, hidden=1)
        TaskFactory.create(app=hidden_project)

        hidden_projects = cached_users.hidden_apps(user.id)

        assert len(hidden_projects) == 1, hidden_projects
        assert hidden_projects[0]['short_name'] == hidden_project.short_name, hidden_projects
Ejemplo n.º 8
0
    def test_hidden_apps_returns_hidden(self):
        """Test CACHE USERS hidden_apps returns a list with the user projects that
        are no drafts but are hidden"""
        user = UserFactory.create()
        hidden_project = AppFactory.create(owner=user, hidden=1)
        TaskFactory.create(app=hidden_project)

        hidden_projects = cached_users.hidden_apps(user.id)

        assert len(hidden_projects) == 1, hidden_projects
        assert hidden_projects[0][
            'short_name'] == hidden_project.short_name, hidden_projects
Ejemplo n.º 9
0
    def test_hidden_apps_returns_fields(self):
        """Test CACHE USERS hidden_apps returns the info of the projects with
        the required fields"""
        user = UserFactory.create()
        hidden_project = AppFactory.create(owner=user, hidden=1)
        TaskFactory.create(app=hidden_project)
        fields = ('id', 'name', 'short_name', 'owner_id', 'description', 'info')

        hidden_projects = cached_users.hidden_apps(user.id)

        for field in fields:
            assert field in hidden_projects[0].keys(), field
Ejemplo n.º 10
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)#,
Ejemplo n.º 11
0
    def test_hidden_apps_returns_fields(self):
        """Test CACHE USERS hidden_apps returns the info of the projects with
        the required fields"""
        user = UserFactory.create()
        hidden_project = AppFactory.create(owner=user, hidden=1)
        TaskFactory.create(app=hidden_project)
        fields = ('id', 'name', 'short_name', 'owner_id', 'description',
                  'overall_progress', 'n_tasks', 'n_volunteers', 'info')

        hidden_projects = cached_users.hidden_apps(user.id)

        for field in fields:
            assert field in hidden_projects[0].keys(), field
Ejemplo 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()
    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)  #,
Ejemplo n.º 13
0
def _show_public_profile(user):
    user_dict = cached_users.get_user_summary(user.name)
    apps_contributed = cached_users.apps_contributed_cached(user.id)
    apps_created = cached_users.published_apps_cached(user.id)
    if current_user.is_authenticated() and current_user.admin:
        apps_hidden = cached_users.hidden_apps(user.id)
        apps_created.extend(apps_hidden)
    if user_dict:
        title = "%s · User Profile" % user_dict['fullname']
        return render_template('/account/public_profile.html',
                               title=title,
                               user=user_dict,
                               apps=apps_contributed,
                               apps_created=apps_created)
Ejemplo n.º 14
0
def _show_public_profile(user):
    user_dict = cached_users.get_user_summary(user.name)
    apps_contributed = cached_users.apps_contributed_cached(user.id)
    apps_created = cached_users.published_apps_cached(user.id)
    if current_user.is_authenticated() and current_user.admin:
        apps_hidden = cached_users.hidden_apps(user.id)
        apps_created.extend(apps_hidden)
    if user_dict:
        title = "%s · User Profile" % user_dict['fullname']
        return render_template('/account/public_profile.html',
                               title=title,
                               user=user_dict,
                               apps=apps_contributed,
                               apps_created=apps_created)
Ejemplo n.º 15
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)
Ejemplo n.º 16
0
def applications(name):
    """
    List user's project list.

    Returns a Jinja2 template with the list of projects of the user.

    """
    user = user_repo.get_by_name(name)
    if not user:
        return abort(404)
    if current_user.name != name:
        return abort(403)

    user = user_repo.get(current_user.id)
    apps_published, apps_draft = _get_user_apps(user.id)
    apps_published.extend(cached_users.hidden_apps(user.id))

    return render_template('account/applications.html',
                           title=gettext("Projects"),
                           apps_published=apps_published,
                           apps_draft=apps_draft)
Ejemplo n.º 17
0
def applications(name):
    """
    List user's project list.

    Returns a Jinja2 template with the list of projects of the user.

    """
    user = user_repo.get_by_name(name)
    if not user:
        return abort(404)
    if current_user.name != name:
        return abort(403)

    user = user_repo.get(current_user.id)
    apps_published, apps_draft = _get_user_apps(user.id)
    apps_published.extend(cached_users.hidden_apps(user.id))

    return render_template('account/applications.html',
                           title=gettext("Projects"),
                           apps_published=apps_published,
                           apps_draft=apps_draft)
Ejemplo n.º 18
0
def applications(name):
    """
    List user's project list.

    Returns a Jinja2 template with the list of projects of the user.

    """
    user = db.slave_session.query(User).filter_by(name=name).first()
    if not user:
        return abort(404)
    if current_user.name != name:
        return abort(403)

    user = db.slave_session.query(model.user.User).get(current_user.id)
    apps_published, apps_draft = _get_user_apps(user.id)
    apps_published.extend(cached_users.hidden_apps(user.id))

    return render_template('account/applications.html',
                           title=gettext("Projects"),
                           apps_published=apps_published,
                           apps_draft=apps_draft)