4545import assign_lib
4646
4747## db
48- from sqlalchemy .exc import OperationalError
4948from sqlalchemy import func , desc , distinct , or_ , text
5049from sqlalchemy .sql import select
5150
@@ -571,9 +570,7 @@ def eventCreator(aid):
571570@app .route ('/adj' , methods = ['GET' ])
572571@login_required
573572def adj ():
574- """ Rendering for adjudication page."""
575- filter = request .form .get ('filter' )
576- sort = request .form .get ('sort' )
573+ """Initial rendering for adjudication page."""
577574
578575 ## TODO: These are placeholders which will be gathered from queries later
579576 query1 = 'Chicago'
@@ -594,23 +591,9 @@ def adj():
594591 # join(CodeEventCreator, CanonicalEventLink.cec_id == CodeEventCreator.id).\
595592 # filter(CanonicalEvent.key == canonical_event_key).all()
596593
597- #####
598- ## Data for search
599- #####
600- ## TODO: Move this into YAML or base this off of EventMetadata fields
601- filter_fields = [
602- "---" ,
603- "article_desc" ,
604- "article_id" ,
605- "desc" ,
606- "event_id" ,
607- "location" ,
608- "start_date" ,
609- "end_date" ,
610- "publication" ,
611- "pub_date" ,
612- "title"
613- ]
594+ ## TODO: Base this off EventMetadata for now. Eventually, we want to get rid of this.
595+ filter_fields = EventMetadata .__table__ .columns .keys ()
596+ filter_fields .remove ('id' )
614597
615598 ## TODO: Do some checks in the template which don't force us to enter in empty variables
616599 ## which will be initialized by load_adj_grid
@@ -630,6 +613,7 @@ def adj():
630613@login_required
631614def load_cand_search ():
632615 """Loads the candidate event search pane."""
616+ pass
633617
634618
635619@app .route ('/load_adj_grid' , methods = ['GET' ])
@@ -662,14 +646,50 @@ def load_adj_grid():
662646## Search functions
663647#####
664648
665- @app .route ('/adj_search/<function>' )
649+ @app .route ('/do_search' , methods = [ 'GET' ] )
666650@login_required
667- def cand_search (function ):
668- """Performs a search on the candidate events."""
669- if function not in ['search' , 'filter' , 'sort' ]:
651+ def do_search ():
652+ """Takes the URL params and searches the candidate events for events
653+ which meet the search criteria."""
654+ search_params = request .args .to_dict ()
655+ 656+ filter_field = search_params .get ('filter_field' )
657+ filter_value = search_params .get ('filter_value' )
658+ filter_compare = search_params .get ('filter_compare' )
659+ 660+ ## TODO: Do the filtering. Find a way to translate the filter compare
661+ ## to a SQLAlchemy expression.
662+ pass
663+ 664+ @app .route ('/adj_search/<function>' , methods = ['POST' ])
665+ @login_required
666+ def adj_search (function ):
667+ """Adds a search/filter/sort form row to the search pane.
668+ Will only do this if the prior search/filter/sort form rows are full."""
669+ 670+ if function == 'search' :
671+ search_str = request .form ['adj-search-input' ]
672+ if search_str is None or search_str == '' :
673+ return make_response ('No search string provided' , 400 )
674+ elif function == 'filter' :
675+ filter_field = request .form ['adj-filter-field' ]
676+ filter_compare = request .form ['adj-filter-compare' ]
677+ filter_value = request .form ['adj-filter-value' ]
678+ 679+ if filter_field is None or filter_compare is None or filter_value is None :
680+ return make_response ('No filter provided' , 400 )
681+ elif function == 'sort' :
682+ sort_field = request .form ['adj-sort-field' ]
683+ sort_order = request .form ['adj-sort-order' ]
684+ 685+ if sort_field is None or sort_order is None :
686+ return make_response ('No sort field provided' , 400 )
687+ else :
670688 return make_response ("Invalid search function" , 400 )
671689
672- return render_template ('adj-{}.html' .format (function ))
690+ is_addition = True if request .form ['is_addition' ] == 'true' else False
691+ 692+ return render_template ('adj-{}.html' .format (function ), is_addition = is_addition )
673693
674694
675695#####
0 commit comments