def search_talks(): info = to_dict( request.args, search_array=TalkSearchArray() ) if "search_type" not in info: info["talk_online"] = True info["daterange"] = info.get("daterange", datetime.now(current_user.tz).strftime("%B %d, %Y -") ) try: talk_count = int(info["talk_count"]) talk_start = int(info["talk_start"]) if talk_start < 0: talk_start += (1 - (talk_start + 1) // talk_count) * talk_count except (KeyError, ValueError): talk_count = info["talk_count"] = 50 talk_start = info["talk_start"] = 0 talk_query = {} talks_parser(info, talk_query) talks = talks_search( talk_query, sort=["start_time", "speaker"], seminar_dict=all_seminars() ) # limit=talk_count, offset=talk_start # The talk query isn't sufficient since we don't do a join so don't have access to whether the seminar is private talks = [talk for talk in talks if talk.searchable()] info["results"] = talks return render_template( "search_talks.html", title="Search talks", info=info, section="Search", subsection="talks", bread=None, )
def dosearch(limit=limit, limitbuffer=limitbuffer): if limit and not getcounters: # we fetch extra talks to account for filtering talks = talks_search(query, sort=sort, seminar_dict=all_seminars(), more=more, limit=limit + limitbuffer) else: talks = talks_search(query, sort=sort, seminar_dict=all_seminars(), more=more) # Filtering on display and hidden isn't sufficient since the seminar could be private talks = [talk for talk in talks if talk.searchable()] return talks
def talks(self): if not self.talks_query: # searching on the empty gives us everything return [] query = { '$or': self.talks_query, 'hidden': { "$or": [False, { "$exists": False }] } } res = [ t for t in talks_search( query, sort=["start_time"], seminar_dict=all_seminars()) if t.searchable() or t.user_can_edit(user=self) ] talk_subscriptions = defaultdict(list) for t in res: bisect.insort(talk_subscriptions[t.seminar_id], t.seminar_ctr) if talk_subscriptions != self.talk_subscriptions: self._data["talk_subscriptions"] = talk_subscriptions self.save() return res
def seminars(self): seminars = all_seminars() ans = [] for elt in self.seminar_subscriptions: try: sem = seminars[elt] if sem.visibility != 0 or sem.user_can_edit(): ans.append(sem) except ValueError: self._data["seminar_subscriptions"].remove(elt) self._dirty = True ans = next_talk_sorted(ans) if self._dirty: self.save() return ans
def ics_talks(self): query = self.talks_query[:] for shortname in self.seminar_subscriptions: query.append({'seminar_id': shortname}) query = {'$or': query, 'hidden': {"$or": [False, {"$exists": False}]}} query_st = {} now = datetime.now(tz=UTC) if self.ics_limit_past: query_st['$gte'] = now - timedelta(days=14) if self.ics_limit_future: query_st['$lte'] = now + timedelta(days=31) if query_st: query['start_time'] = query_st res = [t for t in talks_search(query, seminar_dict=all_seminars()) if t.searchable() or t.user_can_edit(user=self)] res.sort(key=lambda elt: now - elt.start_time if now > elt.start_time else elt.start_time - now) return res
def _talks_index(query={}, sort=None, subsection=None, past=False): # Eventually want some kind of cutoff on which talks are included. query = dict(query) subs = subject_pairs() hide_filters = [] if "subjects" in query: subject = query["subjects"]["$contains"] hide_filters = ["subject"] subs = ((subject, subject.capitalize()), ) elif "topics" in query: hide_filters = ["subject", "topic"] elif topdomain() == "mathseminars.org": query["subjects"] = ["math"] query["display"] = True query["hidden"] = {"$or": [False, {"$exists": False}]} if past: query["end_time"] = {"$lt": datetime.now()} if sort is None: sort = [("start_time", -1), "seminar_id"] else: query["end_time"] = {"$gte": datetime.now()} if sort is None: sort = ["start_time", "seminar_id"] talks = list(talks_search(query, sort=sort, seminar_dict=all_seminars())) # Filtering on display and hidden isn't sufficient since the seminar could be private talks = [talk for talk in talks if talk.searchable()] counters = _get_counters(talks) row_attributes = _get_row_attributes(talks) return render_template("browse_talks.html", title="Browse talks", hide_filters=hide_filters, subjects=subs, section="Browse", subsection=subsection, talk_row_attributes=zip(talks, row_attributes), past=past, **counters)
def _talks_index(query={}, sort=None, subsection=None, past=False): # Eventually want some kind of cutoff on which talks are included. search_array = TalkSearchArray(past=past) info = to_dict(read_search_cookie(search_array), search_array=search_array) info.update(request.args) query = dict(query) parse_substring(info, query, "keywords", ["title", "abstract", "speaker", "speaker_affiliation", "seminar_id", "comments", "speaker_homepage", "paper_link"]) more = {} # we will be selecting talks satsifying the query and recording whether they satisfy the "more" query # Note that talks_parser ignores the "time" field at the moment; see below for workaround talks_parser(info, more) if topdomain() == "mathseminars.org": query["topics"] = {"$contains": "math"} query["hidden"] = {"$or": [False, {"$exists": False}]} if past: query["end_time"] = {"$lt": datetime.now()} if sort is None: sort = [("start_time", -1), "seminar_id"] else: query["end_time"] = {"$gte": datetime.now()} if sort is None: sort = ["start_time", "seminar_id"] talks = list(talks_search(query, sort=sort, seminar_dict=all_seminars(), more=more)) # Filtering on display and hidden isn't sufficient since the seminar could be private talks = [talk for talk in talks if talk.searchable()] # While we may be able to write a query specifying inequalities on the timestamp in the user's timezone, it's not easily supported by talks_search. So we filter afterward timerange = info.get("timerange", "").strip() if timerange: tz = current_user.tz try: timerange = process_user_input(timerange, col="search", typ="daytimes") except ValueError: try: onetime = process_user_input(timerange, col="search", typ="daytime") except ValueError: flash_error("Invalid time range input: %s", timerange) else: for talk in talks: if talk.more: talkstart = adapt_datetime(talk.start_time, tz) t = date_and_daytime_to_time(talkstart.date(), onetime, tz) talk.more = (t == talkstart) else: for talk in talks: if talk.more: talkstart = adapt_datetime(talk.start_time, tz) talkend = adapt_datetime(talk.end_time, tz) t0, t1 = date_and_daytimes_to_times(talkstart.date(), timerange, tz) talk.more = (t0 <= talkstart) and (talkend <= t1) counters = _get_counters(talks) row_attributes = _get_row_attributes(talks) response = make_response(render_template( "browse_talks.html", title="Browse talks", section="Browse", info=info, subsection=subsection, talk_row_attributes=zip(talks, row_attributes), past=past, **counters )) if request.cookies.get("topics", ""): # TODO: when we move cookie data to server with ajax calls, this will need to get updated again # For now we set the max_age to 30 years response.set_cookie("topics_dict", topic_dag.port_cookie(), max_age=60*60*24*365*30) response.set_cookie("topics", "", max_age=0) return response