def app_index(page, lookup, category, fallback, use_count): """Show apps of app_type""" per_page = 5 # @FC to come back to project homepage from the application detail if 'cat_byapp_' in category: category = get_app_category(category.replace("cat_byapp_", "")) # @FC apps, count = lookup(category, page, per_page) data = [] #for app in apps: # if 'tutorial' in app['short_name']: # data.append(dict(app=app, n_tasks=cached_apps.n_tasks(app['id']), # overall_progress=cached_apps.overall_progress(app['id']), # last_activity=cached_apps.last_activity(app['id']))) for app in apps: if 'tutorial' not in app['short_name']: data.append(dict(app=app, n_tasks=cached_apps.n_tasks(app['id']), overall_progress=cached_apps.overall_progress(app['id']), last_activity=cached_apps.last_activity(app['id']))) if fallback and not apps: return redirect(url_for('.published')) pagination = Pagination(page, per_page, count) categories = cached_cat.get_all() # Check for pre-defined categories featured and draft featured_cat = model.Category(name='Featured', short_name='featured', description='Featured applications') if category == 'featured': active_cat = featured_cat elif category == 'draft': active_cat = model.Category(name='Draft', short_name='draft', description='Draft applications') else: active_cat = db.session.query(model.Category)\ .filter_by(short_name=category).first() # Check if we have to add the section Featured to local nav if cached_apps.n_featured() > 0: categories.insert(0, featured_cat) template_args = { "apps": data, "title": gettext("Applications"), "pagination": pagination, "active_cat": active_cat, "n_apps_per_category": None, "categories": categories} n_apps_per_category = dict() for c in categories: n_apps_per_category[c.short_name] = cached_apps.n_count(c.short_name) template_args['n_apps_per_category'] = n_apps_per_category if use_count: template_args.update({"count": count}) return render_template('/applications/index.html', **template_args)
def get(self, id): """Return global stats.""" n_pending_tasks = stats.n_total_tasks_site() - stats.n_task_runs_site() n_users = stats.n_auth_users() + stats.n_anon_users() n_projects = cached_apps.n_published() + cached_apps.n_draft() data = dict(n_projects=n_projects, n_users=n_users, n_task_runs=stats.n_task_runs_site(), n_pending_tasks=n_pending_tasks, categories=[]) # Add Categories categories = cached_categories.get_used() for c in categories: datum = dict() datum[c['short_name']] = cached_apps.n_count(c['short_name']) data['categories'].append(datum) # Add Featured datum = dict() datum['featured'] = cached_apps.n_featured() data['categories'].append(datum) # Add Draft datum = dict() datum['draft'] = cached_apps.n_draft() data['categories'].append(datum) return Response(json.dumps(data), 200, mimetype='application/json')
def index(page): """List apps in the system""" if cached_apps.n_featured() > 0: return app_index(page, cached_apps.get_featured, 'featured', True, False) else: categories = cached_cat.get_all() cat_short_name = categories[0].short_name return redirect(url_for('.app_cat_index', category=cat_short_name))
def app_index(page, lookup, category, fallback, use_count): """Show apps of app_type""" per_page = 5 apps, count = lookup(category, page, per_page) data = [] for app in apps: data.append( dict(app=app, n_tasks=cached_apps.n_tasks(app['id']), overall_progress=cached_apps.overall_progress(app['id']), last_activity=app['last_activity'], last_activity_raw=app['last_activity_raw'])) if fallback and not apps: # pragma: no cover return redirect(url_for('.index')) pagination = Pagination(page, per_page, count) categories = cached_cat.get_all() # Check for pre-defined categories featured and draft featured_cat = model.Category(name='Featured', short_name='featured', description='Featured applications') if category == 'featured': active_cat = featured_cat elif category == 'draft': active_cat = model.Category(name='Draft', short_name='draft', description='Draft applications') else: active_cat = db.session.query(model.Category)\ .filter_by(short_name=category).first() # Check if we have to add the section Featured to local nav if cached_apps.n_featured() > 0: categories.insert(0, featured_cat) template_args = { "apps": data, "title": gettext("Applications"), "pagination": pagination, "active_cat": active_cat, "categories": categories } if use_count: template_args.update({"count": count}) return render_template('/applications/index.html', **template_args)
def index(page): """List apps in the system""" if cached_apps.n_featured() > 0: return app_index(page, cached_apps.get_featured, 'featured', True, False) else: categories = cached_cat.get_all() if len(categories) > 0: cat_short_name = categories[0].short_name else: cat = db.session.query(model.Category).first() if cat: cat_short_name = cat.short_name else: cat_short_name = "algo" return redirect(url_for('.app_cat_index', category=cat_short_name))
def app_index(page, lookup, category, fallback, use_count): """Show apps of app_type""" per_page = 5 apps, count = lookup(category, page, per_page) data = [] for app in apps: data.append(dict(app=app, n_tasks=cached_apps.n_tasks(app['id']), overall_progress=cached_apps.overall_progress(app['id']), last_activity=app['last_activity'], last_activity_raw=app['last_activity_raw'])) if fallback and not apps: # pragma: no cover return redirect(url_for('.index')) pagination = Pagination(page, per_page, count) categories = cached_cat.get_all() # Check for pre-defined categories featured and draft featured_cat = model.Category(name='Featured', short_name='featured', description='Featured applications') if category == 'featured': active_cat = featured_cat elif category == 'draft': active_cat = model.Category(name='Draft', short_name='draft', description='Draft applications') else: active_cat = db.session.query(model.Category)\ .filter_by(short_name=category).first() # Check if we have to add the section Featured to local nav if cached_apps.n_featured() > 0: categories.insert(0, featured_cat) template_args = { "apps": data, "title": gettext("Applications"), "pagination": pagination, "active_cat": active_cat, "categories": categories} if use_count: template_args.update({"count": count}) return render_template('/applications/index.html', **template_args)
def app_index(page, lookup, category, fallback, use_count): """Show apps of app_type""" if not require.app.read(): abort(403) per_page = 5 apps, count = lookup(category, page, per_page) if fallback and not apps: return redirect(url_for('.published')) pagination = Pagination(page, per_page, count) categories = cached_cat.get_all() # Check for pre-defined categories featured and draft featured_cat = model.Category(name='Featured', short_name='featured', description='Featured applications') if category == 'featured': active_cat = featured_cat elif category == 'draft': active_cat = model.Category(name='Draft', short_name='draft', description='Draft applications') else: active_cat = db.session.query(model.Category)\ .filter_by(short_name=category).first() # Check if we have to add the section Featured to local nav if cached_apps.n_featured() > 0: categories.insert(0, featured_cat) template_args = { "apps": apps, "title": lazy_gettext("Applications"), "pagination": pagination, "active_cat": active_cat, "categories": categories } if use_count: template_args.update({"count": count}) return render_template('/applications/index.html', **template_args)
def app_index(page, lookup, category, fallback, use_count): """Show apps of app_type""" if not require.app.read(): abort(403) per_page = 5 apps, count = lookup(category, page, per_page) if fallback and not apps: return redirect(url_for('.published')) pagination = Pagination(page, per_page, count) categories = cached_cat.get_all() # Check for pre-defined categories featured and draft featured_cat = model.Category(name='Featured', short_name='featured', description='Featured applications') if category == 'featured': active_cat = featured_cat elif category == 'draft': active_cat = model.Category(name='Draft', short_name='draft', description='Draft applications') else: active_cat = db.session.query(model.Category)\ .filter_by(short_name=category).first() # Check if we have to add the section Featured to local nav if cached_apps.n_featured() > 0: categories.insert(0, featured_cat) template_args = { "apps": apps, "title": gettext("Applications"), "pagination": pagination, "active_cat": active_cat, "categories": categories} if use_count: template_args.update({"count": count}) return render_template('/applications/index.html', **template_args)