# Path: competencies/views.py
# def organization(request, organization_id):
#     """Displays subject areas and subdiscipline areas for a given organization."""
#     organization = Organization.objects.get(id=organization_id)
#     editors = organization.editors.all()
#     if organization.subjectarea_set.all():
#         can_fork = False
#     else:
#         can_fork = True
#     kwargs = get_visibility_filter(request.user, organization)
#     sas = organization.subjectarea_set.filter(**kwargs)
#     sdas = [sda for sa in sas for sda in sa.subdisciplinearea_set.filter(**kwargs)]    
#     return render_to_response('competencies/organization.html',
#                               {'organization': organization, 'subject_areas': sas,
#                                'sdas': sdas, 'can_fork': can_fork,
#                                'editors': editors,
#                                },
#                               context_instance=RequestContext(request))
# 
# Path: competencies/my_admin.py
# def add_userprofile(user):
# def initialize_data():
# def build_test_schools(num_elements=2):
# 
# Path: competencies/utils.py
# def cascade_visibility_down(element, visibility_mode):
# def cascade_public_up(element):
# def fork_organization(forking_org, original_org):
# 
# Path: users/models.py
# class UserProfile(models.Model):
#     """Was here to manage m2m relation to Organization."""
#     # Keeping this, because I'll store more information about users at some point.
#     user = models.OneToOneField(User)


from random import choice
from django.test import TestCase
from django.test.client import Client
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User
from competencies.models import *
from competencies.views import organization
from competencies import my_admin, utils
from users.models import UserProfile
            else:
                self.assertFalse(org in response.context['my_organizations'])

            # Make sure can edit org is in editor_orgs
            # Make sure non edit org is not in editor_orgs
            if (self.test_user_0 in org.editors.all()
                and org.owner != self.test_user_0):
                self.assertTrue(org in response.context['editor_organizations'])
            else:
                self.assertFalse(org in response.context['editor_organizations'])

            # Make sure private org is not in public orgs
            if org.public:
                self.assertTrue(org in response.context['public_organizations'])
            else:
                self.assertFalse(org in response.context['public_organizations'])


    def test_organization_view_logged_in(self):
        """Organization page lists subject areas and subdiscipline areas for that organization."""
        self.build_to_sas()
        
        self.client.login(username='testuser0', password='pw')

        for organization_num, organization in enumerate(self.test_organizations):
            test_url = reverse('competencies:organization', args=(organization.id,))
            response = self.client.get(test_url)
            self.assertEqual(response.status_code, 200)

            # For now, all users can see the names of all organizations.

# Path: competencies/views.py
# def organization(request, organization_id):
#     """Displays subject areas and subdiscipline areas for a given organization."""
#     organization = Organization.objects.get(id=organization_id)
#     editors = organization.editors.all()
#     if organization.subjectarea_set.all():
#         can_fork = False
#     else:
#         can_fork = True
#     kwargs = get_visibility_filter(request.user, organization)
#     sas = organization.subjectarea_set.filter(**kwargs)
#     sdas = [sda for sa in sas for sda in sa.subdisciplinearea_set.filter(**kwargs)]    
#     return render_to_response('competencies/organization.html',
#                               {'organization': organization, 'subject_areas': sas,
#                                'sdas': sdas, 'can_fork': can_fork,
#                                'editors': editors,
#                                },
#                               context_instance=RequestContext(request))
# 
# Path: competencies/my_admin.py
# def add_userprofile(user):
# def initialize_data():
# def build_test_schools(num_elements=2):
# 
# Path: competencies/utils.py
# def cascade_visibility_down(element, visibility_mode):
# def cascade_public_up(element):
# def fork_organization(forking_org, original_org):
# 
# Path: users/models.py
# class UserProfile(models.Model):
#     """Was here to manage m2m relation to Organization."""
#     # Keeping this, because I'll store more information about users at some point.
#     user = models.OneToOneField(User)


# Path: competencies/tests/test_views.py
from random import choice
from django.test import TestCase
from django.test.client import Client
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User
from competencies.models import *
from competencies.views import organization
from competencies import my_admin, utils
from users.models import UserProfile

            else:
                self.assertFalse(org in response.context['my_organizations'])

            # Make sure can edit org is in editor_orgs
            # Make sure non edit org is not in editor_orgs
            if (self.test_user_0 in org.editors.all()
                and org.owner != self.test_user_0):
                self.assertTrue(org in response.context['editor_organizations'])
            else:
                self.assertFalse(org in response.context['editor_organizations'])

            # Make sure private org is not in public orgs
            if org.public:
                self.assertTrue(org in response.context['public_organizations'])
            else:
                self.assertFalse(org in response.context['public_organizations'])


    def test_organization_view_logged_in(self):
        """Organization page lists subject areas and subdiscipline areas for that organization."""
        self.build_to_sas()
        
        self.client.login(username='testuser0', password='pw')

        for organization_num, organization in enumerate(self.test_organizations):
            test_url = reverse('competencies:organization', args=(organization.id,))
            response = self.client.get(test_url)
            self.assertEqual(response.status_code, 200)

            # For now, all users can see the names of all organizations.

            self.assertEqual(organization, response.context['organization'])