diff --git a/opentech/apply/funds/models/applications.py b/opentech/apply/funds/models/applications.py index 30097f1d3833a2c6f29beef9d29353bddf1c3c80..f2a791dee8cbebd6dd92cb2ba855d519d1728147 100644 --- a/opentech/apply/funds/models/applications.py +++ b/opentech/apply/funds/models/applications.py @@ -345,6 +345,9 @@ class RoundsAndLabsQueryset(PageQuerySet): def closed(self): return self.filter(end_date__lt=date.today()) + def by_lead(self, user): + return self.filter(lead_pk=user.pk) + class RoundsAndLabsProgressQueryset(RoundsAndLabsQueryset): def active(self): @@ -367,6 +370,10 @@ class RoundsAndLabsManager(PageManager): end_date=F('roundbase__end_date'), parent_path=Left(F('path'), Length('path') - ApplicationBase.steplen, output_field=CharField()), fund=Subquery(funds.values('title')[:1]), + lead_pk=Coalesce( + F('roundbase__lead__pk'), + F('labbase__lead__pk'), + ), ) def with_progress(self): @@ -406,6 +413,9 @@ class RoundsAndLabsManager(PageManager): def new(self): return self.get_queryset().new() + def by_lead(self, user): + return self.get_queryset().by_lead(user) + class RoundsAndLabs(Page): """ diff --git a/opentech/apply/funds/templates/funds/includes/round-block.html b/opentech/apply/funds/templates/funds/includes/round-block.html index 8fdca206107d2438cef6a3115d49dfe101260797..56614a4a9d5b075fc1282b7338d0247f6614259f 100644 --- a/opentech/apply/funds/templates/funds/includes/round-block.html +++ b/opentech/apply/funds/templates/funds/includes/round-block.html @@ -1,6 +1,6 @@ <div class="wrapper wrapper--bottom-space"> <section class="section section--with-options"> - <h4 class="heading heading--normal heading--no-margin">All Rounds and Labs</h4> + <h4 class="heading heading--normal heading--no-margin">Your Rounds and Labs</h4> <div class="js-tabs"> <a class="tab__item tab__item--alt" href="#closed-rounds" data-tab="tab-1">Closed</a> <a class="tab__item tab__item--alt" href="#open-rounds" data-tab="tab-2">Open</a> diff --git a/opentech/apply/funds/templates/funds/submissions.html b/opentech/apply/funds/templates/funds/submissions.html index 353450fa78d785a9339a12023d7eb3f69c5f3736..6c938d529c0b682b5dda3b116286fc976e646517 100644 --- a/opentech/apply/funds/templates/funds/submissions.html +++ b/opentech/apply/funds/templates/funds/submissions.html @@ -14,6 +14,11 @@ </div> <div class="wrapper wrapper--large wrapper--inner-space-medium"> + + {% if closed_rounds or open_rounds %} + {% include "funds/includes/round-block.html" with closed_rounds=closed_rounds open_rounds=open_rounds %} + {% endif %} + {% block table %} {{ block.super }} {% endblock %} diff --git a/opentech/apply/funds/views.py b/opentech/apply/funds/views.py index b75cf12325e6c96bf0015eb74be4c308e69f1380..b7c786c2864b416559aaf00902105c8f66835304 100644 --- a/opentech/apply/funds/views.py +++ b/opentech/apply/funds/views.py @@ -89,19 +89,24 @@ class SubmissionOverviewView(AllActivityContextMixin, BaseAdminSubmissionsTable) return super().get_table_data().order_by(F('last_update').desc(nulls_last=True))[:5] def get_context_data(self, **kwargs): - base_query = RoundsAndLabs.objects.with_progress().order_by('end_date') - open_rounds = base_query.open()[:6] - open_query = '?round_state=open' - closed_rounds = base_query.closed()[:6] - closed_query = '?round_state=closed' - - return super().get_context_data( - open_rounds=open_rounds, - open_query=open_query, - closed_rounds=closed_rounds, - closed_query=closed_query, - **kwargs, - ) + # For OTF staff, display rounds/labs where user is the lead + if self.request.user.is_staff: + base_query = RoundsAndLabs.objects.with_progress().active().order_by('-end_date') + base_query = base_query.by_lead(self.request.user) + open_rounds = base_query.open()[:6] + open_query = '?round_state=open' + closed_rounds = base_query.closed()[:6] + closed_query = '?round_state=closed' + + return super().get_context_data( + open_rounds=open_rounds, + open_query=open_query, + closed_rounds=closed_rounds, + closed_query=closed_query, + **kwargs, + ) + else: + return super().get_context_data(**kwargs) class SubmissionListView(AllActivityContextMixin, BaseAdminSubmissionsTable):