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 = [] projects = project_repo.get_all() data['projects'] = [] for project in projects: if project.published == True: data['projects'].append(project) 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 response = dict(template='/home/index.html', **data) return handle_content_type(response)
def test_projects_contributed_no_contributions(self): """Test CACHE USERS projects_contributed returns empty list if the user has not contributed to any project""" user = UserFactory.create() projects_contributed = cached_users.projects_contributed(user.id) assert projects_contributed == [], projects_contributed
def test_projects_contributed_contributions(self): """Test CACHE USERS projects_contributed returns a list of projects that has contributed to""" user = UserFactory.create() project_contributed = ProjectFactory.create() task = TaskFactory.create(project=project_contributed) TaskRunFactory.create(task=task, user=user) another_project = ProjectFactory.create() projects_contributed = cached_users.projects_contributed(user.id) assert len(projects_contributed) == 1 assert projects_contributed[0]['short_name'] == project_contributed.short_name, projects_contributed
def test_projects_contributed_returns_fields(self): """Test CACHE USERS projects_contributed returns the info of the projects with the required fields""" user = UserFactory.create() project_contributed = ProjectFactory.create() task = TaskFactory.create(project=project_contributed) TaskRunFactory.create(task=task, user=user) fields = ('id', 'name', 'short_name', 'owner_id', 'description', 'overall_progress', 'n_tasks', 'n_volunteers', 'info') projects_contributed = cached_users.projects_contributed(user.id) for field in fields: assert field in projects_contributed[0].keys(), field
def home(): """Render home page with the cached projects and users.""" page = 1 per_page = current_app.config.get('APPS_PER_PAGE', 5) 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 response = dict(template='/home/index.html', **data) return handle_content_type(response)
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 response = dict(template='/home/index.html', **data) return handle_content_type(response)
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)