Skip to content

Commit

Permalink
chore: Edit Displayed Text in Bug List Filters Fix (#13)
Browse files Browse the repository at this point in the history
* - issue #1
- used constants for the text displayed in filters

* - added a util function to get actual value from list of tuples.

* Update utils.py

- Simplify the function get_choice_display()
- Improve function docstring
- Add module docstring

---------

Co-authored-by: Niloth P <[email protected]>
  • Loading branch information
harsha-mangena and Niloth-p authored Nov 25, 2023
1 parent 2fc8b25 commit af2b062
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
18 changes: 18 additions & 0 deletions bug_hub/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
Utility Functions
This module contains utility functions that are not tied to specific Django models or views.
These functions provide common functionality that can be reused across different parts of the project.
"""
def get_choice_display(choices, choice_key):
"""
Get the display value for a choice key.
Args:
choices (list of tuple): The list of choices.
choice_key (str): The key of the choice.
Returns:
str: The display value for the choice.
"""
return dict(choices).get(choice_key, "All")
6 changes: 4 additions & 2 deletions bug_hub/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from bug_hub.models import Bug
from config.constants import PAGINATE_BY
from .forms import BugCreationForm
from .choices import BUG_TYPE_CHOICES, STATUS_CHOICES
from .utils import get_choice_display

class BugListView(ListView):
"""
Expand Down Expand Up @@ -65,8 +67,8 @@ def get_context_data(self, **kwargs):
:return: The context data with additional filters.
"""
context = super().get_context_data(**kwargs)
context['status_filter'] = self.status_filter
context['type_filter'] = self.type_filter
context['status_filter'] = get_choice_display(STATUS_CHOICES, self.status_filter)
context['type_filter'] = get_choice_display(BUG_TYPE_CHOICES, self.type_filter)
context['query'] = self.query
return context

Expand Down

0 comments on commit af2b062

Please sign in to comment.