<commit_before>from django.db import models
from django.db.models import signals
from django.contrib.auth.models import User, UserManager, Group
from eve_api.models import EVEAccount

from services import get_api

## Exceptions

class CorporateOnlyService(Exception):
    pass

class ExistingUser(Exception):
    pass

## Models

class SSOUser(models.Model):
    """ Extended SSO User Profile options """

    user = models.ForeignKey(User, unique=True, related_name='profile')

    default_service_passwd = models.CharField(max_length=200)
    default_service_username = models.CharField(max_length=200, blank=True)
    
    website = models.CharField(max_length=200, blank=True)
    aim = models.CharField(max_length=64, blank=True)
    msn = models.CharField(max_length=200, blank=True)
    icq = models.CharField(max_length=15, blank=True)
    xmpp = models.CharField(max_length=200, blank=True)

    def update_access(self):
        """ Steps through each Eve API registered to the user and updates their group 
            access accordingly """
        self.user.groups.clear()
        for eacc in EVEAccount.objects.filter(user=self.user):
            for char in eacc.characters.all():
                if char.corporation.group:
                    self.user.groups.add(char.corporation.group)
                

    def __str__(self):
        return self.user.__str__()

    @staticmethod
    def create_user_profile(sender, instance, created, **kwargs):   
        print 'trigger', instance
        if created:   
            profile, created = SSOUser.objects.get_or_create(user=instance) 

signals.post_save.connect(SSOUser.create_user_profile, sender=User)

class Service(models.Model):
    name = models.CharField(max_length=200)
    url = models.CharField(max_length=200, blank=True)
    active = models.BooleanField(default=True)<commit_msg>Fixed update_access(), now doesn't kill access to non-corp groups<commit_after>from django.db import models
from django.db.models import signals
from django.contrib.auth.models import User, UserManager, Group
from eve_api.models import EVEAccount, EVEPlayerCorporation

from services import get_api

## Exceptions

class CorporateOnlyService(Exception):
    pass

class ExistingUser(Exception):
    pass

## Models

class SSOUser(models.Model):
    """ Extended SSO User Profile options """

    user = models.ForeignKey(User, unique=True, related_name='profile')

    default_service_passwd = models.CharField(max_length=200)
    default_service_username = models.CharField(max_length=200, blank=True)
    
    website = models.CharField(max_length=200, blank=True)
    aim = models.CharField(max_length=64, blank=True)
    msn = models.CharField(max_length=200, blank=True)
    icq = models.CharField(max_length=15, blank=True)
    xmpp = models.CharField(max_length=200, blank=True)

    def update_access(self):
        """ Steps through each Eve API registered to the user and updates their group 
            access accordingly """

        # Create a list of all Corp groups
        corpgroups = []
        for corp in EVEPlayerCorporation.objects.all():
            if corp.group:
                corpgroups.append(corp.group)  
        
        # Create a list of Char groups
        chargroups = []
        for eacc in EVEAccount.objects.filter(user=self.user):
            for char in eacc.characters.all():
                if char.corporation.group:
                    chargroups.append(char.corporation.group)
                
        # Generate the list of groups to add/remove
        delgroups = set(set(self.user.groups.all()) & set(corpgroups)) - set(chargroups)
        addgroups = set(chargroups) - set(set(self.user.groups.all()) & set(corpgroups))
        
        print "Del:", delgroups
        for g in delgroups:
            self.user.groups.remove(g)

        print "Add:", addgroups
        for g in addgroups:
            self.user.groups.add(g)

    def __str__(self):
        return self.user.__str__()

    @staticmethod
    def create_user_profile(sender, instance, created, **kwargs):   
        print 'trigger', instance
        if created:   
            profile, created = SSOUser.objects.get_or_create(user=instance) 

signals.post_save.connect(SSOUser.create_user_profile, sender=User)

class Service(models.Model):
    name = models.CharField(max_length=200)
    url = models.CharField(max_length=200, blank=True)
    active = models.BooleanField(default=True)
{'fraction_non_alphanumeric': 0.09690444145356662, 'fraction_numerical': 0.011215791834903545, 'mean_word_length': 3.1325301204819276, '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': '1012774', 'n_tokens_mistral': 1356, 'n_tokens_neox': 1277, 'n_words': 298}