def on_taskrun_submit(mapper, conn, target): """Update the task.state when n_answers condition is met.""" # Get project details sql_query = ( 'select name, short_name, published, webhook, info from project \ where id=%s') % target.project_id results = conn.execute(sql_query) tmp = dict() for r in results: tmp['name'] = r.name tmp['short_name'] = r.short_name _published = r.published tmp['info'] = r.info _webhook = r.webhook tmp['id'] = target.project_id project_public = dict() project_public.update(Project().to_public_json(tmp)) project_public['action_updated'] = 'TaskCompleted' add_user_contributed_to_feed(conn, target.user_id, project_public) if is_task_completed(conn, target.task_id, target.project_id): update_task_state(conn, target.task_id) update_feed(project_public) result_id = create_result(conn, target.project_id, target.task_id) project_private = dict() project_private.update(project_public) project_private['webhook'] = _webhook push_webhook(project_private, target.task_id, result_id)
def add_blog_event(mapper, conn, target): """Update PYBOSSA feed with new blog post.""" sql_query = ('select name, short_name, info from project \ where id=%s') % target.project_id results = conn.execute(sql_query) obj = dict(action_updated='Blog') tmp = dict() for r in results: tmp['id'] = target.project_id tmp['name'] = r.name tmp['short_name'] = r.short_name tmp['info'] = r.info tmp = Project().to_public_json(tmp) obj.update(tmp) update_feed(obj) # Notify volunteers mail_queue.enqueue(notify_blog_users, blog_id=target.id, project_id=target.project_id) contents = {"en": "New update!"} headings = {"en": target.title} launch_url = url_for('project.show_blogpost', short_name=tmp['short_name'], id=target.id, _external=True) web_buttons = [{"id": "read-more-button", "text": "Read more", "icon": "http://i.imgur.com/MIxJp1L.png", "url": launch_url }] webpush_queue.enqueue(push_notification, project_id=target.project_id, contents=contents, headings=headings, web_buttons=web_buttons, launch_url=launch_url)
def on_taskrun_submit(mapper, conn, target): """Update the task.state when n_answers condition is met.""" # Get project details sql_query = ('select name, short_name, webhook, info from project \ where id=%s') % target.project_id results = conn.execute(sql_query) project_obj = dict(id=target.project_id, name=None, short_name=None, info=None, webhook=None, action_updated='TaskCompleted') for r in results: project_obj['name'] = r.name project_obj['short_name'] = r.short_name project_obj['info'] = r.info project_obj['webhook'] = r.webhook project_obj['id'] = target.project_id add_user_contributed_to_feed(conn, target.user_id, project_obj) if is_task_completed(conn, target.task_id): update_task_state(conn, target.task_id) update_feed(project_obj) result_id = create_result(conn, target.project_id, target.task_id) push_webhook(project_obj, target.task_id, result_id)
def add_project_event(mapper, conn, target): """Update PyBossa feed with new project.""" obj = dict(id=target.id, name=target.name, short_name=target.short_name, action_updated='Project') update_feed(obj)
def on_taskrun_submit(mapper, conn, target): """Update the task.state when n_answers condition is met.""" # Get project details sql_query = ('select name, short_name, published, webhook, info from project \ where id=%s') % target.project_id results = conn.execute(sql_query) tmp = dict() for r in results: tmp['name'] = r.name tmp['short_name'] = r.short_name _published = r.published tmp['info'] = r.info _webhook = r.webhook tmp['id'] = target.project_id project_public = dict() project_public.update(Project().to_public_json(tmp)) project_public['action_updated'] = 'TaskCompleted' add_user_contributed_to_feed(conn, target.user_id, project_public) if is_task_completed(conn, target.task_id, target.project_id): update_task_state(conn, target.task_id) update_feed(project_public) result_id = create_result(conn, target.project_id, target.task_id) project_private = dict() project_private.update(project_public) project_private['webhook'] = _webhook push_webhook(project_private, target.task_id, result_id)
def add_project_event(mapper, conn, target): """Update PYBOSSA feed with new project.""" tmp = dict(id=target.id, name=target.name, short_name=target.short_name, info=target.info) obj = dict(action_updated='Project') tmp = Project().to_public_json(tmp) obj.update(tmp) update_feed(obj)
def add_user_contributed_to_feed(conn, user_id, project_obj): if user_id is not None: sql_query = ('select fullname, name, info from "user" \ where id=%s') % user_id results = conn.execute(sql_query) for r in results: obj = dict(id=user_id, name=r.name, fullname=r.fullname, info=r.info, project_name=project_obj['name'], project_short_name=project_obj['short_name'], action_updated='UserContribution') update_feed(obj)
def add_task_event(mapper, conn, target): """Update PyBossa feed with new task.""" sql_query = ('select name, short_name, info from project \ where id=%s') % target.project_id results = conn.execute(sql_query) obj = dict(id=target.project_id, name=None, short_name=None, info=None, action_updated='Task') for r in results: obj['name'] = r.name obj['short_name'] = r.short_name obj['info'] = r.info update_feed(obj)
def add_task_event(mapper, conn, target): """Update PYBOSSA feed with new task.""" sql_query = ('select name, short_name, info from project \ where id=%s') % target.project_id results = conn.execute(sql_query) obj = dict(action_updated='Task') tmp = dict() for r in results: tmp['id'] = target.project_id tmp['name'] = r.name tmp['short_name'] = r.short_name tmp['info'] = r.info tmp = Project().to_public_json(tmp) obj.update(tmp) update_feed(obj)
def add_user_contributed_to_feed(conn, user_id, project_obj): if user_id is not None: sql_query = ('select fullname, name, info from "user" \ where id=%s') % user_id results = conn.execute(sql_query) for r in results: tmp = dict(id=user_id, name=r.name, fullname=r.fullname, info=r.info) tmp = User().to_public_json(tmp) tmp['project_name'] = project_obj['name'] tmp['project_short_name'] = project_obj['short_name'] tmp['action_updated'] = 'UserContribution' update_feed(tmp)
def add_blog_event(mapper, conn, target): """Update PyBossa feed with new blog post.""" sql_query = ( ( "select name, short_name, info from project \ where id=%s" ) % target.project_id ) results = conn.execute(sql_query) obj = dict(id=target.project_id, name=None, short_name=None, info=None, action_updated="Blog") for r in results: obj["name"] = r.name obj["short_name"] = r.short_name obj["info"] = r.info update_feed(obj)
def on_taskrun_submit(mapper, conn, target): """Update the task.state when n_answers condition is met.""" # Get project details sql_query = ( 'select name, short_name, published, webhook, info, category_id \ from project where id=%s') % target.project_id results = conn.execute(sql_query) tmp = dict() for r in results: tmp['name'] = r.name tmp['short_name'] = r.short_name _published = r.published tmp['info'] = r.info _webhook = r.webhook tmp['category_id'] = r.category_id tmp['id'] = target.project_id project_public = dict() project_public.update(Project().to_public_json(tmp)) project_public['action_updated'] = 'TaskCompleted' sched.after_save(target, conn) add_user_contributed_to_feed(conn, target.user_id, project_public) # golden tasks never complete; bypass update to task.state # mark task as exported false for each task run submissions task = task_repo.get_task(id=target.task_id) if task.calibration: if task.exported and _published: sql_query = ("""UPDATE task SET exported=False \ WHERE id=%s;""") % (task.id) conn.execute(sql_query) return is_completed = is_task_completed(conn, target.task_id, target.project_id) if is_completed: update_task_state(conn, target.task_id) check_and_send_task_notifications(target.project_id, conn) if is_completed and _published: update_feed(project_public) result_id = create_result(conn, target.project_id, target.task_id) project_private = dict() project_private.update(project_public) project_private['webhook'] = _webhook push_webhook(project_private, target.task_id, result_id)
def add_project_event(mapper, conn, target): """Update PYBOSSA feed with new project.""" tmp = dict(id=target.id, name=target.name, short_name=target.short_name, info=target.info) obj = dict(action_updated='Project') tmp = Project().to_public_json(tmp) obj.update(tmp) update_feed(obj) # Create a clean projectstats object for it sql_query = """INSERT INTO project_stats (project_id, n_tasks, n_task_runs, n_results, n_volunteers, n_completed_tasks, overall_progress, average_time, n_blogposts, last_activity, info) VALUES (%s, 0, 0, 0, 0, 0, 0, 0, 0, 0, '{}');""" % (target.id) conn.execute(sql_query)
def add_blog_event(mapper, conn, target): """Update PYBOSSA feed with new blog post.""" sql_query = ('select name, short_name, info from project \ where id=%s') % target.project_id results = conn.execute(sql_query) obj = dict(action_updated='Blog') tmp = dict() for r in results: tmp['id'] = target.project_id tmp['name'] = r.name tmp['short_name'] = r.short_name tmp['info'] = r.info tmp = Project().to_public_json(tmp) obj.update(tmp) update_feed(obj) # Notify volunteers mail_queue.enqueue(notify_blog_users, blog_id=target.id, project_id=target.project_id)
def add_blog_event(mapper, conn, target): """Update PyBossa feed with new blog post.""" sql_query = ('select name, short_name, info from project \ where id=%s') % target.project_id results = conn.execute(sql_query) obj = dict(id=target.project_id, name=None, short_name=None, info=None, action_updated='Blog') for r in results: obj['name'] = r.name obj['short_name'] = r.short_name obj['info'] = r.info update_feed(obj) # Notify volunteers mail_queue.enqueue(notify_blog_users, blog_id=target.id, project_id=target.project_id)
def on_taskrun_submit(mapper, conn, target): """Update the task.state when n_answers condition is met.""" # Get project details sql_query = ( 'select name, short_name, published, webhook, info, category_id \ from project where id=%s') % target.project_id results = conn.execute(sql_query) tmp = dict() for r in results: tmp['name'] = r.name tmp['short_name'] = r.short_name _published = r.published tmp['info'] = r.info _webhook = r.webhook tmp['category_id'] = r.category_id tmp['id'] = target.project_id project_public = dict() project_public.update(Project().to_public_json(tmp)) project_public['action_updated'] = 'TaskCompleted' sched.after_save(target, conn) add_user_contributed_to_feed(conn, target.user_id, project_public) if is_task_completed(conn, target.task_id, target.project_id): update_task_state(conn, target.task_id) update_feed(project_public) result_id = create_result(conn, target.project_id, target.task_id) project_private = dict() project_private.update(project_public) project_private['webhook'] = _webhook push_webhook(project_private, target.task_id, result_id) # Every time a registered user contributes a taskrun its notified_at column is reset # so the job for deleting inactive accounts, is not triggered if target.user_id: sql = f"update \"user\" set notified_at=null where \"user\".id={target.user_id};" conn.execute(sql)
def add_user_event(mapper, conn, target): """Update PyBossa feed with new user.""" obj = target.dictize() obj['action_updated']='User' update_feed(obj)
def add_user_event(mapper, conn, target): """Update PYBOSSA feed with new user.""" obj = target.to_public_json() obj['action_updated'] = 'User' update_feed(obj)
def update_audit_data(mapper, conn, target): try: if not isinstance(target.info, dict): return data = target.info if not data.has_key('result'): return sql_query = ( 'select id from project where category_id in (select category_id \ from project where id=%s) and id != %s') % (target.project_id, target.project_id) print(sql_query) result = conn.execute(sql_query) print(3432432) one = result.fetchone() if len(one) <= 0: return project_id = one[0] print(one) info = {} print(target.__dict__) info['project_id'] = project_id info['task_id'] = target.task_id info['user_id'] = target.user_id info['user_ip'] = "" info['finish_time'] = target.finish_time info['result'] = data['result'] info['answers'] = data['answers'] info['question'] = data['question'] info['link'] = data['link'] info['url_m'] = data['url_m'] info['url_b'] = data['url_b'] sql_query = ( "insert into task(created, project_id, state, quorum, calibration, \ priority_0, info, n_answers) values (TIMESTAMP '%s', %s, 'ongoing', 0, 0, 0, '%s', 30) RETURNING id;" % (make_timestamp(), project_id, json.dumps(info))) print(sql_query) result = conn.execute(sql_query) id_of_new_row = result.fetchone()[0] print(id_of_new_row) sql_query = ( "insert into counter(created, project_id, task_id, n_task_runs) \ VALUES (TIMESTAMP '%s', %s, %s, 0)" % (make_timestamp(), project_id, id_of_new_row)) print(sql_query) conn.execute(sql_query) print(sql_query) """Update PYBOSSA feed with new task.""" sql_query = ('select name, short_name, info from project \ where id=%s') % project_id results = conn.execute(sql_query) obj = dict(action_updated='Task') tmp = dict() for r in results: tmp['id'] = project_id tmp['name'] = r.name tmp['short_name'] = r.short_name tmp['info'] = r.info tmp = Project().to_public_json(tmp) obj.update(tmp) update_feed(obj) except: raise