Skip to content

Commit

Permalink
Merge pull request #1829 from 18F/nmb/1002-18f-coe-special
Browse files Browse the repository at this point in the history
Show both 18F and CoE projects on timecard entry page
  • Loading branch information
neilmb authored Nov 7, 2024
2 parents af7ebdb + ea2dbfe commit 344605f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
17 changes: 16 additions & 1 deletion tock/hours/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,9 @@ def test_project_choice_filtering(self):
org_coe = Organization.objects.create(name='CoE')
org_coe.save()

org_other = Organization.objects.create(name='Other')
org_other.save()

accounting_code = AccountingCode.objects.get(pk=1)

project_18f = Project.objects.create(
Expand All @@ -527,6 +530,13 @@ def test_project_choice_filtering(self):
)
project_coe.save()

project_other = Project.objects.create(
name='a project with a non-18F/CoE org',
accounting_code=accounting_code,
organization=org_other
)
project_other.save()

project_none = Project.objects.create(
name='a project with no org assignment',
accounting_code=accounting_code,
Expand All @@ -553,18 +563,23 @@ def test_project_choice_filtering(self):

project_18f_found = False
project_coe_found = False
project_other_found = False
project_none_found = False
str_formset = str(response.context['formset']).split('\n')
for line in str_formset:
if line.find(f'option value="{project_18f.id}"') > 0:
project_18f_found = True
if line.find(f'option value="{project_coe.id}"') > 0:
project_coe_found = True
if line.find(f'option value="{project_other.id}"') > 0:
project_other_found = True
if line.find(f'option value="{project_none.id}"') > 0:
project_none_found = True

self.assertTrue(project_18f_found)
self.assertFalse(project_coe_found)
# special cased to now show CoE projects too!!
self.assertTrue(project_coe_found)
self.assertFalse(project_other_found)
self.assertTrue(project_none_found)

def test_holiday_prefill(self):
Expand Down
13 changes: 12 additions & 1 deletion tock/hours/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
TimecardForm, TimecardFormSet, projects_as_choices,
timecard_formset_factory)
from .models import (Project, ReportingPeriod, Timecard, TimecardNote,
TimecardObject, TimecardPrefillData)
TimecardObject, TimecardPrefillData, Organization)


class BulkTimecardSerializer(serializers.Serializer):
Expand Down Expand Up @@ -496,6 +496,17 @@ def get_context_data(self, **kwargs):
# already-generated choices. Ideally we should be passing these
# into the formset constructor.
projects = reporting_period.get_projects().filter(Q(organization=self.request.user.user_data.organization) | Q(organization=None))

# 18F and CoE need to see each others projects
special_orgs = Organization.objects.filter(Q(name="18F") | Q(name="CoE"))
if (self.request.user.user_data.organization in special_orgs):
# special case: for users in the 18F or CoE organizations, show
# projects for both organizations
projects = reporting_period.get_projects().filter(
Q(organization__in=special_orgs)
| Q(organization=None)
)

choices = projects_as_choices(projects)

for form in formset.forms:
Expand Down

0 comments on commit 344605f

Please sign in to comment.