Skip to content

Commit

Permalink
added filter issue by open or close status
Browse files Browse the repository at this point in the history
  • Loading branch information
hexwhiz committed Oct 24, 2024
1 parent 8878b32 commit fe343a2
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
26 changes: 25 additions & 1 deletion home/templates/dashboard/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
display: none;
position: absolute;
left: 100%;
top: 0;
margin-top: 5;
}

Expand Down Expand Up @@ -89,7 +90,13 @@
<li>
<a class="dropdown-item" href="#">
Difficulty &raquo;
<button type="button" disabled class="btn btn-danger btn-sm">{{ curr_difficulty }}</button>
<button type="button" disabled class="btn btn-danger btn-sm">
{%if curr_difficulty%}
{{ curr_difficulty }}
{%else%}
ALL
{%endif%}
</button>
</a>
<ul class="dropdown-menu dropdown-submenu">
<li><a class="dropdown-item" href="{% url 'filter_by_difficulty' 'All' %}">All</a></li>
Expand Down Expand Up @@ -138,6 +145,23 @@
{% endfor %}
</ul>
</li>
<li>
<a class="dropdown-item" href="#">
Status &raquo;
<button type="button" disabled class="btn btn-danger btn-sm">
{%if curr_status%}
{{ curr_status }}
{%else%}
ALL
{%endif%}
</button>
</a>
<ul class="dropdown-menu dropdown-submenu">
<li><a class="dropdown-item" href="{% url 'filter_by_status' 'All' %}">All</a></li>
<li><a class="dropdown-item" href="{% url 'filter_by_status' 'Open' %}">Open</a></li>
<li><a class="dropdown-item" href="{% url 'filter_by_status' 'Closed' %}">Closed</a></li>
</ul>
</li>
</ul>
</li>
<li class="nav-item">
Expand Down
2 changes: 2 additions & 0 deletions home/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@
path('contact/', views.contact_form, name='contact_form'),
path('like/<int:issue_pk>/', views.likes, name='like_issue'),
path('dislike/<int:issue_pk>/', views.dislikes, name='dislike_issue'),
path('filter_by_status/<str:status>/',
views.filter_by_status, name='filter_by_status'),
]
41 changes: 41 additions & 0 deletions home/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,47 @@ def filter_by_difficulty(request, difficulty_level=None):

return render(request, 'dashboard/index.html', context=context)

@complete_profile_required
def filter_by_status(request, status=None):
"""
Filter the issues on basis of their open or close status.
params: selected filter option
return:
"""
issues_qs = Issue.objects.all()
project_qs = Project.objects.all()

if status and status != 'All':
status_mapping = {
'Open': Issue.OPEN,
'Closed': Issue.CLOSED
}
if status in status_mapping:
issues_qs = issues_qs.filter(state=status_mapping[status])

domains_qs = Domain.objects.all()
subdomains_qs = SubDomain.objects.all()

curr_domain = request.GET.get('domain', 'All')
curr_subdomain = request.GET.get('subdomain', 'All')

if curr_domain != 'All':
issues_qs = issues_qs.filter(project__domain__name=curr_domain)

if curr_subdomain != 'All':
issues_qs = issues_qs.filter(project__subdomain__name=curr_subdomain)

context = {
'projects': project_qs,
'issues': issues_qs,
'domains': domains_qs,
'subdomains': subdomains_qs,
'curr_domain': curr_domain,
'curr_subdomain': curr_subdomain,
'curr_status': status if status else 'All'
}

return render(request, 'dashboard/index.html', context=context)

def authorize(request):
"""
Expand Down
18 changes: 18 additions & 0 deletions project/migrations/0042_alter_issue_levelcolor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1 on 2024-10-24 16:35

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('project', '0041_issue_levelcolor'),
]

operations = [
migrations.AlterField(
model_name='issue',
name='levelcolor',
field=models.PositiveSmallIntegerField(choices=[(0, '#f2f2f2'), (4, '#39c0ed'), (1, '#00b74a'), (2, '#ffa900'), (3, '#f93154')], default=1, verbose_name='Level Color'),
),
]

0 comments on commit fe343a2

Please sign in to comment.