Skip to content

Commit

Permalink
Merge pull request #28 from aparsons/django-update
Browse files Browse the repository at this point in the history
Update Django to 1.11.x
  • Loading branch information
aparsons authored Jul 19, 2019
2 parents be26de8 + 861b380 commit e3f71b8
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ __pycache__/
# Distribution / packaging
.Python
env/
py3env/
py*env/
build/
libs/
develop-eggs/
Expand Down
16 changes: 7 additions & 9 deletions project/boh/filters.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import django_filters

from django_filters import filters

from .models import Organization, Application


class ApplicationFilter(django_filters.FilterSet):
name = filters.CharFilter(lookup_type='icontains')
organization = filters.ModelMultipleChoiceFilter(queryset=Organization.objects.all())
business_criticality = filters.MultipleChoiceFilter(choices=Application.BUSINESS_CRITICALITY_CHOICES)
platform = filters.MultipleChoiceFilter(choices=Application.PLATFORM_CHOICES)
lifecycle = filters.MultipleChoiceFilter(choices=Application.LIFECYCLE_CHOICES)
origin = filters.MultipleChoiceFilter(choices=Application.ORIGIN_CHOICES)
asvs_level = filters.MultipleChoiceFilter(choices=Application.ASVS_CHOICES)
name = django_filters.CharFilter(lookup_expr='icontains')
organization = django_filters.ModelMultipleChoiceFilter(queryset=Organization.objects.all())
business_criticality = django_filters.MultipleChoiceFilter(choices=Application.BUSINESS_CRITICALITY_CHOICES)
platform = django_filters.MultipleChoiceFilter(choices=Application.PLATFORM_CHOICES)
lifecycle = django_filters.MultipleChoiceFilter(choices=Application.LIFECYCLE_CHOICES)
origin = django_filters.MultipleChoiceFilter(choices=Application.ORIGIN_CHOICES)
asvs_level = django_filters.MultipleChoiceFilter(choices=Application.ASVS_CHOICES)

class Meta:
model = Application
Expand Down
36 changes: 31 additions & 5 deletions project/boh/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,11 +593,37 @@ def test_is_past_due(self):
self.assertFalse(self.ac_1.is_past_due())


class CommentTests(TestCase):
class EngagementCommentTests(TestCase):

def test_init(self):
self.u_1 = User(pk = 1)
self.e_1 = models.Engagement(pk = 1)

self.ec_1 = models.EngagementComment(message = 'Hello World', user = self.u_1, engagement = self.e_1)
self.ec_1.save()

self.assertEqual('Hello World', self.ec_1.message)
self.assertEqual(self.u_1, self.ec_1.user)
self.assertEqual(self.e_1, self.ec_1.engagement)

def test_str(self):
self.ec_1 = models.EngagementComment(message = 'Hello World')
self.assertEqual('Hello World', self.ec_1.__str__())

class ActivityCommentTests(TestCase):

def test_init(self):
self.u_1 = User(pk = 1)
self.a_1 = models.Activity(pk = 1)

self.ac_1 = models.ActivityComment(message = 'Hello World', user = self.u_1, activity = self.a_1)
self.ac_1.save()

self.assertEqual('Hello World', self.ac_1.message)
self.assertEqual(self.u_1, self.ac_1.user)
self.assertEqual(self.a_1, self.ac_1.activity)

def test_str(self):
self.user_1 = User.objects.create(username='testy', password='secret', email='[email protected]')
self.user_1.save()
self.ac_1 = models.ActivityComment(message = 'Hello World')
self.assertEqual('Hello World', self.ac_1.__str__())

self.c_1 = models.Comment(message='Hello World', user=self.user_1)
self.assertEqual('Hello World', self.c_1.__str__())
24 changes: 12 additions & 12 deletions project/boh/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def dashboard_personal(request):
"""The personal dashboard with information relevant to the current user."""

activities = models.Activity.objects.filter(users__id=request.user.id) \
.select_related('activity_type__name') \
.select_related('activity_type') \
.select_related('engagement') \
.select_related('engagement__application__name') \
.select_related('engagement__application') \
.annotate(comment_count=Count('activitycomment'))

pending_activities = activities.filter(status=models.Engagement.PENDING_STATUS)
Expand All @@ -94,34 +94,34 @@ def dashboard_team(request):
activities_by_user = User.objects.all().prefetch_related(
Prefetch('activity_set', queryset=models.Activity.objects
.filter(~Q(status=models.Activity.CLOSED_STATUS))
.select_related('activity_type__name')
.select_related('activity_type')
.select_related('engagement')
.annotate(comment_count=Count('activitycomment'))
.select_related('engagement__application__name')
.select_related('engagement__application')
)
)

# Find open and pending engagements
engagements = models.Engagement.objects.all().prefetch_related(
Prefetch('activity_set', queryset=models.Activity.objects.all()
.select_related('activity_type__name')
.select_related('activity_type')
.annotate(user_count=Count('users'))
)
).select_related('application__name').annotate(comment_count=Count('engagementcomment'))
).select_related('application').annotate(comment_count=Count('engagementcomment'))

open_engagements = engagements.filter(status=models.Engagement.OPEN_STATUS)
pending_engagements = engagements.filter(status=models.Engagement.PENDING_STATUS)

# Find activities where no user is assigned
unassigned_activities = models.Activity.objects.filter(users=None) \
.select_related('activity_type__name') \
.select_related('activity_type') \
.select_related('engagement') \
.select_related('engagement__application__name') \
.select_related('engagement__application') \
.annotate(comment_count=Count('activitycomment'))

# Find engagements where no activities have been created
empty_engagements = models.Engagement.objects.filter(activity__isnull=True) \
.select_related('application__name') \
.select_related('application') \
.prefetch_related('activity_set') \
.annotate(comment_count=Count('engagementcomment'))

Expand Down Expand Up @@ -869,7 +869,7 @@ def application_list(request):
if queries.__contains__('page_size'):
del queries['page_size']

application_filter = filters.ApplicationFilter(request.GET, queryset=models.Application.objects.all().select_related('organization__name').prefetch_related('tags'))
application_filter = filters.ApplicationFilter(request.GET, queryset=models.Application.objects.all().select_related('organization').prefetch_related('tags'))

page_size = 25

Expand All @@ -883,7 +883,7 @@ def application_list(request):
else:
page_size = int(page_size)

paginator = Paginator(application_filter, page_size)
paginator = Paginator(application_filter.qs, page_size)

page = request.GET.get('page')

Expand Down Expand Up @@ -930,7 +930,7 @@ def application_engagements(request, application_id):
engagements = application.engagement_set.prefetch_related(
Prefetch('activity_set', queryset=models.Activity.objects
.all()
.select_related('activity_type__name')
.select_related('activity_type')
)
).annotate(comment_count=Count('engagementcomment'))

Expand Down
6 changes: 3 additions & 3 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Django==1.9.13
Django==1.11.22
django-formtools==1.0
djangorestframework==3.3.3
django-filter==0.13.0
djangorestframework==3.4.7
django-filter==1.1.0
django-widget-tweaks==1.4.1
Markdown==2.6.11
phonenumbers==8.9.10
Expand Down

0 comments on commit e3f71b8

Please sign in to comment.