Beispiel #1
0
def delete_tasks(short_name):
    """Delete ALL the tasks for a given application"""
    app, n_tasks, n_task_runs, overall_progress, last_activity = app_by_shortname(short_name)
    try:
        require.app.read(app)
        require.app.update(app)
        if request.method == 'GET':
            title = app_title(app, "Delete")
            return render_template('applications/tasks/delete.html',
                                   app=app,
                                   n_tasks=n_tasks,
                                   overall_progress=overall_progress,
                                   last_activity=last_activity,
                                   title=title)
        else:
            tasks = db.session.query(model.Task).filter_by(app_id=app.id).all()
            for t in tasks:
                db.session.delete(t)
            db.session.commit()
            msg = gettext("All the tasks and associated task runs have been deleted")
            flash(msg, 'success')
            cached_apps.delete_last_activity(app.id)
            cached_apps.delete_n_tasks(app.id)
            cached_apps.delete_n_task_runs(app.id)
            cached_apps.delete_overall_progress(app.id)
            return redirect(url_for('.tasks', short_name=app.short_name))
    except HTTPException:
        return abort(403)
Beispiel #2
0
def _import_task(app, handler, form, render_forms):
    try:
        empty = True
        n = 0
        n_data = 0
        for task_data in handler.tasks(form):
            n_data += 1
            task = model.Task(app_id=app.id)
            [setattr(task, k, v) for k, v in task_data.iteritems()]
            data = db.session.query(model.Task).filter_by(app_id=app.id).filter_by(info=task.info).first()
            if data is None:
                db.session.add(task)
                db.session.commit()
                n += 1
                empty = False
        if empty and n_data == 0:
            raise importer.BulkImportException(
                gettext('Oops! It looks like the file is empty.'))
        if empty and n_data > 0:
            flash(gettext('Oops! It looks like there are no new records to import.'), 'warning')

        msg = str(n) + " " + gettext('Tasks imported successfully!')
        if n == 1:
            msg = str(n) + " " + gettext('Task imported successfully!')
        flash(msg, 'success')
        cached_apps.delete_n_tasks(app.id)
        cached_apps.delete_n_task_runs(app.id)
        cached_apps.delete_overall_progress(app.id)
        cached_apps.delete_last_activity(app.id)
        return redirect(url_for('.tasks', short_name=app.short_name))
    except importer.BulkImportException, err_msg:
        flash(err_msg, 'error')
Beispiel #3
0
 def create_tasks(self, task_repo, project_id, **form_data):
     from pybossa.cache import apps as cached_apps
     from pybossa.model.task import Task
     """Create tasks from a remote source using an importer object and
     avoiding the creation of repeated tasks"""
     importer_id = form_data.get('type')
     empty = True
     n = 0
     importer = self._create_importer_for(importer_id)
     for task_data in importer.tasks(**form_data):
         task = Task(app_id=project_id)
         [setattr(task, k, v) for k, v in task_data.iteritems()]
         found = task_repo.get_task_by(app_id=project_id, info=task.info)
         if found is None:
             task_repo.save(task)
             n += 1
             empty = False
     if empty:
         msg = gettext('It looks like there were no new records to import')
         return msg
     msg = str(n) + " " + gettext('new tasks were imported successfully')
     if n == 1:
         msg = str(n) + " " + gettext('new task was imported successfully')
     cached_apps.delete_n_tasks(project_id)
     cached_apps.delete_n_task_runs(project_id)
     cached_apps.delete_overall_progress(project_id)
     cached_apps.delete_last_activity(project_id)
     return msg
Beispiel #4
0
def delete_tasks(short_name):
    """Delete ALL the tasks for a given application"""
    app, n_tasks, n_task_runs, overall_progress, last_activity = app_by_shortname(
        short_name)
    try:
        require.app.read(app)
        require.app.update(app)
        if request.method == 'GET':
            title = app_title(app, "Delete")
            return render_template('applications/tasks/delete.html',
                                   app=app,
                                   n_tasks=n_tasks,
                                   overall_progress=overall_progress,
                                   last_activity=last_activity,
                                   title=title)
        else:
            tasks = db.session.query(model.Task).filter_by(app_id=app.id).all()
            for t in tasks:
                db.session.delete(t)
            db.session.commit()
            msg = gettext(
                "All the tasks and associated task runs have been deleted")
            flash(msg, 'success')
            cached_apps.delete_last_activity(app.id)
            cached_apps.delete_n_tasks(app.id)
            cached_apps.delete_n_task_runs(app.id)
            cached_apps.delete_overall_progress(app.id)
            return redirect(url_for('.tasks', short_name=app.short_name))
    except HTTPException:
        return abort(403)
Beispiel #5
0
def _import_task(app, handler, form, render_forms):
    try:
        empty = True
        n = 0
        n_data = 0
        for task_data in handler.tasks(form):
            n_data += 1
            task = model.Task(app_id=app.id)
            [setattr(task, k, v) for k, v in task_data.iteritems()]
            data = db.session.query(model.Task).filter_by(app_id=app.id).filter_by(info=task.info).first()
            if data is None:
                db.session.add(task)
                db.session.commit()
                n += 1
                empty = False
        if empty and n_data == 0:
            raise importer.BulkImportException(
                gettext('Oops! It looks like the file is empty.'))
        if empty and n_data > 0:
            flash(gettext('Oops! It looks like there are no new records to import.'), 'warning')

        msg = str(n) + " " + gettext('Tasks imported successfully!')
        if n == 1:
            msg = str(n) + " " + gettext('Task imported successfully!')
        flash(msg, 'success')
        cached_apps.delete_n_tasks(app.id)
        cached_apps.delete_n_task_runs(app.id)
        cached_apps.delete_overall_progress(app.id)
        cached_apps.delete_last_activity(app.id)
        return redirect(url_for('.tasks', short_name=app.short_name))
    except importer.BulkImportException, err_msg:
        flash(err_msg, 'error')
Beispiel #6
0
def create_tasks(task_repo, tasks_data, project_id):
    empty = True
    n = 0
    for task_data in tasks_data:
        task = Task(app_id=project_id)
        [setattr(task, k, v) for k, v in task_data.iteritems()]
        found = task_repo.get_task_by(app_id=project_id, info=task.info)
        if found is None:
            task_repo.save(task)
            n += 1
            empty = False
    if empty:
        msg = gettext('It looks like there were no new records to import')
        return msg
    msg = str(n) + " " + gettext('new tasks were imported successfully')
    if n == 1:
        msg = str(n) + " " + gettext('new task was imported successfully')
    cached_apps.delete_n_tasks(project_id)
    cached_apps.delete_n_task_runs(project_id)
    cached_apps.delete_overall_progress(project_id)
    cached_apps.delete_last_activity(project_id)
    return msg