コード例 #1
0
ファイル: models.py プロジェクト: MichaelKohler/remo
    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)
コード例 #2
0
ファイル: models.py プロジェクト: theparadoxer02/remo
    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)
コード例 #3
0
ファイル: models.py プロジェクト: MichaelKohler/remo
    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)
コード例 #4
0
ファイル: models.py プロジェクト: yomanpatil/remo
    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)
コード例 #5
0
ファイル: models.py プロジェクト: mozillach/remo
    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)
コード例 #6
0
ファイル: models.py プロジェクト: caktus/remo
    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
コード例 #7
0
ファイル: models.py プロジェクト: caktus/remo
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)
コード例 #8
0
ファイル: models.py プロジェクト: Josespaul/remo
    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()
コード例 #9
0
ファイル: models.py プロジェクト: sachithamh/remo
    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()