# Path: bakery/auth/models.py
# class BakeryUser(AbstractBaseUser):
#     username = models.CharField(_('Username'), max_length=50, unique=True)
#     email = models.EmailField(_('Email'), max_length=254, unique=True)
#     name = models.CharField(_('Name'), max_length=100, blank=True, null=True)
#     is_superuser = models.BooleanField(_('Superuser'), default=False)
#     is_staff = models.BooleanField(_('Staff'), default=False)
#     is_active = models.BooleanField(_('Active'), default=True)
#     is_organization = models.BooleanField(_('Organization'))
#     profile_url = models.URLField(_('Profile'), blank=True, null=True)
#     date_joined = models.DateTimeField(_('date joined'), default=timezone.now)
# 
#     objects = BakeryUserManager()
# 
#     USERNAME_FIELD = 'username'
#     REQUIRED_FIELDS = ['password']
# 
#     class Meta:
#         verbose_name = _('User')
#         verbose_name_plural = _('Users')
# 
#     def __str__(self):
#         return self.username
# 
#     def get_absolute_url(self):
#         return reverse_lazy('auth:profile', kwargs={'username': self.username})
# 
#     def get_full_name(self):
#         return self.name
# 
#     def get_short_name(self):
#         "Returns the short name for the user."
#         return self.name
# 
#     def get_display_name(self):
#         return self.name or self.username
# 
#     def get_gravatar(self):
#         return get_gravatar(self.email)
# 
#     def vote_for_cookie(self, cookie):
#         do_vote(self, cookie)
# 
#     @property
#     def candies_list(self):
#         candies_list = getattr(self, '_candies_list', [])
#         if not candies_list:
#             candies = self.candies.order_by('candy_type')
#             for candy in CANDIES:
#                 candy_type = candy[0]
#                 count = candies.filter(candy_type=candy_type).count()
#                 candies_list.append((candy, count))
#             setattr(self, '_candies_list', candies_list)
#         return candies_list
# 
# Path: bakery/utils/vcs/gh.py
# def _github_setup():
# def get_repo_from_url(url, gh_setup=github_setup):
# def get_repo_from_full_name(full_name, gh_setup=github_setup):
# def get_cookie_data_from_repo(repo):
# def filter_repo(repo, filters):
# def get_mapping_file_from_repo(repo):
# def decode_file(content_file):
# def get_content_from_content_file(content_file):
# def fork_repository(user, repo):


from django.db.models import Manager
from django.db.models.query import QuerySet
from bakery.auth.models import BakeryUser
from bakery.utils.vcs import gh
        obj, created = self.get_or_create(*args, **kwargs)

        if not created:
            fields = dict(kwargs.pop("defaults", {}))
            fields.update(kwargs)
            for key, value in fields.items():
                setattr(obj, key, value)
            obj.save()

        return obj


class CookieManager(Manager):
    use_for_related_fields = True

    def get_query_set(self):
        return CookieQuerySet(self.model)

    def update_or_create(self, *args, **kwargs):
        return self.get_query_set().update_or_create(**kwargs)

    def import_from_url(self, url):
        """Imports or updates from ``url``"""
        if 'git@github.com' in url or 'https://github.com/' in url:
            repo = gh.get_repo_from_url(url)
            return self.import_from_repo(repo)

        raise ValueError('{0} is not a recognized URL'.format(url))

    def import_from_repo(self, repo):

# Path: bakery/auth/models.py
# class BakeryUser(AbstractBaseUser):
#     username = models.CharField(_('Username'), max_length=50, unique=True)
#     email = models.EmailField(_('Email'), max_length=254, unique=True)
#     name = models.CharField(_('Name'), max_length=100, blank=True, null=True)
#     is_superuser = models.BooleanField(_('Superuser'), default=False)
#     is_staff = models.BooleanField(_('Staff'), default=False)
#     is_active = models.BooleanField(_('Active'), default=True)
#     is_organization = models.BooleanField(_('Organization'))
#     profile_url = models.URLField(_('Profile'), blank=True, null=True)
#     date_joined = models.DateTimeField(_('date joined'), default=timezone.now)
# 
#     objects = BakeryUserManager()
# 
#     USERNAME_FIELD = 'username'
#     REQUIRED_FIELDS = ['password']
# 
#     class Meta:
#         verbose_name = _('User')
#         verbose_name_plural = _('Users')
# 
#     def __str__(self):
#         return self.username
# 
#     def get_absolute_url(self):
#         return reverse_lazy('auth:profile', kwargs={'username': self.username})
# 
#     def get_full_name(self):
#         return self.name
# 
#     def get_short_name(self):
#         "Returns the short name for the user."
#         return self.name
# 
#     def get_display_name(self):
#         return self.name or self.username
# 
#     def get_gravatar(self):
#         return get_gravatar(self.email)
# 
#     def vote_for_cookie(self, cookie):
#         do_vote(self, cookie)
# 
#     @property
#     def candies_list(self):
#         candies_list = getattr(self, '_candies_list', [])
#         if not candies_list:
#             candies = self.candies.order_by('candy_type')
#             for candy in CANDIES:
#                 candy_type = candy[0]
#                 count = candies.filter(candy_type=candy_type).count()
#                 candies_list.append((candy, count))
#             setattr(self, '_candies_list', candies_list)
#         return candies_list
# 
# Path: bakery/utils/vcs/gh.py
# def _github_setup():
# def get_repo_from_url(url, gh_setup=github_setup):
# def get_repo_from_full_name(full_name, gh_setup=github_setup):
# def get_cookie_data_from_repo(repo):
# def filter_repo(repo, filters):
# def get_mapping_file_from_repo(repo):
# def decode_file(content_file):
# def get_content_from_content_file(content_file):
# def fork_repository(user, repo):


# Path: bakery/cookies/managers.py
from django.db.models import Manager
from django.db.models.query import QuerySet
from bakery.auth.models import BakeryUser
from bakery.utils.vcs import gh

        obj, created = self.get_or_create(*args, **kwargs)

        if not created:
            fields = dict(kwargs.pop("defaults", {}))
            fields.update(kwargs)
            for key, value in fields.items():
                setattr(obj, key, value)
            obj.save()

        return obj


class CookieManager(Manager):
    use_for_related_fields = True

    def get_query_set(self):
        return CookieQuerySet(self.model)

    def update_or_create(self, *args, **kwargs):
        return self.get_query_set().update_or_create(**kwargs)

    def import_from_url(self, url):
        """Imports or updates from ``url``"""
        if 'git@github.com' in url or 'https://github.com/' in url:
            repo = gh.get_repo_from_url(url)
            return self.import_from_repo(repo)

        raise ValueError('{0} is not a recognized URL'.format(url))

    def import_from_repo(self, repo):

        cookie_data = gh.get_cookie_data_from_repo(repo)