Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Rex Dri
Rex Dri
Commits
f2cdf1ea
Unverified
Commit
f2cdf1ea
authored
May 17, 2020
by
Estelle Veisemburger
Committed by
Florent Chehab
May 24, 2020
Browse files
feat(filter): apply filter to previous exchanges search
parent
9fc1fdda
Changes
3
Hide whitespace changes
Inline
Side-by-side
backend/backend_app/models/exchangeFeedback.py
View file @
f2cdf1ea
from
django.core.validators
import
MaxValueValidator
,
MinValueValidator
from
django.db
import
models
from
django_filters.rest_framework
import
DjangoFilterBackend
from
rest_framework.permissions
import
BasePermission
from
django_filters
import
rest_framework
as
filters
from
backend_app.models.abstract.essentialModule
import
(
EssentialModule
,
...
...
@@ -78,6 +80,23 @@ class ExchangePermission(BasePermission):
return
request
.
user
.
pk
==
obj
.
exchange
.
student
.
pk
class
CharInFilter
(
filters
.
BaseInFilter
,
filters
.
CharFilter
):
pass
class
ExchangeFeedbackFilter
(
filters
.
FilterSet
):
exchange__student_major_in
=
CharInFilter
(
field_name
=
'exchange__student_major'
,
lookup_expr
=
'in'
)
exchange__student_minor_in
=
CharInFilter
(
field_name
=
'exchange__student_minor'
,
lookup_expr
=
'in'
)
class
Meta
:
model
=
ExchangeFeedback
fields
=
[
'exchange__student_major_in'
,
'exchange__student_minor_in'
]
class
ExchangeFeedbackFilterBackend
(
DjangoFilterBackend
):
filterset_base
=
ExchangeFeedbackFilter
class
ExchangeFeedbackViewSet
(
EssentialModuleViewSet
):
permission_classes
=
(
NoDelete
&
NoPost
&
(
ReadOnly
|
IsStaff
|
ExchangePermission
),
...
...
@@ -99,9 +118,8 @@ class ExchangeFeedbackViewSet(EssentialModuleViewSet):
end_point_route
=
"exchangeFeedbacks"
filterset_fields
=
(
"university"
,
"exchange__student_major"
,
"exchange__student_minor"
,
"untouched"
,
)
filter_backends
=
(
filters
.
DjangoFilterBackend
,
ExchangeFeedbackFilterBackend
,)
required_filterset_fields
=
(
"university"
,)
pagination_class
=
CustomPagination
frontend/src/components/university/tabs/PreviousExchangesTab.jsx
View file @
f2cdf1ea
...
...
@@ -19,6 +19,11 @@ import withUnivInfo from "../../../hoc/withUnivInfo";
import
withNetworkWrapper
,
{
NetWrapParam
,
}
from
"
../../../hoc/withNetworkWrapper
"
;
import
{
getAllMajors
,
getAllMinors
,
getUpdatedUnivMajorMinors
,
}
from
"
../../../utils/majorMinorMappings
"
;
const
undefinedVal
=
uuidv4
();
...
...
@@ -52,10 +57,13 @@ function PreviousExchangesTab({
})
{
const
classes
=
useStyles
();
const
univMajorMinorsUpdated
=
getUpdatedUnivMajorMinors
(
univMajorMinors
);
const
displayMinorSelect
=
major
!==
undefinedVal
;
let
minors
;
if
(
displayMinorSelect
)
minors
=
univMajorMinors
.
find
((
el
)
=>
el
.
major
===
major
).
minors
;
if
(
displayMinorSelect
)
{
minors
=
univMajorMinorsUpdated
.
find
((
el
)
=>
el
.
major
===
major
).
minors
;
}
return
(
<>
...
...
@@ -70,7 +78,7 @@ function PreviousExchangesTab({
}
}
>
<
MenuItem
value
=
{
undefinedVal
}
>
Pas de filtre
</
MenuItem
>
{
univMajorMinors
{
univMajorMinors
Updated
.
filter
((
el
)
=>
el
.
major
!==
null
)
.
map
((
el
)
=>
(
<
MenuItem
key
=
{
el
.
major
}
value
=
{
el
.
major
}
>
...
...
@@ -176,10 +184,14 @@ const buildExchangesParams = (
const
params
=
RequestParams
.
Builder
.
withQueryParam
(
"
university
"
,
univId
)
.
withQueryParam
(
"
page_size
"
,
8
)
.
withQueryParam
(
"
page
"
,
page
);
if
(
typeof
major
!==
"
undefined
"
&&
major
!==
undefinedVal
)
params
.
withQueryParam
(
"
exchange__student_major
"
,
major
);
if
(
typeof
minor
!==
"
undefined
"
&&
minor
!==
undefinedVal
)
params
.
withQueryParam
(
"
exchange__student_minor
"
,
minor
);
if
(
typeof
major
!==
"
undefined
"
&&
major
!==
undefinedVal
)
{
const
finalMajors
=
getAllMajors
(
major
);
params
.
withQueryParam
(
"
exchange__student_major_in
"
,
finalMajors
.
join
(
"
,
"
));
}
if
(
typeof
minor
!==
"
undefined
"
&&
minor
!==
undefinedVal
)
{
const
finalMinors
=
getAllMinors
(
major
,
minor
);
params
.
withQueryParam
(
"
exchange__student_minor_in
"
,
finalMinors
.
join
(
"
,
"
));
}
if
(
showUntouched
===
false
)
params
.
withQueryParam
(
"
untouched
"
,
false
);
return
params
.
build
();
};
...
...
frontend/src/services/FilterService.js
View file @
f2cdf1ea
...
...
@@ -121,8 +121,8 @@ class FilterService {
);
const
extraMinors
=
this
.
getMajorInUniv
(
univObj
).
map
((
major
)
=>
{
maj
or
=
getUpdatedMajor
(
major
);
return
`
${
maj
or
}
— Toutes filières confondues`
;
const
maj
=
getUpdatedMajor
(
major
);
return
`
${
maj
}
— Toutes filières confondues`
;
});
return
[...
new
Set
(
realMinors
),
...
extraMinors
];
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment