# Path: authentication/models.py
# class User(AbstractBaseUser, PermissionsMixin):
#     main_character_id = models.PositiveIntegerField(primary_key=True)
#     email = models.EmailField(max_length=255, null=True, blank=True)
#     is_staff = models.BooleanField(default=False)
#     is_active = models.BooleanField(default=False)
# 
#     USERNAME_FIELD = 'main_character_id'
#     REQUIRED_FIELDS = []
# 
#     objects = UserManager()
# 
#     class Meta:
#         verbose_name = 'user'
#         verbose_name_plural = 'users'
# 
#     @property
#     def main_character(self):
#         if self.characters.filter(id=self.main_character_id).exists():
#             return self.characters.get(id=self.main_character_id)
#         elif EVECharacter.objects.filter(id=self.main_character_id).exists():
#             logger.warn("User with main character ID %s has detached main character model" % self.get_full_name())
#             return EVECharacter.objects.get(id=self.main_character_id)
#         else:
#             return None
# 
#     def get_full_name(self):
#         return str(self.main_character_id)
#     def get_short_name(self):
#         if self.main_character:
#             return str(self.main_character)
#         else:
#             return self.get_full_name()
# 
#     def __unicode__(self):
#         if self.main_character:
#             return str(self.main_character).encode('utf-8')
#         else:
#             logger.debug("Missing character model for user with main character id %s, returning id as __unicode__." % self.main_character_id)
#             return self.get_short_name().encode('utf-8')
# 
# Path: access/models.py
# def get_rule_ct_filter():
#     RULE_CONTENT_TYPES = [
#         ContentType.objects.get_for_model(AllianceAccessRule),
#         ContentType.objects.get_for_model(CorpAccessRule),
#         ContentType.objects.get_for_model(CharacterAccessRule),
#         ContentType.objects.get_for_model(ContactAccess),
#     ]
# 
#     return {'pk__in': [a.pk for a in RULE_CONTENT_TYPES]}


from django.contrib.auth.models import Group
from authentication.models import User
from django.utils import timezone
from django.db import models
from managers import GroupApplicationManager, ExtendedGroupManager
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType
from access.models import get_rule_ct_filter
        return False

    def can_demote_admin(self, user, admin):
        if user == self.owner and admin in self.admins.all():
            return True
        elif user == admin and user in self.admins.all():
            return True
        return False

    def can_leave_group(self, user):
        if user == self.owner:
            return False
        elif user in self.admins.all():
            return False
        return True

    def can_remove_member(self, user, member):
        if member == self.owner:
            return False
        elif member in self.admins.all():
            return False
        elif user == self.owner or user in self.admins.all():
            return True

    @property
    def basic_members(self):
        return [u for u in self.group.user_set.all() if u != self.owner and u not in self.admins.all()]

class GroupApplication(models.Model):
    extended_group = models.ForeignKey(ExtendedGroup, on_delete=models.CASCADE, related_name='applications')

# Path: authentication/models.py
# class User(AbstractBaseUser, PermissionsMixin):
#     main_character_id = models.PositiveIntegerField(primary_key=True)
#     email = models.EmailField(max_length=255, null=True, blank=True)
#     is_staff = models.BooleanField(default=False)
#     is_active = models.BooleanField(default=False)
# 
#     USERNAME_FIELD = 'main_character_id'
#     REQUIRED_FIELDS = []
# 
#     objects = UserManager()
# 
#     class Meta:
#         verbose_name = 'user'
#         verbose_name_plural = 'users'
# 
#     @property
#     def main_character(self):
#         if self.characters.filter(id=self.main_character_id).exists():
#             return self.characters.get(id=self.main_character_id)
#         elif EVECharacter.objects.filter(id=self.main_character_id).exists():
#             logger.warn("User with main character ID %s has detached main character model" % self.get_full_name())
#             return EVECharacter.objects.get(id=self.main_character_id)
#         else:
#             return None
# 
#     def get_full_name(self):
#         return str(self.main_character_id)
#     def get_short_name(self):
#         if self.main_character:
#             return str(self.main_character)
#         else:
#             return self.get_full_name()
# 
#     def __unicode__(self):
#         if self.main_character:
#             return str(self.main_character).encode('utf-8')
#         else:
#             logger.debug("Missing character model for user with main character id %s, returning id as __unicode__." % self.main_character_id)
#             return self.get_short_name().encode('utf-8')
# 
# Path: access/models.py
# def get_rule_ct_filter():
#     RULE_CONTENT_TYPES = [
#         ContentType.objects.get_for_model(AllianceAccessRule),
#         ContentType.objects.get_for_model(CorpAccessRule),
#         ContentType.objects.get_for_model(CharacterAccessRule),
#         ContentType.objects.get_for_model(ContactAccess),
#     ]
# 
#     return {'pk__in': [a.pk for a in RULE_CONTENT_TYPES]}


# Path: groupmanagement/models.py
from django.contrib.auth.models import Group
from authentication.models import User
from django.utils import timezone
from django.db import models
from managers import GroupApplicationManager, ExtendedGroupManager
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType
from access.models import get_rule_ct_filter

        return False

    def can_demote_admin(self, user, admin):
        if user == self.owner and admin in self.admins.all():
            return True
        elif user == admin and user in self.admins.all():
            return True
        return False

    def can_leave_group(self, user):
        if user == self.owner:
            return False
        elif user in self.admins.all():
            return False
        return True

    def can_remove_member(self, user, member):
        if member == self.owner:
            return False
        elif member in self.admins.all():
            return False
        elif user == self.owner or user in self.admins.all():
            return True

    @property
    def basic_members(self):
        return [u for u in self.group.user_set.all() if u != self.owner and u not in self.admins.all()]

class GroupApplication(models.Model):
    extended_group = models.ForeignKey(ExtendedGroup, on_delete=models.CASCADE, related_name='applications')

    user = models.ForeignKey(User, on_delete=models.CASCADE)