Exemplo n.º 1
0
    def save(self, *args, **kwargs):
        if not self.pk:
            self.slug = uuslug(self.name, instance=self)
        else:
            # Update action items
            current_poll = Poll.objects.get(id=self.pk)
            action_model = ContentType.objects.get_for_model(self)
            action_items = ActionItem.objects.filter(content_type=action_model,
                                                     object_id=self.pk)

            if current_poll.end != self.end:
                action_items.update(due_date=self.end.date())

            if current_poll.valid_groups != self.valid_groups:
                action_items.delete()
                ActionItem.create(self)

            if not settings.CELERY_ALWAYS_EAGER:
                if self.is_current_voting:
                    celery_control.revoke(self.task_end_id)
                elif self.is_future_voting:
                    celery_control.revoke(self.task_start_id)
                    celery_control.revoke(self.task_end_id)

            if not self.is_future_voting:
                obj = Poll.objects.get(pk=self.id)
                if self.end > obj.end:
                    self.is_extended = True

        super(Poll, self).save()
Exemplo n.º 2
0
    def save(self, *args, **kwargs):
        if not self.pk:
            self.slug = uuslug(self.name, instance=self)
        else:
            # Update action items
            current_poll = Poll.objects.get(id=self.pk)
            action_model = ContentType.objects.get_for_model(self)
            action_items = ActionItem.objects.filter(content_type=action_model,
                                                     object_id=self.pk)

            if current_poll.end != self.end:
                action_items.update(due_date=self.end.date())

            if current_poll.valid_groups != self.valid_groups:
                action_items.delete()
                ActionItem.create(self)

            if not settings.CELERY_ALWAYS_EAGER:
                if self.is_current_voting:
                    celery_control.revoke(self.task_end_id)
                elif self.is_future_voting:
                    celery_control.revoke(self.task_start_id)
                    celery_control.revoke(self.task_end_id)

            if not self.is_future_voting:
                obj = Poll.objects.get(pk=self.id)
                if self.end > obj.end:
                    self.is_extended = True

        super(Poll, self).save()
Exemplo n.º 3
0
    def save(self, *args, **kwargs):
        super(EventMetricOutcome, self).save(*args, **kwargs)

        # Resolve action items for post event metrics
        # if only is past event
        if self.event.is_past_event:
            ActionItem.resolve(instance=self.event, user=self.event.owner, name=self.event.name)
Exemplo n.º 4
0
def notify_event_owners_to_input_metrics():
    """Send an email to event creators.

    After an event has finished event creators are notified
    that they should input the actual metrics for the event.
    """
    start = datetime.combine(get_date(days=-1), datetime.min.time())
    end = datetime.combine(get_date(days=-1), datetime.max.time())
    events = Event.objects.filter(end__range=[start, end],
                                  has_new_metrics=True,
                                  eventmetricoutcome__outcome__isnull=True)
    events = events.distinct()

    event_model = ContentType.objects.get_for_model(Event)
    for event in events:
        # Before sending an email check that an action item already exists.
        # If it does, then we have already sent this email.

        action_item = ActionItem.objects.filter(content_type=event_model,
                                                object_id=event.id)
        if not action_item.exists():
            subject = u'[Reminder] Please add the actual metrics for event {0}'.format(
                event.name)
            template = 'email/event_creator_notification_to_input_metrics.jinja'
            data = {'event': event}
            send_remo_mail.delay(subject=subject,
                                 email_template=template,
                                 recipients_list=[event.owner.id],
                                 data=data)
            ActionItem.create(instance=event)
Exemplo n.º 5
0
Arquivo: tasks.py Projeto: flaki/remo
def notify_event_owners_to_input_metrics():
    """Send an email to event creators.

    After an event has finished event creators are notified
    that they should input the actual metrics for the event.
    """
    start = datetime.combine(get_date(days=-1), datetime.min.time())
    end = datetime.combine(get_date(days=-1), datetime.max.time())
    events = Event.objects.filter(
        end__range=[start, end], has_new_metrics=True, eventmetricoutcome__outcome__isnull=True
    )
    events = events.distinct()

    event_model = ContentType.objects.get_for_model(Event)
    for event in events:
        # Before sending an email check that an action item already exists.
        # If it does, then we have already sent this email.

        action_item = ActionItem.objects.filter(content_type=event_model, object_id=event.id)
        if not action_item.exists():
            subject = "[Reminder] Please add the actual metrics for event {0}".format(event.name)
            template = "email/event_creator_notification_to_input_metrics.txt"
            data = {"event": event}
            send_remo_mail(subject=subject, email_template=template, recipients_list=[event.owner.id], data=data)
            ActionItem.create(instance=event)
Exemplo n.º 6
0
    def save(self, *args, **kwargs):
        if self.poll.automated_poll:
            name = u'{0} {1}'.format(BUDGET_VOTE_ACTION, self.poll.bug.summary)
        else:
            name = u'{0} {1}'.format(VOTE_ACTION, self.poll.name)

        super(Vote, self).save(*args, **kwargs)
        ActionItem.resolve(instance=self.poll, user=self.user, name=name)
Exemplo n.º 7
0
    def save(self, *args, **kwargs):
        if self.poll.automated_poll:
            name = u'{0} {1}'.format(BUDGET_VOTE_ACTION, self.poll.bug.summary)
        else:
            name = u'{0} {1}'.format(VOTE_ACTION, self.poll.name)

        super(Vote, self).save(*args, **kwargs)
        ActionItem.resolve(instance=self.poll, user=self.user, name=name)
Exemplo n.º 8
0
    def save(self, *args, **kwargs):
        super(EventMetricOutcome, self).save(*args, **kwargs)

        # Resolve action items for post event metrics
        # if only is past event
        if self.event.is_past_event:
            ActionItem.resolve(instance=self.event,
                               user=self.event.owner,
                               name=self.event.name)
Exemplo n.º 9
0
    def save(self, *args, **kwargs):
        if self.poll.automated_poll:
            ActionItem.resolve(instance=self.poll, user=self.user,
                               name=BUDGET_VOTE_ACTION)
        else:
            ActionItem.resolve(instance=self.poll, user=self.user,
                               name=VOTE_ACTION)

        super(Vote, self).save(*args, **kwargs)
Exemplo n.º 10
0
def create_poll_action_items():
    """Create action items for current polls."""
    # avoid circular dependencies
    from remo.voting.models import Poll

    start = now() - timedelta(hours=4)
    polls = Poll.objects.filter(start__range=[start, now()])
    for poll in polls:
        ActionItem.create(poll)
Exemplo n.º 11
0
def create_poll_action_items():
    """Create action items for current polls."""
    # avoid circular dependencies
    from remo.voting.models import Poll

    start = now() - timedelta(hours=4)
    polls = Poll.objects.filter(start__range=[start, now()])
    for poll in polls:
        ActionItem.create(poll)
Exemplo n.º 12
0
    def test_resolve_action_item_invalid_date(self, mocked_date):
        model = ContentType.objects.get_for_model(UserProfile)
        user = UserFactory.create(groups=['Mentor'])
        mocked_date.return_value = datetime(now().year, now().month, 1)
        ActionItem.create(user.userprofile)
        items = ActionItem.objects.filter(content_type=model)
        eq_(items.count(), 1)
        eq_(items[0].resolved, False)

        mocked_date.return_value = datetime(now().year, now().month, 11)
        resolve_nomination_action_items()
        eq_(items.count(), 1)
        eq_(items[0].resolved, False)
Exemplo n.º 13
0
    def test_resolve_action_item_invalid_date(self, mocked_date):
        model = ContentType.objects.get_for_model(UserProfile)
        user = UserFactory.create(groups=['Mentor'])
        mocked_date.return_value = datetime(now().year, now().month, 1)
        ActionItem.create(user.userprofile)
        items = ActionItem.objects.filter(content_type=model)
        eq_(items.count(), 1)
        eq_(items[0].resolved, False)

        mocked_date.return_value = datetime(now().year, now().month, 11)
        resolve_nomination_action_items()
        eq_(items.count(), 1)
        eq_(items[0].resolved, False)
Exemplo n.º 14
0
    def get_action_items(self):
        # Avoid circular dependency
        from remo.base.helpers import user_is_rep

        if not self.assigned_to or not user_is_rep(self.assigned_to):
            return []

        def _get_action_name(action_name):
            return '{0} {1}'.format(action_name, self.summary)

        action_items = []
        actions = [
            (_get_action_name(ADD_RECEIPTS_ACTION),
             'waiting_receipts', ActionItem.NORMAL),
            (_get_action_name(ADD_REPORT_ACTION),
             'waiting_report', ActionItem.NORMAL),
            (_get_action_name(ADD_PHOTOS_ACTION),
             'waiting_photos', ActionItem.NORMAL),
            (_get_action_name(ADD_REPORTS_PHOTOS_ACTION),
             'waiting_report_photos', ActionItem.NORMAL),
            (_get_action_name(REVIEW_BUDGET_REQUEST_ACTION),
             'council_member_assigned', ActionItem.BLOCKER)
        ]

        for action_name, attr, priority in actions:
            if getattr(self, attr, None):
                action_item = Item(action_name, self.assigned_to,
                                   priority, None)
                action_items.append(action_item)
            else:
                ActionItem.resolve(instance=self, user=self.assigned_to,
                                   name=action_name)

        mentor_action = _get_action_name(WAITING_MENTOR_VALIDATION_ACTION)
        if self.assigned_to and user_is_rep(self.assigned_to):
            mentor = self.assigned_to
            if self.pending_mentor_validation:
                action_item = Item(mentor_action, mentor,
                                   ActionItem.BLOCKER, None)
                action_items.append(action_item)
            else:
                ActionItem.resolve(instance=self, user=mentor,
                                   name=mentor_action)

        action_name = _get_action_name(NEEDINFO_ACTION)
        for user in self.budget_needinfo.all():
            action_item = Item(action_name, user, ActionItem.CRITICAL, None)
            action_items.append(action_item)

        return action_items
Exemplo n.º 15
0
def send_rotm_nomination_reminder():
    """ Send an email reminder to all mentors.

    The first day of each month, the mentor group receives an email reminder
    in order to nominate Reps for the Rep of the month voting.
    """

    now_date = now().date()
    if now_date.day == ROTM_REMINDER_DAY:
        data = {'month': number2month(now_date.month)}
        subject = 'Nominate Rep of the month'
        template = 'emails/mentors_rotm_reminder.txt'
        send_remo_mail(subject=subject,
                       email_template=template,
                       recipients_list=[settings.REPS_MENTORS_LIST],
                       data=data)
        mentors = User.objects.filter(groups__name='Mentor')
        for mentor in mentors:
            ActionItem.create(mentor.userprofile)
Exemplo n.º 16
0
def send_rotm_nomination_reminder():
    """ Send an email reminder to all mentors.

    The first day of each month, the mentor group receives an email reminder
    in order to nominate Reps for the Rep of the month voting.
    """

    now_date = now().date()
    if (now_date.day == ROTM_REMINDER_DAY
            or waffle.switch_is_active('enable_rotm_tasks')):
        data = {'month': number2month(now_date.month)}
        subject = 'Nominate Rep of the month'
        template = 'emails/mentors_rotm_reminder.jinja'
        send_remo_mail(subject=subject,
                       email_template=template,
                       recipients_list=[settings.REPS_MENTORS_LIST],
                       data=data)
        mentors = User.objects.filter(groups__name='Mentor')
        for mentor in mentors:
            ActionItem.create(mentor.userprofile)
Exemplo n.º 17
0
def notify_event_owners_to_input_metrics():
    """Send an email to event creators.

    After an event has finished event creators are notified
    that they should input the actual metrics for the event.
    """
    start = datetime.combine(get_date(days=-1), datetime.min.time())
    end = datetime.combine(get_date(days=-1), datetime.max.time())
    events = Event.objects.filter(end__range=[start, end],
                                  has_new_metrics=True,
                                  eventmetricoutcome__outcome__isnull=True)
    events = events.distinct()

    for event in events:
        subject = ('[Reminder] Please add the actual metrics for event {0}'
                   .format(event.name))
        template = 'email/event_creator_notification_to_input_metrics.txt'
        data = {'event': event}
        send_remo_mail(subject=subject, email_template=template,
                       recipients_list=[event.owner.id], data=data)
        ActionItem.create(instance=event)
Exemplo n.º 18
0
def notify_event_owners_to_input_metrics():
    """Send an email to event creators.

    After an event has finished event creators are notified
    that they should input the actual metrics for the event.
    """
    start = datetime.combine(get_date(days=-1), datetime.min.time())
    end = datetime.combine(get_date(days=-1), datetime.max.time())
    events = Event.objects.filter(end__range=[start, end],
                                  has_new_metrics=True,
                                  eventmetricoutcome__outcome__isnull=True)
    events = events.distinct()

    for event in events:
        subject = (
            '[Reminder] Please add the actual metrics for event {0}'.format(
                event.name))
        template = 'email/event_creator_notification_to_input_metrics.txt'
        data = {'event': event}
        send_remo_mail(subject=subject,
                       email_template=template,
                       recipients_list=[event.owner.id],
                       data=data)
        ActionItem.create(instance=event)
Exemplo n.º 19
0
def update_budget_needinfo_action_items(sender, instance, action, pk_set,
                                        **kwargs):
    """Update ActionItem objects on needinfo change."""
    name = '{0} {1}'.format(NEEDINFO_ACTION, instance.summary)
    if action == 'post_remove':
        for pk in pk_set:
            ActionItem.resolve(instance=instance, user=User.objects.get(pk=pk),
                               name=name)

    if action == 'pre_clear':
        for user in instance.budget_needinfo.all():
            ActionItem.resolve(instance=instance, user=user, name=name)

    if action == 'post_add':
        ActionItem.create(instance=instance)
Exemplo n.º 20
0
    def save(self, *args, **kwargs):
        """Override save for custom functionality."""

        # Make last report notificaton date NULL on new report
        today = get_date()
        if self.pk is None and self.user.userprofile.first_report_notification:
            start = today - datetime.timedelta(weeks=4)
            end = today + datetime.timedelta(weeks=4)
            if self.report_date in daterange(start, end):
                self.user.userprofile.first_report_notification = None
                self.user.userprofile.second_report_notification = None
                self.user.userprofile.save()

        # User streaks functionality
        one_week = datetime.timedelta(7)
        current_start = self.user.userprofile.current_streak_start or None
        longest_start = self.user.userprofile.longest_streak_start or None
        longest_end = self.user.userprofile.longest_streak_end or None

        # Save the mentor of the user if no mentor is defined.
        if not self.mentor:
            self.mentor = self.user.userprofile.mentor
        # Save the country if possible
        saved_report = get_object_or_none(NGReport, id=self.id)
        if (saved_report and (saved_report.latitude != self.latitude or
                              saved_report.longitude != self.longitude)):
            country = None
            try:
                country = self.location.split(',')[-1].strip()
            except IndexError:
                pass
            if country in COUNTRIES_LIST:
                self.country = country
        super(NGReport, self).save()

        # Resolve the verified action items.
        action_item_name = u'{0} {1}'.format(VERIFY_ACTION, self.user.get_full_name())
        if self.verified_activity:
            ActionItem.resolve(instance=self,
                               user=self.mentor,
                               name=action_item_name)
        else:
            # Create all the action items, if any
            ActionItem.create(self)

        if self.is_future_report:
            return

        # If there is already a running streak and the report date
        # is within this streak, update the current streak counter.
        if (current_start and self.report_date < current_start and
                self.report_date in daterange((current_start - one_week), current_start)):
            current_start = self.report_date
        # If there isn't any current streak, and the report date
        # is within the current week, let's start the counting.
        elif not current_start and self.report_date in daterange(get_date(-7), today):
            current_start = self.report_date

        # Longest streak section
        # If longest streak already exists, let's update it.
        if longest_start and longest_end:

            # Compare the number of reports registered during
            # the current streak and the number of reports
            # during the longest streak. If current streak is bigger
            # than the previous longest streak, update the longest streak.
            longest_streak_count = NGReport.objects.filter(
                report_date__range=(longest_start, longest_end),
                user=self.user).count()
            current_streak_count = NGReport.objects.filter(
                report_date__range=(current_start, today),
                user=self.user).count()
            if current_start and current_streak_count > longest_streak_count:
                longest_start = current_start
                longest_end = today

            # This happens only when a user appends a report, dated in the
            # range of longest streak counters and it's out of the range
            # of current streak counter.
            elif self.report_date in daterange(longest_start - one_week, longest_end + one_week):
                if self.report_date < longest_start:
                    longest_start = self.report_date
                elif self.report_date > longest_end:
                    longest_end = self.report_date
        else:
            # Longest streak counters are empty, let's setup their value
            longest_start = self.report_date
            longest_end = self.report_date
        # Assign the calculated values, to user's profile.
        self.user.userprofile.current_streak_start = current_start
        self.user.userprofile.longest_streak_start = longest_start
        self.user.userprofile.longest_streak_end = longest_end
        self.user.userprofile.save()
Exemplo n.º 21
0
    def save(self, *args, **kwargs):
        """Override save for custom functionality."""

        # Make last report notificaton date NULL on new report
        today = get_date()
        if self.pk is None and self.user.userprofile.first_report_notification:
            start = today - datetime.timedelta(weeks=4)
            end = today + datetime.timedelta(weeks=4)
            if self.report_date in daterange(start, end):
                self.user.userprofile.first_report_notification = None
                self.user.userprofile.second_report_notification = None
                self.user.userprofile.save()

        # User streaks functionality
        one_week = datetime.timedelta(7)
        current_start = self.user.userprofile.current_streak_start or None
        longest_start = self.user.userprofile.longest_streak_start or None
        longest_end = self.user.userprofile.longest_streak_end or None

        # Save the mentor of the user if no mentor is defined.
        if not self.mentor:
            self.mentor = self.user.userprofile.mentor
        # Save the country if possible
        saved_report = get_object_or_none(NGReport, id=self.id)
        if (saved_report and (saved_report.latitude != self.latitude
                              or saved_report.longitude != self.longitude)):
            country = None
            try:
                country = self.location.split(',')[-1].strip()
            except IndexError:
                pass
            if country in COUNTRIES_LIST:
                self.country = country
        super(NGReport, self).save()

        # Resolve the verified action items.
        action_item_name = u'{0} {1}'.format(VERIFY_ACTION,
                                             self.user.get_full_name())
        if self.verified_activity:
            ActionItem.resolve(instance=self,
                               user=self.mentor,
                               name=action_item_name)
        else:
            # Create all the action items, if any
            ActionItem.create(self)

        if self.is_future_report:
            return

        # If there is already a running streak and the report date
        # is within this streak, update the current streak counter.
        if (current_start and self.report_date < current_start
                and self.report_date in daterange(
                    (current_start - one_week), current_start)):
            current_start = self.report_date
        # If there isn't any current streak, and the report date
        # is within the current week, let's start the counting.
        elif not current_start and self.report_date in daterange(
                get_date(-7), today):
            current_start = self.report_date

        # Longest streak section
        # If longest streak already exists, let's update it.
        if longest_start and longest_end:

            # Compare the number of reports registered during
            # the current streak and the number of reports
            # during the longest streak. If current streak is bigger
            # than the previous longest streak, update the longest streak.
            longest_streak_count = NGReport.objects.filter(
                report_date__range=(longest_start, longest_end),
                user=self.user).count()
            current_streak_count = NGReport.objects.filter(
                report_date__range=(current_start, today),
                user=self.user).count()
            if current_start and current_streak_count > longest_streak_count:
                longest_start = current_start
                longest_end = today

            # This happens only when a user appends a report, dated in the
            # range of longest streak counters and it's out of the range
            # of current streak counter.
            elif self.report_date in daterange(longest_start - one_week,
                                               longest_end + one_week):
                if self.report_date < longest_start:
                    longest_start = self.report_date
                elif self.report_date > longest_end:
                    longest_end = self.report_date
        else:
            # Longest streak counters are empty, let's setup their value
            longest_start = self.report_date
            longest_end = self.report_date
        # Assign the calculated values, to user's profile.
        self.user.userprofile.current_streak_start = current_start
        self.user.userprofile.longest_streak_start = longest_start
        self.user.userprofile.longest_streak_end = longest_end
        self.user.userprofile.save()