Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix current_position_nonexec filter so it only filters out current exec positions, not past #373

Merged
merged 2 commits into from
Aug 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions cdhweb/people/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ def project_manager_years(self):
def _current_position_query(self):
# query to find a person with a current cdh position
# person *has* a position and it has no end date or date after today
return models.Q(positions__isnull=False) & (
today = date.today()
return models.Q(positions__start_date__lte=today) & (
models.Q(positions__end_date__isnull=True)
| models.Q(positions__end_date__gte=date.today())
)
Comment on lines 178 to 185
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this get used elsewhere? seems like it'd affect other things too (and glad we fixed it!)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it gets used in multiple places, which is why we had a method for it. Yeah, not sure how we missed that one (although it's an edge case for sure)

Expand Down Expand Up @@ -220,10 +221,12 @@ def current_position(self):

def current_position_nonexec(self):
"""Return profiles for users with a current position, excluding
executive committee positions."""
return self.filter(
models.Q(self._current_position_query())
& ~models.Q(positions__title__title__in=self.exec_committee_titles)
current executive committee positions."""
cpq = self._current_position_query()
return (
self.filter(cpq)
.annotate(current_position_title=models.F("positions__title__title"))
.exclude(current_position_title__in=self.exec_committee_titles)
)

def order_by_position(self):
Expand Down