# Path: teamwork_example/wiki/models.py
# class Document(models.Model):
#     name = models.CharField(max_length=80, unique=True)
#     content = models.TextField(blank=True, null=True)
#     site = models.ForeignKey(Site, blank=True, null=True)
#     team = models.ForeignKey(Team, blank=True, null=True)
#     parent = models.ForeignKey('self', blank=True, null=True)
#     creator = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True)
# 
#     objects = DocumentManager()
# 
#     class Meta:
#         permissions = (
#             ('view_document', 'Can view document'),
#             ('add_document_child', 'Can add child document'),
#             ('frob', 'Can frobulate documents'),
#             ('xyzzy', 'Can xyzzy documents'),
#             ('hello', 'Can hello documents'),
#             ('quux', 'Can quuxify documents'),
#         )
# 
#     def __unicode__(self):
#         return self.name
# 
#     def get_absolute_url(self):
#         """Build the absolute URL to this document from its full path"""
#         return reverse('wiki.views.view', args=[self.name])
# 
#     def get_owner_user(self):
#         return self.creator
# 
#     def filter_permissions(self, user, permissions):
#         """Filter permissions with custom logic"""
#         if ('quux' in user.username):
#             if permissions is None:
#                 permissions = set()
#             permissions.add('wiki.quux')
#         return permissions
# 
#     def get_permission_parents(self):
#         """Build a list of parents from self to root"""
#         curr, parents = self, []
#         while curr.parent:
#             curr = curr.parent
#             parents.append(curr)
#         return parents
# 
#     def get_children(self):
#         return Document.objects.filter(parent=self).all()
# 
# Path: teamwork/models.py
# class Team(models.Model):
#     """
#     Organizational unit for a set of users with assigned roles
#     """
#     name = models.CharField(
#         _("name"), max_length=128, editable=True, unique=True,
#         db_index=True)
#     description = models.TextField(
#         _("Description of intended use"), null=True, blank=True)
#     founder = models.ForeignKey(
#         settings.AUTH_USER_MODEL, db_index=True, blank=True, null=True)
# 
#     created = models.DateTimeField(auto_now_add=True, db_index=True)
#     modified = models.DateTimeField(auto_now=True, null=True, db_index=True)
# 
#     objects = TeamManager()
# 
#     class Meta:
#         permissions = (
#             ('view_team', 'Can view team'),
#         )
# 
#     def __unicode__(self):
#         return self.name
# 
#     @property
#     def team(self):
#         return self
# 
#     def has_user(self, user):
#         """Determine whether the given user is a member of this team"""
#         # TODO: founder is not considered a member without an associated role
#         hits = (Role.users.through.objects
#                     .filter(role__team=self, user=user)).count()
#         return hits > 0
# 
#     def filter_permissions(self, user, permissions):
#         """Filter permissions with custom logic"""
#         if user == self.founder:
#             # Founder is admin-equivalent for the team
#             if permissions is None:
#                 permissions = set()
#             for perm, desc in self._meta.permissions:
#                 permissions.add('teamwork.%s' % perm)
#         return permissions
# 
#     def get_all_permissions(self, user):
#         """Get all Permissions applied to this User based on assigned Roles"""
#         role_ids = (Role.users.through.objects
#                         .filter(user=user, role__team=self)
#                         .values('role'))
#         return (p.permission for p in
#                 Role.permissions.through.objects
#                     .filter(role__in=role_ids)
#                     .select_related())


from django.shortcuts import render
from django.contrib.auth import get_user_model
from teamwork_example.wiki.models import Document
from teamwork.models import Team


def index(request):
    users = get_user_model().objects.all()
    documents = Document.objects.filter(parent=None).all()
    teams = Team.objects.all()
    return render(request, 'base/index.html', dict(

# Path: teamwork_example/wiki/models.py
# class Document(models.Model):
#     name = models.CharField(max_length=80, unique=True)
#     content = models.TextField(blank=True, null=True)
#     site = models.ForeignKey(Site, blank=True, null=True)
#     team = models.ForeignKey(Team, blank=True, null=True)
#     parent = models.ForeignKey('self', blank=True, null=True)
#     creator = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True)
# 
#     objects = DocumentManager()
# 
#     class Meta:
#         permissions = (
#             ('view_document', 'Can view document'),
#             ('add_document_child', 'Can add child document'),
#             ('frob', 'Can frobulate documents'),
#             ('xyzzy', 'Can xyzzy documents'),
#             ('hello', 'Can hello documents'),
#             ('quux', 'Can quuxify documents'),
#         )
# 
#     def __unicode__(self):
#         return self.name
# 
#     def get_absolute_url(self):
#         """Build the absolute URL to this document from its full path"""
#         return reverse('wiki.views.view', args=[self.name])
# 
#     def get_owner_user(self):
#         return self.creator
# 
#     def filter_permissions(self, user, permissions):
#         """Filter permissions with custom logic"""
#         if ('quux' in user.username):
#             if permissions is None:
#                 permissions = set()
#             permissions.add('wiki.quux')
#         return permissions
# 
#     def get_permission_parents(self):
#         """Build a list of parents from self to root"""
#         curr, parents = self, []
#         while curr.parent:
#             curr = curr.parent
#             parents.append(curr)
#         return parents
# 
#     def get_children(self):
#         return Document.objects.filter(parent=self).all()
# 
# Path: teamwork/models.py
# class Team(models.Model):
#     """
#     Organizational unit for a set of users with assigned roles
#     """
#     name = models.CharField(
#         _("name"), max_length=128, editable=True, unique=True,
#         db_index=True)
#     description = models.TextField(
#         _("Description of intended use"), null=True, blank=True)
#     founder = models.ForeignKey(
#         settings.AUTH_USER_MODEL, db_index=True, blank=True, null=True)
# 
#     created = models.DateTimeField(auto_now_add=True, db_index=True)
#     modified = models.DateTimeField(auto_now=True, null=True, db_index=True)
# 
#     objects = TeamManager()
# 
#     class Meta:
#         permissions = (
#             ('view_team', 'Can view team'),
#         )
# 
#     def __unicode__(self):
#         return self.name
# 
#     @property
#     def team(self):
#         return self
# 
#     def has_user(self, user):
#         """Determine whether the given user is a member of this team"""
#         # TODO: founder is not considered a member without an associated role
#         hits = (Role.users.through.objects
#                     .filter(role__team=self, user=user)).count()
#         return hits > 0
# 
#     def filter_permissions(self, user, permissions):
#         """Filter permissions with custom logic"""
#         if user == self.founder:
#             # Founder is admin-equivalent for the team
#             if permissions is None:
#                 permissions = set()
#             for perm, desc in self._meta.permissions:
#                 permissions.add('teamwork.%s' % perm)
#         return permissions
# 
#     def get_all_permissions(self, user):
#         """Get all Permissions applied to this User based on assigned Roles"""
#         role_ids = (Role.users.through.objects
#                         .filter(user=user, role__team=self)
#                         .values('role'))
#         return (p.permission for p in
#                 Role.permissions.through.objects
#                     .filter(role__in=role_ids)
#                     .select_related())


# Path: teamwork_example/base/views.py
from django.shortcuts import render
from django.contrib.auth import get_user_model
from teamwork_example.wiki.models import Document
from teamwork.models import Team



def index(request):
    users = get_user_model().objects.all()
    documents = Document.objects.filter(parent=None).all()
    teams = Team.objects.all()
    return render(request, 'base/index.html', dict(

        users=users, documents=documents, teams=teams