Example #1
0
def send_email_notifications():
    from pybossa.core import sentinel
    from pybossa.cache import projects as cached_projects
    from pybossa.core import project_repo
    from pybossa.sched import Schedulers

    redis_conn = sentinel.master
    project_set = redis_conn.hgetall('updated_project_ids') or {}
    for project_id, timestamp in project_set.iteritems():
        project = project_repo.get(project_id)
        redis_conn.hdel('updated_project_ids', project_id)
        if not project.email_notif:
            continue
        user_emails = []
        if cached_projects.get_project_scheduler(project_id) == Schedulers.user_pref:
            user_emails = user_repo.get_user_pref_recent_contributor_emails(project_id, timestamp)
        else:
            if cached_projects.overall_progress(project_id) != 100:
                user_emails = user_repo.get_recent_contributor_emails(project_id)

        if user_emails:
            recipients = []
            for email_addr in user_emails:
                if email_addr not in recipients:
                    recipients.append(email_addr)
            subject = (u'New Tasks have been imported to {}'.format(project.name))
            body = u'Hello,\n\nThere have been new tasks uploaded to the previously finished project, {0}. ' \
                   u'\nLog on to {1} to complete any available tasks.' \
                .format(project.name, current_app.config.get('BRAND'))
            mail_dict = dict(recipients=recipients, subject=subject, body=body)
            send_mail(mail_dict)
    return True
Example #2
0
def before_add_task_event(mapper, conn, target):
    redis_conn = sentinel.master
    if cached_projects.get_project_scheduler(target.project_id) == Schedulers.user_pref:
        if not redis_conn.hget('updated_project_ids', target.project_id):
            redis_conn.hset('updated_project_ids', target.project_id, make_timestamp())
    else:
        if cached_projects.overall_progress(target.project_id) == 100:
            redis_conn.hset('updated_project_ids', target.project_id, make_timestamp())