Ejemplo n.º 1
0
    def clear_labels(self):
        """
        Removes all labels from this message
        """
        from casepro.statistics.models import DailyCount, datetime_to_date

        day = datetime_to_date(self.created_on, self.org)
        for label in self.labels.all():
            DailyCount.record_removal(day, DailyCount.TYPE_INCOMING, label)

        Labelling.objects.filter(message=self).delete()
Ejemplo n.º 2
0
    def unlabel(self, *labels):
        """
        Removes the given labels from this message
        """
        from casepro.statistics.models import DailyCount, datetime_to_date

        existing_labellings = Labelling.objects.filter(
            message=self, label__in=labels).select_related("label")

        day = datetime_to_date(self.created_on, self.org)
        for labelling in existing_labellings:
            DailyCount.record_removal(day, DailyCount.TYPE_INCOMING,
                                      labelling.label)

        Labelling.objects.filter(
            id__in=[l.id for l in existing_labellings]).delete()