def handle_valid_form(form): hidden = int(form.hidden.data) new_info = {} # Add the info items app, n_tasks, n_task_runs, overall_progress, last_activity = app_by_shortname(short_name) if form.thumbnail.data: new_info['thumbnail'] = form.thumbnail.data #if form.sched.data: # new_info['sched'] = form.sched.data # Merge info object info = dict(app.info.items() + new_info.items()) new_application = model.App( id=form.id.data, name=form.name.data, short_name=form.short_name.data, description=form.description.data, long_description=form.long_description.data, hidden=hidden, info=info, owner_id=app.owner_id, allow_anonymous_contributors=form.allow_anonymous_contributors.data, category_id=form.category_id.data) app, n_tasks, n_task_runs, overall_progress, last_activity = app_by_shortname(short_name) db.session.merge(new_application) db.session.commit() cached_apps.reset() cached_cat.reset() flash(gettext('Application updated!'), 'success') return redirect(url_for('.details', short_name=new_application.short_name))
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 handle_valid_form(form): hidden = int(form.hidden.data) new_info = {} # Add the info items app = app_by_shortname(short_name) if form.thumbnail.data: new_info['thumbnail'] = form.thumbnail.data #if form.sched.data: # new_info['sched'] = form.sched.data # Merge info object info = dict(app.info.items() + new_info.items()) new_application = model.App( id=form.id.data, name=form.name.data, short_name=form.short_name.data, description=form.description.data, long_description=form.long_description.data, hidden=hidden, info=info, owner_id=app.owner_id, allow_anonymous_contributors=form.allow_anonymous_contributors.data, category_id=form.category_id.data) app = app_by_shortname(short_name) db.session.merge(new_application) db.session.commit() cached_apps.reset() cached_cat.reset() flash(gettext('Application updated!'), 'success') return redirect(url_for('.details', short_name=new_application.short_name))
def task_scheduler(short_name): app = app_by_shortname(short_name) title = app_title(app, lazy_gettext('Scheduler')) form = TaskSchedulerForm() try: require.app.read(app) require.app.update(app) if request.method == 'GET': if app.info.get('sched'): for s in form.sched.choices: if app.info['sched'] == s[0]: form.sched.data = s[0] break return render_template('/applications/task_scheduler.html', title=title, form=form, app=app) elif request.method == 'POST' and form.validate(): if form.sched.data: app.info['sched'] = form.sched.data cached_apps.reset() db.session.add(app) db.session.commit() msg = lazy_gettext("Application Task Scheduler updated!") flash(msg, 'success') return redirect(url_for('.tasks', short_name=app.short_name)) else: flash(lazy_gettext('Please correct the errors'), 'error') return render_template('/applications/task_scheduler.html', title=title, form=form, app=app) except: return abort(403)
def featured(app_id=None): """List featured apps of PyBossa""" try: categories = cached_cat.get_all() if request.method == 'GET': apps = {} for c in categories: n_apps = cached_apps.n_count(category=c.short_name) apps[c.short_name], n_apps = cached_apps.get(category=c.short_name, page=1, per_page=n_apps) return render_template('/admin/applications.html', apps=apps, categories=categories) elif app_id: if request.method == 'POST': cached_apps.reset() f = model.Featured() f.app_id = app_id app = db.session.query(model.App).get(app_id) require.app.update(app) # 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: msg = "App.id %s alreay in Featured table" % app_id return format_error(msg, 415) 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: msg = 'App.id %s is not in Featured table' % app_id return format_error(msg, 404) else: msg = ('App.id is missing for %s action in featured method' % request.method) return format_error(msg, 415) except HTTPException: return abort(403) except Exception as e: current_app.logger.error(e) return abort(500)
def new(): if not require.app.create(): abort(403) form = AppForm(request.form) categories = db.session.query(model.Category).all() form.category_id.choices = [(c.id, c.name) for c in categories] def respond(errors): return render_template('applications/new.html', title=lazy_gettext("Create an Application"), form=form, errors=errors) if request.method != 'POST': return respond(False) if not form.validate(): flash(lazy_gettext('Please correct the errors'), 'error') return respond(True) info = {} # Add the info items if form.thumbnail.data: info['thumbnail'] = form.thumbnail.data app = model.App( name=form.name.data, short_name=form.short_name.data, description=form.description.data, long_description=form.long_description.data, category_id=form.category_id.data, allow_anonymous_contributors=form.allow_anonymous_contributors.data, hidden=int(form.hidden.data), owner_id=current_user.id, info=info, ) cached_apps.reset() db.session.add(app) db.session.commit() # Clean cache msg_1 = lazy_gettext('Application created!') flash('<i class="icon-ok"></i> ' + msg_1, 'success') flash( '<i class="icon-bullhorn"></i> ' + lazy_gettext('You can check the ') + '<strong><a href="https://docs.pybossa.com">' + lazy_gettext('Guide and Documentation') + '</a></strong> ' + lazy_gettext('for adding tasks, a thumbnail, using PyBossa.JS, etc.'), 'info') return redirect(url_for('.settings', short_name=app.short_name))
def new(): if not require.app.create(): abort(403) form = AppForm(request.form) categories = db.session.query(model.Category).all() form.category_id.choices = [(c.id, c.name) for c in categories] def respond(errors): return render_template('applications/new.html', title=gettext("Create an Application"), form=form, errors=errors) if request.method != 'POST': return respond(False) if not form.validate(): flash(gettext('Please correct the errors'), 'error') return respond(True) info = {} # Add the info items if form.thumbnail.data: info['thumbnail'] = form.thumbnail.data app = model.App(name=form.name.data, short_name=form.short_name.data, description=form.description.data, long_description=form.long_description.data, category_id=form.category_id.data, allow_anonymous_contributors=form.allow_anonymous_contributors.data, hidden=int(form.hidden.data), owner_id=current_user.id, info=info,) cached_apps.reset() db.session.add(app) db.session.commit() # Clean cache msg_1 = gettext('Application created!') flash('<i class="icon-ok"></i> ' + msg_1, 'success') flash('<i class="icon-bullhorn"></i> ' + gettext('You can check the ') + '<strong><a href="https://docs.pybossa.com">' + gettext('Guide and Documentation') + '</a></strong> ' + gettext('for adding tasks, a thumbnail, using PyBossa.JS, etc.'), 'info') return redirect(url_for('.settings', short_name=app.short_name))
def featured(app_id=None): """List featured apps of PyBossa""" try: if request.method == 'GET': categories = cached_cat.get_all() apps = {} for c in categories: n_apps = cached_apps.n_count(category=c.short_name) apps[c.short_name] = cached_apps.get(category=c.short_name, page=1, per_page=n_apps) return render_template('/admin/applications.html', apps=apps, categories=categories) else: app = db.session.query(model.app.App).get(app_id) if app: require.app.update(app) if request.method == 'POST': cached_apps.reset() if not app.featured: app.featured = True db.session.add(app) db.session.commit() return json.dumps(app.dictize()) else: msg = "App.id %s already featured" % app_id return format_error(msg, 415) if request.method == 'DELETE': cached_apps.reset() if app.featured: app.featured = False db.session.add(app) db.session.commit() return json.dumps(app.dictize()) else: msg = 'App.id %s is not featured' % app_id return format_error(msg, 415) else: msg = 'App.id %s not found' % app_id return format_error(msg, 404) except Exception as e: # pragma: no cover current_app.logger.error(e) return abort(500)