
from __future__ import unicode_literals

from celery.schedules import crontab

from indico.core.celery import celery
from indico.core.db import db
from indico.modules.events.surveys.models.surveys import Survey


@celery.periodic_task(name='survey_start_notifications', run_every=crontab(minute='*/30'))
def send_start_notifications():
    opened_surveys = Survey.find_all(~Survey.is_deleted, ~Survey.start_notification_sent, Survey.has_started,
                                     Survey.notifications_enabled)
    try:
        for survey in opened_surveys:
            survey.send_start_notification()
    finally:
        db.session.commit()


from __future__ import unicode_literals

from celery.schedules import crontab

from indico.core.celery import celery
from indico.core.db import db
from indico.modules.events.surveys.models.surveys import Survey


@celery.periodic_task(name='survey_start_notifications', run_every=crontab(minute='*/30'))
def send_start_notifications():
    active_surveys = Survey.find_all(Survey.is_active, ~Survey.start_notification_sent, Survey.notifications_enabled)
    try:
        for survey in active_surveys:
            survey.send_start_notification()
    finally:
        db.session.commit()

Use safer condition for survey start notification
Use safer condition for survey start notification

  
  from __future__ import unicode_literals
  
  from celery.schedules import crontab
  
  from indico.core.celery import celery
  from indico.core.db import db
  from indico.modules.events.surveys.models.surveys import Survey
  
  
  @celery.periodic_task(name='survey_start_notifications', run_every=crontab(minute='*/30'))
  def send_start_notifications():
-     opened_surveys = Survey.find_all(~Survey.is_deleted, ~Survey.start_notification_sent, Survey.has_started,
+     active_surveys = Survey.find_all(Survey.is_active, ~Survey.start_notification_sent, Survey.notifications_enabled)
-                                      Survey.notifications_enabled)
      try:
-         for survey in opened_surveys:
+         for survey in active_surveys:
              survey.send_start_notification()
      finally:
          db.session.commit()
  
Use safer condition for survey start notification
## Code Before:

from __future__ import unicode_literals

from celery.schedules import crontab

from indico.core.celery import celery
from indico.core.db import db
from indico.modules.events.surveys.models.surveys import Survey


@celery.periodic_task(name='survey_start_notifications', run_every=crontab(minute='*/30'))
def send_start_notifications():
    opened_surveys = Survey.find_all(~Survey.is_deleted, ~Survey.start_notification_sent, Survey.has_started,
                                     Survey.notifications_enabled)
    try:
        for survey in opened_surveys:
            survey.send_start_notification()
    finally:
        db.session.commit()

## Instruction:
Use safer condition for survey start notification
## Code After:

from __future__ import unicode_literals

from celery.schedules import crontab

from indico.core.celery import celery
from indico.core.db import db
from indico.modules.events.surveys.models.surveys import Survey


@celery.periodic_task(name='survey_start_notifications', run_every=crontab(minute='*/30'))
def send_start_notifications():
    active_surveys = Survey.find_all(Survey.is_active, ~Survey.start_notification_sent, Survey.notifications_enabled)
    try:
        for survey in active_surveys:
            survey.send_start_notification()
    finally:
        db.session.commit()
