<commit_before>from django.db import models
from group.models import Group
from taggit.managers import TaggableManager
from django.utils.functional import cached_property
from django.contrib.auth.models import User

### contains all site definitions    
class Site(models.Model):
    group = models.ForeignKey(Group, related_name="sites")
    hostname = models.CharField(max_length=256, unique=True)
    last_change = models.DateTimeField(null=True)
    tags = TaggableManager(blank=True)

    def recursive_alerting(self, user):
        from alert.models import SiteAlert, TagAlert, GroupAlert

        ### is alerting enabled for this site?
        try:
            sitealert = SiteAlert.objects.get(site=self, user=user)
            return True
        except SiteAlert.DoesNotExist:
            pass

        ### is alerting enabled for the sites group?
        try:
            groupalert = GroupAlert.objects.get(group=self.group)
            return True
        except GroupAlert.DoesNotExist:
            pass

        ### is alerting enabled for any of this sites tags?
        for tag in self.tags.all():
            try:
                tagalert = TagAlert.objects.get(tag=tag, user=user)
                return True
            except TagAlert.DoesNotExist:
                pass

        ### neither site, group or tag alerting for this site
        return False

    def get_alert_users(self):
        from alert.models import SiteAlert, TagAlert, GroupAlert
        sitealertusers = User.objects.filter(id__in=SiteAlert.objects.filter(site=self).values('user'))
        groupalertusers = User.objects.filter(id__in=GroupAlert.objects.filter(group=self.group).values('user'))
        tagalertusers = User.objects.filter(id__in=TagAlert.objects.filter(tag__name__in=self.tags.all()).values('user'))
        alertusers = sitealertusers | groupalertusers | tagalertusers
        return alertusers.distinct()

    def __unicode__(self):
        return "%s (%s)" % (self.hostname, self.group)

<commit_msg>fix bug in tag alerting<commit_after>from django.db import models
from group.models import Group
from taggit.managers import TaggableManager
from django.utils.functional import cached_property
from django.contrib.auth.models import User

### contains all site definitions    
class Site(models.Model):
    group = models.ForeignKey(Group, related_name="sites")
    hostname = models.CharField(max_length=256, unique=True)
    last_change = models.DateTimeField(null=True)
    tags = TaggableManager(blank=True)

    def recursive_alerting(self, user):
        from alert.models import SiteAlert, TagAlert, GroupAlert

        ### is alerting enabled for this site?
        try:
            sitealert = SiteAlert.objects.get(site=self, user=user)
            return True
        except SiteAlert.DoesNotExist:
            pass

        ### is alerting enabled for the sites group?
        try:
            groupalert = GroupAlert.objects.get(group=self.group)
            return True
        except GroupAlert.DoesNotExist:
            pass

        ### is alerting enabled for any of this sites tags?
        for tag in self.tags.all():
            try:
                tagalert = TagAlert.objects.get(tag=tag, user=user)
                return True
            except TagAlert.DoesNotExist:
                pass

        ### neither site, group or tag alerting for this site
        return False

    def get_alert_users(self):
        from alert.models import SiteAlert, TagAlert, GroupAlert
        sitealertusers = User.objects.filter(id__in=SiteAlert.objects.filter(site=self).values('user'))
        groupalertusers = User.objects.filter(id__in=GroupAlert.objects.filter(group=self.group).values('user'))
        tagalertusers = User.objects.filter(id__in=TagAlert.objects.filter(tag__in=[tag.id for tag in site.tags.all()]).values('user'))
        alertusers = sitealertusers | groupalertusers | tagalertusers
        return alertusers.distinct()

    def __unicode__(self):
        return "%s (%s)" % (self.hostname, self.group)


{'fraction_non_alphanumeric': 0.09057255676209279, 'fraction_numerical': 0.0014807502467917078, 'mean_word_length': 2.7878504672897195, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '772555', 'n_tokens_mistral': 1113, 'n_tokens_neox': 1081, 'n_words': 278}