Skip to content

Commit

Permalink
refactor: remove EighthBlock.get_surrounding_blocks() in favor of Eig…
Browse files Browse the repository at this point in the history
…hthBlock.objects.get_blocks_this_year()

They literally do the exact same thing, except that
EighthBlock.get_surrounding_blocks() is less efficient and returns
a list instead of a QuerySet
  • Loading branch information
anonymoose2 authored and theo-o committed Jun 28, 2019
1 parent 70538c0 commit 9ccf7bf
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
14 changes: 0 additions & 14 deletions intranet/apps/eighth/models.py
Expand Up @@ -2,7 +2,6 @@
# pylint: enable=pointless-string-statement
import datetime
import logging
from itertools import chain

from django.conf import settings
from django.contrib.auth import get_user_model
Expand Down Expand Up @@ -513,19 +512,6 @@ def previous_blocks(self, quantity=-1):
return reversed(blocks)
return reversed(blocks[:quantity])

def get_surrounding_blocks(self):
"""Get the blocks around the one given.
Returns: a list of all of those blocks.
"""

next_blocks = self.next_blocks()
prev_blocks = self.previous_blocks()

surrounding_blocks = list(chain(prev_blocks, [self], next_blocks))
return surrounding_blocks

def is_today(self):
"""Does the block occur today?"""
return datetime.date.today() == self.date
Expand Down
4 changes: 2 additions & 2 deletions intranet/apps/eighth/views/signup.py
Expand Up @@ -112,7 +112,7 @@ def eighth_signup_view(request, block_id=None):
# The provided block_id is invalid
raise http.Http404

surrounding_blocks = block.get_surrounding_blocks()
surrounding_blocks = EighthBlock.objects.get_blocks_this_year()
schedule = []

signups = EighthSignup.objects.filter(user=user).select_related("scheduled_activity__block", "scheduled_activity__activity")
Expand Down Expand Up @@ -196,7 +196,7 @@ def eighth_display_view(request, block_id=None):
# The provided block_id is invalid
raise http.Http404

surrounding_blocks = block.get_surrounding_blocks()
surrounding_blocks = EighthBlock.objects.get_blocks_this_year()
schedule = []

signups = EighthSignup.objects.filter(user=user).select_related("scheduled_activity__block", "scheduled_activity__activity")
Expand Down

0 comments on commit 9ccf7bf

Please sign in to comment.