<commit_before>from django.contrib import admin
from django.contrib.contenttypes import generic
from django.db import models

from pennyblack import settings
from pennyblack.options import NewsletterReceiverMixin, JobUnitMixin, JobUnitAdmin

import datetime

class NewsletterSubscriberManager(models.Manager):
    """
    Custom manager for NewsletterSubscriber to provide extra functionality
    """
    use_for_related_fields = True
    
    def get_or_add(self,email, **kwargs):
        """
        Gets a subscriber, if he doesn't exist it creates him.
        """
        try:
            return self.get(email__iexact=email)
        except self.model.DoesNotExist:
            return self.create(email=email.lower(), **kwargs)
    
    def active(self):
        """
        Gives only the active subscribers
        """
        return self.filter(is_active=True)
        
newsletter_subscriber_manager = NewsletterSubscriberManager()

class NewsletterSubscriber(models.Model, NewsletterReceiverMixin):
    """
    A generic newsletter subscriber
    """
    # from pennyblack.models.mail import Mail
    email = models.EmailField(verbose_name="Email address")
    groups = models.ManyToManyField('subscriber.SubscriberGroup',
        verbose_name="Groups", related_name='subscribers')<commit_msg>make emailaddress in subscriber module unique<commit_after>from django.contrib import admin
from django.contrib.contenttypes import generic
from django.db import models

from pennyblack import settings
from pennyblack.options import NewsletterReceiverMixin, JobUnitMixin, JobUnitAdmin

import datetime

class NewsletterSubscriberManager(models.Manager):
    """
    Custom manager for NewsletterSubscriber to provide extra functionality
    """
    use_for_related_fields = True
    
    def get_or_add(self,email, **kwargs):
        """
        Gets a subscriber, if he doesn't exist it creates him.
        """
        try:
            return self.get(email__iexact=email)
        except self.model.DoesNotExist:
            return self.create(email=email.lower(), **kwargs)
    
    def active(self):
        """
        Gives only the active subscribers
        """
        return self.filter(is_active=True)
        
newsletter_subscriber_manager = NewsletterSubscriberManager()

class NewsletterSubscriber(models.Model, NewsletterReceiverMixin):
    """
    A generic newsletter subscriber
    """
    # from pennyblack.models.mail import Mail
    email = models.EmailField(verbose_name="Email address", unique=True)
    groups = models.ManyToManyField('subscriber.SubscriberGroup',
        verbose_name="Groups", related_name='subscribers')
{'fraction_non_alphanumeric': 0.08154020385050963, 'fraction_numerical': 0.0, 'mean_word_length': 3.483925549915398, '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': '916541', 'n_tokens_mistral': 706, 'n_tokens_neox': 686, 'n_words': 177}