<commit_before>import os.path
# import re
# import magic
import PIL.Image
import logging

from django.conf import settings
from django.db import models

from toolkit.diary.models import Role

logger = logging.getLogger(__name__)

class Member(models.Model):

    # This is the primary key used in the old perl/bdb system, used as the
    # user-facing membership number (rather than using the private key). 
    # Defaults to = pk. Note; not actually a number!
    number = models.CharField(max_length=10, null=False, blank=False, editable=False)

    name = models.CharField(max_length=64, blank=False, null=False)
    email = models.CharField(max_length=64, blank=True, null=True) # , unique=True)

    address = models.CharField(max_length=128, blank=True, null=True)
    posttown = models.CharField(max_length=64, blank=True, null=True)
    postcode = models.CharField(max_length=16, blank=True, null=True)
    country = models.CharField(max_length=32, blank=True, null=True)

    website = models.CharField(max_length=128, blank=True, null=True)
    phone = models.CharField(max_length=64, blank=True, null=True)
    altphone = models.CharField(max_length=64, blank=True, null=True)
    notes = models.CharField(max_length=1024, blank=True, null=True)

    mailout = models.BooleanField(default=True, blank=False, null=False)
    mailout_failed = models.BooleanField(default=False, blank=False, null=False)

    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        db_table = 'Members'

    def __unicode__(self):
        return self.name

    def save(self, *args, **kwargs):
        # If a user number hasn't been set, save a placeholder, then re-save
        # with the private key as the number:
        set_number = False
        if self.number == '':
            set_number = True
            self.number = "?"

        result = super(Member, self).save(*args, **kwargs)

        if set_number:
            self.number = str(self.pk)
            self.save()

        return result

#    weak_email_validator = re.compile("""\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b""")
#    def weak_validate_email(self):
#        pass


class Volunteer(models.Model):

    def __init__(self, *args, **kwargs):
        super(Volunteer, self).__init__(*args, **kwargs)
        self.original_portrait = self.portrait.file.name if self.portrait else None

    member = models.OneToOneField('Member', related_name='volunteer')

    notes = models.CharField(max_length=4096, blank=True, null=True)
    active = models.BooleanField(default=True, blank=False, null=False)

    portrait = models.ImageField(upload_to="volunteers", max_length=256, null=True, blank=True)
    portrait_thumb = models.ImageField(upload_to="volunteers_thumbnails", max_length=256, null=True, blank=True, editable=False)

    # Roles
    roles = models.ManyToManyField(Role, db_table='Volunteer_Roles', blank=True)

    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        db_table = 'Volunteers'

    def save(self, *args, **kwargs):
        # Before saving, if portrait has changed:
        update_thumbnail = kwargs.pop('update_portrait_thumbnail', True)

        result = super(Volunteer, self).save(*args, **kwargs)

        logging.info(self.original_portrait)
        if self.original_portrait or (self.portrait and self.portrait.file.name != self.original_portrait):<commit_msg>Delete spurious logging<commit_after>import os.path
# import re
# import magic
import PIL.Image
import logging

from django.conf import settings
from django.db import models

from toolkit.diary.models import Role

logger = logging.getLogger(__name__)

class Member(models.Model):

    # This is the primary key used in the old perl/bdb system, used as the
    # user-facing membership number (rather than using the private key). 
    # Defaults to = pk. Note; not actually a number!
    number = models.CharField(max_length=10, null=False, blank=False, editable=False)

    name = models.CharField(max_length=64, blank=False, null=False)
    email = models.CharField(max_length=64, blank=True, null=True) # , unique=True)

    address = models.CharField(max_length=128, blank=True, null=True)
    posttown = models.CharField(max_length=64, blank=True, null=True)
    postcode = models.CharField(max_length=16, blank=True, null=True)
    country = models.CharField(max_length=32, blank=True, null=True)

    website = models.CharField(max_length=128, blank=True, null=True)
    phone = models.CharField(max_length=64, blank=True, null=True)
    altphone = models.CharField(max_length=64, blank=True, null=True)
    notes = models.CharField(max_length=1024, blank=True, null=True)

    mailout = models.BooleanField(default=True, blank=False, null=False)
    mailout_failed = models.BooleanField(default=False, blank=False, null=False)

    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        db_table = 'Members'

    def __unicode__(self):
        return self.name

    def save(self, *args, **kwargs):
        # If a user number hasn't been set, save a placeholder, then re-save
        # with the private key as the number:
        set_number = False
        if self.number == '':
            set_number = True
            self.number = "?"

        result = super(Member, self).save(*args, **kwargs)

        if set_number:
            self.number = str(self.pk)
            self.save()

        return result

#    weak_email_validator = re.compile("""\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b""")
#    def weak_validate_email(self):
#        pass


class Volunteer(models.Model):

    def __init__(self, *args, **kwargs):
        super(Volunteer, self).__init__(*args, **kwargs)
        self.original_portrait = self.portrait.file.name if self.portrait else None

    member = models.OneToOneField('Member', related_name='volunteer')

    notes = models.CharField(max_length=4096, blank=True, null=True)
    active = models.BooleanField(default=True, blank=False, null=False)

    portrait = models.ImageField(upload_to="volunteers", max_length=256, null=True, blank=True)
    portrait_thumb = models.ImageField(upload_to="volunteers_thumbnails", max_length=256, null=True, blank=True, editable=False)

    # Roles
    roles = models.ManyToManyField(Role, db_table='Volunteer_Roles', blank=True)

    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        db_table = 'Volunteers'

    def save(self, *args, **kwargs):
        # Before saving, if portrait has changed:
        update_thumbnail = kwargs.pop('update_portrait_thumbnail', True)

        result = super(Volunteer, self).save(*args, **kwargs)

        if self.original_portrait or (self.portrait and self.portrait.file.name != self.original_portrait):
{'fraction_non_alphanumeric': 0.11889414124050995, 'fraction_numerical': 0.012032660077352814, 'mean_word_length': 3.8085399449035813, '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': '3276844', 'n_tokens_mistral': 2283, 'n_tokens_neox': 2191, 'n_words': 488}