Skip to content

Commit

Permalink
Fix tasks in ProjectDetailView
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Jul 28, 2020
1 parent d0ce225 commit 8cecf96
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
4 changes: 2 additions & 2 deletions rdmo/projects/templates/projects/project_detail_tasks.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<h2>{% trans 'Tasks' %}</h2>

{% if project.tasks.exists %}
{% if tasks %}

<table class="table">
<thead>
Expand All @@ -11,7 +11,7 @@ <h2>{% trans 'Tasks' %}</h2>
<th style="width: 20%">{% trans 'Time frame' %}</th>
</thead>
<tbody>
{% for task in project.tasks.all %}
{% for task in tasks %}
<tr>
<td>{{ task.title }}</td>
<td>{{ task.text }}</td>
Expand Down
8 changes: 5 additions & 3 deletions rdmo/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,19 @@ class ProjectDetailView(ObjectPermissionMixin, DetailView):

def get_context_data(self, **kwargs):
context = super(ProjectDetailView, self).get_context_data(**kwargs)
project = context['project']

context['memberships'] = []
for membership in Membership.objects.filter(project=context['project']).order_by('user__last_name'):
for membership in Membership.objects.filter(project=project).order_by('user__last_name'):
context['memberships'].append({
'id': membership.id,
'user': membership.user,
'role': dict(Membership.ROLE_CHOICES)[membership.role],
'last_owner': is_last_owner(context['project'], membership.user),
'last_owner': is_last_owner(project, membership.user),
})

context['snapshots'] = context['project'].snapshots.all()
context['tasks'] = project.tasks.active(project)
context['snapshots'] = project.snapshots.all()
return context


Expand Down
26 changes: 14 additions & 12 deletions rdmo/tasks/managers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.db import models

from rdmo.core.managers import (CurrentSiteManagerMixin,
CurrentSiteQuerySetMixin, GroupsQuerySetMixin)

Expand All @@ -8,26 +9,27 @@ class TaskQuestionSet(CurrentSiteQuerySetMixin, GroupsQuerySetMixin, models.Quer
def filter_catalog(self, catalog):
return self.filter(models.Q(catalogs=None) | models.Q(catalogs=catalog))


class TaskManager(CurrentSiteManagerMixin, CurrentSiteQuerySetMixin, models.Manager):

def get_queryset(self):
return TaskQuestionSet(self.model, using=self._db)

def filter_catalog(self, catalog):
return self.get_queryset().filter_catalog(catalog)

def active(self, project):
tasks = []
for task in self:
conditions = task.conditions.all()

if conditions:
for condition in conditions:
if condition.resolve(project):
task.dates = task.get_dates(project.values.filter(snapshot=None))
tasks.append(task)
break

task.dates = task.get_dates(project.values.filter(snapshot=None))

return tasks


class TaskManager(CurrentSiteManagerMixin, CurrentSiteQuerySetMixin, models.Manager):

def get_queryset(self):
return TaskQuestionSet(self.model, using=self._db)

def filter_catalog(self, catalog):
return self.get_queryset().filter_catalog(catalog)

def active(self, project):
return self.get_queryset().active(project)

0 comments on commit 8cecf96

Please sign in to comment.