Skip to content

Commit

Permalink
project filter fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Esmat-Farjad committed Dec 27, 2023
1 parent 6e34dc9 commit 8db67a1
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 42 deletions.
36 changes: 36 additions & 0 deletions src/project_reports/filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import django_filters
from django import forms

from rh.models import ActivityDomain, Cluster, Location, Organization
from .models import ProjectMonthlyReport

class ReportFilterForm(django_filters.FilterSet):
clusters = django_filters.ModelMultipleChoiceFilter(
# field_name='test',
# to_field_name='project',
queryset = Cluster.objects.all(),
widget=forms.SelectMultiple()
)
organization = django_filters.ModelMultipleChoiceFilter(
queryset = Organization.objects.all(),
widget=forms.SelectMultiple(),
)
activity_domains = django_filters.ModelChoiceFilter(
queryset = ActivityDomain.objects.all(),
widget=forms.SelectMultiple(),
)
country = django_filters.ModelChoiceFilter(
queryset = Location.objects.filter(type="Country"),
widget=forms.Select(),
)
province = django_filters.ModelChoiceFilter(
queryset = Location.objects.filter(type="Province"),
widget=forms.Select()
),
district = django_filters.ModelChoiceFilter(
queryset = Location.objects.filter(type="District"),
widget=forms.Select(),
)
class Meta:
model = ProjectMonthlyReport
fields = "__all__"
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.0.6 on 2023-12-27 03:31

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('rh', '0012_merge_20231220_0933'),
('project_reports', '0004_activityplanreport_target_achieved'),
]

operations = [
migrations.AlterField(
model_name='activityplanreport',
name='report_types',
field=models.ManyToManyField(blank=True, to='rh.reporttype'),
),
]
2 changes: 1 addition & 1 deletion src/project_reports/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ActivityPlanReport(models.Model):
activity_plan = models.ForeignKey(ActivityPlan, on_delete=models.CASCADE, null=True, blank=True)
indicator = models.ForeignKey(Indicator, on_delete=models.SET_NULL, null=True)

report_types = models.ManyToManyField(ReportType, null=True, blank=True)
report_types = models.ManyToManyField(ReportType, blank=True)
target_achieved = models.IntegerField(default=0, null=True, blank=True)

class Meta:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</ul>
<div class="actions-panel">
<div class="filter-holder">
<a href="#" class="btn btn-red filter-open">Filter</a>
<!-- <a href="#" class="btn btn-red filter-open">Filter</a> -->
<form action="#" class="filter-form">
<div class="filter-options">
<div class="block-top">
Expand All @@ -53,28 +53,16 @@
</select>
</div>
<div class="select-field">
<label>Country</label>
<select name="country" id="country" class="custom-select">
<option value="placeholder" disabled selected placeholder>Country</option>
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
</select>
<label for="report-country">Country</label>
{{report_filter.form.country}}
</div>
<div class="select-field">
<label>Province/ State</label>
<select name="state" id="state" class="custom-select">
<option value="placeholder" disabled selected placeholder>Province/ State</option>
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
</select>
{{report_filter.form.province}}
</div>
<div class="select-field">
<label>District</label>
<select name="district" id="district" class="custom-select">
<option value="placeholder" disabled selected placeholder>District</option>
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
</select>
{{report_filter.form.district}}
</div>
<div class="date-picker-field">
<div class="date start">
Expand All @@ -89,27 +77,15 @@
</div>
<div class="select-field">
<label>Cluster/Sector</label>
<select name="cluster" id="cluster" class="custom-select">
<option value="placeholder" disabled selected placeholder>Cluster/Sector</option>
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
</select>
{{report_filter.form.clusters}}
</div>
<div class="select-field">
<label>Organization</label>
<select name="organisation" id="organisation" class="custom-select">
<option value="placeholder" disabled selected placeholder>Organization</option>
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
</select>
{{report_filter.form.organization}}
</div>
<div class="select-field">
<label>Activity Domain</label>
<select name="domain" id="domain" class="custom-select">
<option value="placeholder" disabled selected placeholder>Activity Domain</option>
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
</select>
{{report_filter.form.activity_domains}}
</div>
</div>
<div class="block-footer">
Expand Down
17 changes: 15 additions & 2 deletions src/project_reports/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django.urls import reverse
from django.utils import timezone
from django.views.decorators.cache import cache_control

from .filter import ReportFilterForm

Check failure on line 14 in src/project_reports/views.py

View workflow job for this annotation

GitHub Actions / build (3.10.13)

Ruff (F401)

src/project_reports/views.py:14:21: F401 `.filter.ReportFilterForm` imported but unused
from rh.models import ImplementationModalityType, Indicator, Location, Project

from .forms import (
Expand All @@ -22,12 +22,24 @@
TargetLocationReportFormSet,
)
from .models import ActivityPlanReport, DisaggregationLocationReport, ProjectMonthlyReport, TargetLocationReport

from django.core.paginator import Paginator

Check failure on line 25 in src/project_reports/views.py

View workflow job for this annotation

GitHub Actions / build (3.10.13)

Ruff (F401)

src/project_reports/views.py:25:35: F401 `django.core.paginator.Paginator` imported but unused
RECORDS_PER_PAGE = 10

@cache_control(no_store=True)
@login_required
def index_project_report_view(request, project):
"""Project Monthly Report View"""
# report_filter = ReportFilterForm(
# request.GET,
# queryset=ProjectMonthlyReport.objects.all()
# .prefetch_related("project","ActivityPlanReport")
# .order_by("-id"),
# )
# page_obj = Paginator(report_filter.qs, RECORDS_PER_PAGE)
# page = request.GET.get('page')
# project_page = page_obj.get_page(page)
# total_pages = "a" * project_page.paginator.num_pages

project = get_object_or_404(Project, pk=project)
project_reports = ProjectMonthlyReport.objects.filter(project=project.pk)
active_project_reports = project_reports.filter(active=True)
Expand All @@ -41,6 +53,7 @@ def index_project_report_view(request, project):
"project_reports_todo": project_reports_todo,
"project_report_complete": project_report_complete,
"project_report_archive": project_report_archive,
# "report_filter":report_filter,
"project_view": False,
"financial_view": False,
"reports_view": True,
Expand Down
10 changes: 5 additions & 5 deletions src/rh/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ class ProjectsFilter(django_filters.FilterSet):
# FIXME: Fix the options issue
clusters = django_filters.ModelMultipleChoiceFilter(
queryset=Cluster.objects.all(),
widget=forms.SelectMultiple(attrs={"class": "js_multiselect"}),
widget=forms.SelectMultiple(attrs={"class":"input-select"})
)
implementing_partners = django_filters.ModelMultipleChoiceFilter(
queryset=Organization.objects.all(),
widget=forms.SelectMultiple(attrs={"class": "js_multiselect"}),
widget=forms.SelectMultiple(attrs={"class":"input-select"})
)
donors = django_filters.ModelMultipleChoiceFilter(
queryset=Donor.objects.all(),
widget=forms.SelectMultiple(attrs={"class": "js_multiselect"}),
widget=forms.SelectMultiple(attrs={"class":"input-select"}),
)
programme_partners = django_filters.ModelMultipleChoiceFilter(
queryset=Organization.objects.all(),
widget=forms.SelectMultiple(attrs={"class": "js_multiselect"}),
widget=forms.SelectMultiple(attrs={"class":"input-select"})
)
activity_domains = django_filters.ModelMultipleChoiceFilter(
queryset=ActivityDomain.objects.all(),
widget=forms.SelectMultiple(attrs={"class": "js_multiselect"}),
widget=forms.SelectMultiple(attrs={"class":"input-select"})
)

class Meta:
Expand Down
21 changes: 19 additions & 2 deletions src/rh/templates/rh/projects/views/projects_view_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,41 @@
</div>
<div class="actions-panel">
<div class="filter-holder">
<a href="#" class="btn btn-red filter-open">Filter</a>
<a href="#" class="btn btn-red filter-open">Filter
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 23 23" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M10.5 6h9.75M10.5 6a1.5 1.5 0 1 1-3 0m3 0a1.5 1.5 0 1 0-3 0M3.75 6H7.5m3 12h9.75m-9.75 0a1.5 1.5 0 0 1-3 0m3 0a1.5 1.5 0 0 0-3 0m-3.75 0H7.5m9-6h3.75m-3.75 0a1.5 1.5 0 0 1-3 0m3 0a1.5 1.5 0 0 0-3 0m-9.75 0h9.75" />
</svg>
</a>
<!-- FIXME: FIX the filter selections -->
<form action="#" class="filter-form">

<div class="filter-options">
<div class="block-top">
<span class="title">Filter</span>
<a class="filter-close" href="#"></a>
</div>
<div class="filter-heading-text">
<span>
<span class="info-sign"></span>
Get your project data sorted.
</span>

</div>
<div class="block-body" data-simplebar>
<div class="select-field">
<label>Donors</label>
<div class="small-label">[hold down the control/command button to select multiple]</div>
{{ project_filter.form.donors }}
</div>
<div class="select-field ">
<label for="{{ project_filter.form.clusters.id_for_label }}">Clusters / Sectors</label>
<div class="small-label">[hold down the control/command button to select multiple]</div>
{{ project_filter.form.clusters }}
</div>
<div class="select-field">
<label>Activity Domain</label>
{{ project_filter.form.activities }}
<div class="small-label">[hold down the control/command button to select multiple]</div>
{{ project_filter.form.activity_domains }}
</div>
<div class="date-picker-field">
<div class="date start">
Expand All @@ -99,10 +114,12 @@
</div>
<div class="select-field">
<label>Implementing Partner</label>
<div class="small-label">[hold down the control/command button to select multiple]</div>
{{ project_filter.form.implementing_partners }}
</div>
<div class="select-field">
<label>Programme Partner</label>
<div class="small-label">[hold down the control/command button to select multiple]</div>
{{ project_filter.form.programme_partners }}
</div>
<div class="select-field">
Expand Down
2 changes: 2 additions & 0 deletions src/static/project_reports/js/monthly_report.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
**/
$(function () {

$(".js_multiselect").select2();

$('tr[data-url]').on('click', function() {
window.location.href = $(this).data('url');
});
Expand Down
21 changes: 21 additions & 0 deletions src/static/src/styles/layout/_common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ ul{
.target-location-container {
margin: 8px 0;
}
.info-sign{
border: 1px solid $red-be;
margin-right: 3px;
border-radius: 5px;
}
.filter-heading-text{
margin-bottom: 10px;
font-size: 14px;
font-weight: 600;
color: #6b6d70;
}
.circle-bage{
background-color: #6b6d70;
color: white;
Expand Down Expand Up @@ -147,6 +158,16 @@ ul{
.show-password{
float: inline-end;
}
.small-label{
font-size: 11px;
font-weight: 600;
vertical-align: top;
color: #aaadb1;
}
.input-select{
width: 100%;
height: 4.5rem;
}
//------------------------
// Random added style end
//-------------------------
Expand Down

0 comments on commit 8db67a1

Please sign in to comment.