def processComicQueryArgs(self, query):
        def hasValue(obj):
            return obj is not None and obj != ""
        
        keyphrase_filter = self.get_argument(u"keyphrase", default=None)
        series_filter = self.get_argument(u"series", default=None)
        path_filter = self.get_argument(u"path", default=None)
        folder_filter = self.get_argument(u"folder", default="")
        title_filter = self.get_argument(u"title", default=None)
        start_filter = self.get_argument(u"start_date", default=None)
        end_filter = self.get_argument(u"end_date", default=None)
        added_since = self.get_argument(u"added_since", default=None)
        modified_since = self.get_argument(u"modified_since", default=None)
        lastread_since = self.get_argument(u"lastread_since", default=None)
        order = self.get_argument(u"order", default=None)
        character = self.get_argument(u"character", default=None)
        team = self.get_argument(u"team", default=None)
        location = self.get_argument(u"location", default=None)
        storyarc = self.get_argument(u"storyarc", default=None)
        volume = self.get_argument(u"volume", default=None)
        publisher = self.get_argument(u"publisher", default=None)
        credit_filter = self.get_argument(u"credit", default=None)
        tag = self.get_argument(u"tag", default=None)
        genre = self.get_argument(u"genre", default=None)

        if folder_filter != "":
            folder_filter = os.path.normcase(os.path.normpath(folder_filter))
            print folder_filter
        
        person = None
        role = None
        if hasValue(credit_filter):
            credit_info = credit_filter.split(":")
            if len(credit_info[0]) != 0:
                person = credit_info[0] 
                if len(credit_info) > 1:
                    role = credit_info[1]

        if hasValue(person):
            query = query.join(Credit).filter(Person.name.ilike(person.replace("*","%"))).filter(Credit.person_id==Person.id)
            if role is not None:
                query = query.filter(Credit.role_id==Role.id).filter(Role.name.ilike(role.replace("*","%")))
            #query = query.filter( Comic.persons.contains(unicode(person).replace("*","%") ))
        
        if hasValue(keyphrase_filter):
            keyphrase_filter = unicode(keyphrase_filter).replace("*","%")
            keyphrase_filter = "%" + keyphrase_filter + "%"
            query = query.filter( Comic.series.ilike(keyphrase_filter) 
                                | Comic.title.ilike(keyphrase_filter)
                                | Comic.publisher.ilike(keyphrase_filter)
                                | Comic.path.ilike(keyphrase_filter)
                                | Comic.comments.ilike(keyphrase_filter)
                                #| Comic.characters_raw.any(Character.name.ilike(keyphrase_filter))
                                #| Comic.teams_raw.any(Team.name.ilike(keyphrase_filter))
                                #| Comic.locations_raw.any(Location.name.ilike(keyphrase_filter))
                                #| Comic.storyarcs_raw.any(StoryArc.name.ilike(keyphrase_filter))
                                | Comic.persons_raw.any(Person.name.ilike(keyphrase_filter))
                            )

        def addQueryOnScalar(query, obj_prop, filt):
            if hasValue(filt):
                filt = unicode(filt).replace("*","%")
                return query.filter( obj_prop.ilike(filt))
            else:
                return query
        def addQueryOnList(query, obj_list, list_prop, filt):
            if hasValue(filt):
                filt = unicode(filt).replace("*","%")
                return query.filter( obj_list.any(list_prop.ilike(filt)))
            else:
                return query

        query = addQueryOnScalar(query, Comic.series, series_filter)
        query = addQueryOnScalar(query, Comic.title, title_filter)
        query = addQueryOnScalar(query, Comic.path, path_filter)
        query = addQueryOnScalar(query, Comic.folder, folder_filter)
        query = addQueryOnScalar(query, Comic.publisher, publisher)
        query = addQueryOnList(query, Comic.characters_raw, Character.name, character)
        query = addQueryOnList(query, Comic.generictags_raw, GenericTag.name, tag)
        query = addQueryOnList(query, Comic.teams_raw, Team.name, team)
        query = addQueryOnList(query, Comic.locations_raw, Location.name, location)
        query = addQueryOnList(query, Comic.storyarcs_raw, StoryArc.name, storyarc)
        query = addQueryOnList(query, Comic.genres_raw, Genre.name, genre)
        #if hasValue(series_filter):
        #    query = query.filter( Comic.series.ilike(unicode(series_filter).replace("*","%") ))
        #if hasValue(title_filter):
        #    query = query.filter( Comic.title.ilike(unicode(title_filter).replace("*","%") ))
        #if hasValue(filename_filter):
        #    query = query.filter( Comic.path.ilike(unicode(filename_filter).replace("*","%") ))
        #if hasValue(publisher):
        #    query = query.filter( Comic.publisher.ilike(unicode(publisher).replace("*","%") ))
        #if hasValue(character):
        #    query = query.filter( Comic.characters_raw.any(Character.name.ilike(unicode(character).replace("*","%") )))
        #if hasValue(tag):
        #    query = query.filter( Comic.generictags.contains(unicode(tag).replace("*","%") ))
        #if hasValue(team):
        #    query = query.filter( Comic.teams.contains(unicode(team).replace("*","%") ))
        #if hasValue(location):
        #    query = query.filter( Comic.locations.contains(unicode(location).replace("*","%") ))
        #if hasValue(storyarc):
        #    query = query.filter( Comic.storyarcs.contains(unicode(storyarc).replace("*","%") ))
        #if hasValue(genre):
        #    query = query.filter( Comic.genres.contains(unicode(genre).replace("*","%") ))
        if hasValue(volume):
            try:
                vol = 0
                vol = int(volume)
                query = query.filter(Comic.volume == vol)
            except:
                pass
                    
        if hasValue(start_filter):
            try:
                dt = dateutil.parser.parse(start_filter)
                query = query.filter( Comic.date >= dt)
            except:
                pass
        
        if hasValue(end_filter):
            try:
                dt = dateutil.parser.parse(end_filter)
                query = query.filter( Comic.date <= dt)
            except:
                pass
            
        if hasValue(modified_since):
            try:
                dt=dateutil.parser.parse(modified_since)
                resultset = resultset.filter( Comic.mod_ts >= dt )
            except:
                pass

        if hasValue(added_since):
            try:
                dt=dateutil.parser.parse(added_since)
                query = query.filter( Comic.added_ts >= dt )
            except:
                pass
        
        if hasValue(lastread_since):
            try:
                dt=dateutil.parser.parse(lastread_since)
                query = query.filter( Comic.lastread_ts >= dt, Comic.lastread_ts != "" )
            except:
                pass
        
        order_key = None
        # ATB temp hack to cover "slicing" bug where
        # if no order specified, the child collections
        # get chopped off sometimes
        if not hasValue(order):
            order = "id"
        
        if hasValue(order):
            if order[0] == "-":
                order_desc = True
                order = order[1:]
            else:
                order_desc = False
            if order == "id":
                order_key = Comic.id                
            if order == "series":
                order_key = Comic.series
            elif order == "modified":
                order_key = Comic.mod_ts
            elif order == "added":
                order_key = Comic.added_ts
            elif order == "lastread":
                order_key = Comic.lastread_ts
            elif order == "volume":
                order_key = Comic.volume
            elif order == "issue":
                order_key = Comic.issue_num
            elif order == "date":
                order_key = Comic.date
            elif order == "publisher":
                order_key = Comic.publisher
            elif order == "title":
                order_key = Comic.title
            elif order == "path":
                order_key = Comic.path
                
        if order_key is not None:
            if order_desc:
                order_key = order_key.desc()                
            query = query.order_by(order_key)

        return query
dataset/ETHPy150Open beville/ComicStreamer/comicstreamerlib/server.py/JSONResultAPIHandler.processComicQueryArgs/original