def get_non_contributors_users_jobs(queue='quaterly'):
"""Return a list of users that have never contributed to a project."""
from sqlalchemy.sql import text
from pybossa.model.user import User
from pybossa.core import db
# Second users that have created an account but never participated
sql = text('''SELECT id FROM "user" WHERE
NOT EXISTS (SELECT user_id FROM task_run
WHERE task_run.user_id="user".id)''')
results = db.slave_session.execute(sql)
timeout = current_app.config.get('TIMEOUT')
for row in results:
user = User.query.get(row.id)
if user.subscribed:
subject = "Why don't you help us?!"
body = render_template('/account/email/noncontributors.md',
user=user.dictize(),
config=current_app.config)
html = render_template('/account/email/noncontributors.html',
user=user.dictize(),
config=current_app.config)
mail_dict = dict(recipients=[user.email_addr],
subject=subject,
body=body,
html=html)
job = dict(name=send_mail,
args=[mail_dict],
kwargs={},
timeout=timeout,
queue=queue)
yield job
评论列表
文章目录