def featured(app_id=None): """List featured apps of PyBossa""" n_published = cached_apps.n_published() if request.method == 'GET': apps, n_published = cached_apps.get_published(page=1, per_page=n_published) return render_template('/admin/applications.html', apps=apps) if request.method == 'POST': cached_apps.reset() f = model.Featured() f.app_id = app_id # Check if the app is already in this table tmp = db.session.query(model.Featured)\ .filter(model.Featured.app_id == app_id)\ .first() if (tmp is None): db.session.add(f) db.session.commit() return json.dumps(f.dictize()) else: return json.dumps({'error': 'App.id %s already in Featured table' % app_id}) if request.method == 'DELETE': cached_apps.reset() f = db.session.query(model.Featured)\ .filter(model.Featured.app_id == app_id)\ .first() if (f): db.session.delete(f) db.session.commit() return "", 204 else: return json.dumps({'error': 'App.id %s is not in Featured table' % app_id})
def api(): """Render help/api page""" apps, count = cached_apps.get_published() if len(apps) > 0: app_id = choice(apps)['id'] else: app_id = None return render_template('help/api.html', title="Help: API", app_id=app_id)
def index(page): if require.app.read(): per_page = 5 apps, count = cached_apps.get_published(page, per_page) pagination = Pagination(page, per_page, count) return render_template('/applications/index.html', title="Applications", apps=apps, pagination=pagination) else: abort(403)
def published(page): """Show the Published apps""" if require.app.read(): per_page = 5 apps, count = cached_apps.get_published(page, per_page) pagination = Pagination(page, per_page, count) return render_template('/applications/index.html', title="Applications", apps=apps, count=count, pagination=pagination, app_type='app-published') else: abort(403)