Skip to content
This repository was archived by the owner on Nov 6, 2025. It is now read-only.

Commit 344605f

Browse files
authored
Merge pull request #1829 from 18F/nmb/1002-18f-coe-special
Show both 18F and CoE projects on timecard entry page
2 parents af7ebdb + ea2dbfe commit 344605f

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

tock/hours/tests/test_views.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,9 @@ def test_project_choice_filtering(self):
511511
org_coe = Organization.objects.create(name='CoE')
512512
org_coe.save()
513513

514+
org_other = Organization.objects.create(name='Other')
515+
org_other.save()
516+
514517
accounting_code = AccountingCode.objects.get(pk=1)
515518

516519
project_18f = Project.objects.create(
@@ -527,6 +530,13 @@ def test_project_choice_filtering(self):
527530
)
528531
project_coe.save()
529532

533+
project_other = Project.objects.create(
534+
name='a project with a non-18F/CoE org',
535+
accounting_code=accounting_code,
536+
organization=org_other
537+
)
538+
project_other.save()
539+
530540
project_none = Project.objects.create(
531541
name='a project with no org assignment',
532542
accounting_code=accounting_code,
@@ -553,18 +563,23 @@ def test_project_choice_filtering(self):
553563

554564
project_18f_found = False
555565
project_coe_found = False
566+
project_other_found = False
556567
project_none_found = False
557568
str_formset = str(response.context['formset']).split('\n')
558569
for line in str_formset:
559570
if line.find(f'option value="{project_18f.id}"') > 0:
560571
project_18f_found = True
561572
if line.find(f'option value="{project_coe.id}"') > 0:
562573
project_coe_found = True
574+
if line.find(f'option value="{project_other.id}"') > 0:
575+
project_other_found = True
563576
if line.find(f'option value="{project_none.id}"') > 0:
564577
project_none_found = True
565578

566579
self.assertTrue(project_18f_found)
567-
self.assertFalse(project_coe_found)
580+
# special cased to now show CoE projects too!!
581+
self.assertTrue(project_coe_found)
582+
self.assertFalse(project_other_found)
568583
self.assertTrue(project_none_found)
569584

570585
def test_holiday_prefill(self):

tock/hours/views.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
TimecardForm, TimecardFormSet, projects_as_choices,
3232
timecard_formset_factory)
3333
from .models import (Project, ReportingPeriod, Timecard, TimecardNote,
34-
TimecardObject, TimecardPrefillData)
34+
TimecardObject, TimecardPrefillData, Organization)
3535

3636

3737
class BulkTimecardSerializer(serializers.Serializer):
@@ -496,6 +496,17 @@ def get_context_data(self, **kwargs):
496496
# already-generated choices. Ideally we should be passing these
497497
# into the formset constructor.
498498
projects = reporting_period.get_projects().filter(Q(organization=self.request.user.user_data.organization) | Q(organization=None))
499+
500+
# 18F and CoE need to see each others projects
501+
special_orgs = Organization.objects.filter(Q(name="18F") | Q(name="CoE"))
502+
if (self.request.user.user_data.organization in special_orgs):
503+
# special case: for users in the 18F or CoE organizations, show
504+
# projects for both organizations
505+
projects = reporting_period.get_projects().filter(
506+
Q(organization__in=special_orgs)
507+
| Q(organization=None)
508+
)
509+
499510
choices = projects_as_choices(projects)
500511

501512
for form in formset.forms:

0 commit comments

Comments
 (0)