File tree 3 files changed +38
-3
lines changed
3 files changed +38
-3
lines changed Original file line number Diff line number Diff line change @@ -331,6 +331,28 @@ class RawPaginationData(TypedDict, Generic[T]):
331
331
page_obj : Paginator [T ]
332
332
333
333
334
+ def filter_announcements_by_search (request , items ):
335
+ print (items )
336
+ if "search" not in request .GET :
337
+ return items
338
+ searchParam = request .GET ["search" ]
339
+ if len (searchParam .strip ()) == 0 :
340
+ return items
341
+ searchParam = searchParam .lower ()
342
+
343
+ def filterMethod (item ):
344
+ return searchParam in item .title .lower () or searchParam in item .content .lower ()
345
+
346
+ filteredItems = list (filter (filterMethod , items ))
347
+
348
+ sorted_announcements = sorted (
349
+ filteredItems ,
350
+ key = lambda announcement : (searchParam .lower () not in announcement .title .lower (), searchParam .lower () not in announcement .content .lower ()),
351
+ )
352
+
353
+ return sorted_announcements
354
+
355
+
334
356
def paginate_announcements_list_raw (
335
357
request : HttpRequest ,
336
358
items : Sequence [T ],
@@ -358,6 +380,8 @@ def paginate_announcements_list_raw(
358
380
else :
359
381
page_num = DEFAULT_PAGE_NUM
360
382
383
+ items = filter_announcements_by_search (request , items )
384
+
361
385
paginator = Paginator (items , 15 )
362
386
if page_num not in paginator .page_range :
363
387
page_num = DEFAULT_PAGE_NUM
Original file line number Diff line number Diff line change 1
1
/* global $ */
2
- $ ( document ) . ready ( function ( ) {
2
+ $ ( document ) . ready ( function ( ) {
3
3
updatePartiallyHidden ( ) ;
4
4
5
5
filterClubAnnouncements ( ) ;
@@ -62,6 +62,12 @@ $(document).ready(function() {
62
62
filterClubAnnouncements ( ) ;
63
63
} ) ;
64
64
65
+ $ ( "#subscribed-announcement-search" ) . submit ( ( e ) => {
66
+ e . preventDefault ( ) ;
67
+ const value = $ ( "#subscribed-announcement-search-input" ) . val ( ) ;
68
+ window . location . replace ( "/announcements/club?search=" + value ) ;
69
+ } )
70
+
65
71
} ) ;
66
72
67
73
function updatePartiallyHidden ( ) {
Original file line number Diff line number Diff line change 102
102
< div class ="warning-announcement "> {{ dash_warning|safe|linebreaks }}</ div >
103
103
{% endif %}
104
104
105
- < div class ="announcements-header ">
105
+ < div class ="announcements-header " style ="" >
106
106
107
107
< h2 > {{ dashboard_header }}</ h2 >
108
+ < span class ="announcements-icon-wrapper " style ="display: flex; flex-direction: row; ">
109
+ {% if view_announcements_url == "club_announcements" %}
110
+ < form id ="subscribed-announcement-search " style ="display: flex; margin-right:1px ">
111
+ < input id ="subscribed-announcement-search-input " type ="text " placeholder ="Search Club Announcements " style ="width: 15rem; " class ="dashboard-textinput " onsubmit ="" >
112
+ </ form >
113
+ {% endif %}
108
114
109
- < span class ="announcements-icon-wrapper ">
110
115
{% if show_expired or not show_widgets %}
111
116
< a href ="{% url 'index' %} " class ="button " style ="float:left "> < i class ="fas fa-arrow-left " style ="width: 11px "> </ i > Dashboard</ a >
112
117
You can’t perform that action at this time.
0 commit comments