def ams(): seminars = next_talk_sorted( seminars_search( query={"topics": { '$contains': "math" }}, organizer_dict=all_organizers(), )) from collections import defaultdict math_topics = { rec["topic_id"]: rec["name"].capitalize() for rec in db.new_topics.search({ "topic_id": { "$in": list(db.new_topics.lookup("math", "children")) } }) } seminars_dict = defaultdict(list) for sem in seminars: for topic in sem.topics: if topic in math_topics: seminars_dict[topic].append(sem) return render_template("ams.html", title="AMS example", math_topics=sorted(math_topics.items(), key=lambda x: x[1]), seminars_dict=seminars_dict)
def show_institution(shortname): institution = db.institutions.lookup(shortname) if institution is None: return abort(404, "Institution not found") institution = WebInstitution(shortname, data=institution) section = "Manage" if current_user.is_creator else None query = {"institutions": {"$contains": shortname}} if not current_user.is_admin: query["display"] = True # Find other institutions that are joint with seminars here others = list(set(sum(seminars_search(query, "institutions"), []))) idict = all_institutions({"shortname": {"$in": others}}) events = next_talk_sorted( list( seminars_search(query, organizer_dict=all_organizers(), institution_dict=idict))) seminars = [S for S in events if not S.is_conference] conferences = [S for S in events if S.is_conference] conferences.sort(key=lambda S: (S.start_date, S.name)) return render_template( "institution.html", seminars=seminars, conferences=conferences, title="View institution", institution=institution, section=section, subsection="viewinst", )
def _search_series(conference=False): info = to_dict(request.args, search_array=SeriesSearchArray(conference=conference)) if "search_type" not in info: info["seminar_online"] = True info["daterange"] = info.get("daterange", datetime.now(current_user.tz).strftime("%B %d, %Y -")) try: seminar_count = int(info["seminar_count"]) seminar_start = int(info["seminar_start"]) if seminar_start < 0: seminar_start += (1 - (seminar_start + 1) // seminar_count) * seminar_count except (KeyError, ValueError): seminar_count = info["seminar_count"] = 50 seminar_start = info["seminar_start"] = 0 seminar_query, org_query = {"is_conference": conference}, {} seminars_parser(info, seminar_query, org_query, conference=conference) res = [s for s in seminars_search(seminar_query, organizer_dict=all_organizers(org_query))] # process query again with keywords applied to seminar_organizers rather than seminars if "keywords" in info: seminar_query, org_query = {"is_conference": conference}, {} seminars_parser(info, seminar_query, org_query, org_keywords=True, conference=conference) res += list(seminars_search(seminar_query, organizer_dict=all_organizers(org_query))) info["results"] = date_sorted(res) if conference else next_talk_sorted(res) subsection = "conferences" if conference else "seminars" title = "Search " + ("conferences" if conference else "seminar series") return render_template( "search_seminars.html", title=title, info=info, section="Search", subsection=subsection, bread=None, is_conference=conference, )
def _search_series(conference): info = to_dict(request.args, search_array=SemSearchArray()) if "search_type" not in info: info["seminar_online"] = True try: seminar_count = int(info["seminar_count"]) seminar_start = int(info["seminar_start"]) if seminar_start < 0: seminar_start += ( 1 - (seminar_start + 1) // seminar_count) * seminar_count except (KeyError, ValueError): seminar_count = info["seminar_count"] = 50 seminar_start = info["seminar_start"] = 0 seminar_query = {"is_conference": conference} seminars_parser(info, seminar_query) # Ideally we would do the following with a single join query, but the backend doesn't support joins yet. # Instead, we use a function that returns a dictionary of all next talks as a function of seminar id. # One downside of this approach is that we have to retrieve ALL seminars, which we're currently doing anyway. # The second downside is that we need to do two queries. print(seminar_query) info["results"] = next_talk_sorted( seminars_search(seminar_query, organizer_dict=all_organizers())) print(len(info["results"])) return render_template("search_seminars.html", title="Search seminars", info=info, section="Search", subsection="seminars", bread=None, is_conference=conference)
def seminars(self): ans = [] for elt in self.seminar_subscriptions: try: ans.append(WebSeminar(elt)) except ValueError: self._data["seminar_subscriptions"].remove(elt) self._dirty = True ans = next_talk_sorted(ans) if self._dirty: self.save() return ans
def _series_index(query, sort=None, subsection=None, conference=True, past=False): search_array = SeriesSearchArray(conference=conference, 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", ["name", "description", "homepage", "shortname", "comments"]) more = {} # we will be selecting talks satsifying the query and recording whether they satisfy the "more" query seminars_parser(info, more) query["visibility"] = 2 print(info, more) if conference: # Be permissive on end-date since we don't want to miss ongoing conferences, and we could have time zone differences. Ignore the possibility that the user/conference is in Kiribati. recent = datetime.now().date() - timedelta(days=1) if past: query["end_date"] = {"$lt": recent} else: query["end_date"] = {"$gte": recent} if sort is None: if past: sort = [("end_date", -1), ("start_date", -1), "name"] else: sort = ["start_date", "end_date", "name"] if sort is None: # not conferences # We don't currently call this case in the past, but if we add it we probably # need a last_talk_sorted that sorts by end time of last talk in reverse order series = next_talk_sorted(seminars_search(query, organizer_dict=all_organizers(), more=more)) else: series = list(seminars_search(query, sort=sort, organizer_dict=all_organizers(), more=more)) counters = _get_counters(series) row_attributes = _get_row_attributes(series) title = "Browse conferences" if conference else "Browse seminar series" response = make_response(render_template( "browse_series.html", title=title, section="Browse", subsection=subsection, info=info, series_row_attributes=zip(series, row_attributes), is_conference=conference, 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
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 ams(): seminars = next_talk_sorted( seminars_search(query={"subjects": { '$contains': "math" }}, organizer_dict=all_organizers())) from collections import defaultdict math_topics = { elt['subject'] + '_' + elt['abbreviation']: elt['name'].capitalize() for elt in db.topics.search() if elt['subject'] == 'math' } seminars_dict = defaultdict(list) for sem in seminars: for topic in sem.topics: if topic in math_topics: seminars_dict[topic].append(sem) return render_template("ams.html", title="AMS example", math_topics=sorted(math_topics.items(), key=lambda x: x[1]), seminars_dict=seminars_dict)
def _series_index(query, sort=None, subsection=None, conference=True, past=False): query = dict(query) query["display"] = True query["visibility"] = 2 if conference: # Be permissive on end-date since we don't want to miss ongoing conferences, and we could have time zone differences. Ignore the possibility that the user/conference is in Kiribati. recent = datetime.now().date() - timedelta(days=1) if past: query["end_date"] = {"$lt": recent} else: query["end_date"] = {"$gte": recent} if conference and sort is None: if past: sort = [("end_date", -1), ("start_date", -1), "name"] else: sort = ["start_date", "end_date", "name"] if sort is None: # not conferences # We don't currently call this case in the past, but if we add it we probably # need a last_talk_sorted that sorts by end time of last talk in reverse order series = next_talk_sorted( seminars_search(query, organizer_dict=all_organizers())) else: series = list( seminars_search(query, sort=sort, organizer_dict=all_organizers())) counters = _get_counters(series) row_attributes = _get_row_attributes(series) title = "Browse conferences" if conference else "Browse seminar series" return render_template("browse_series.html", title=title, hide_filters=[], subjects=subject_pairs(), section="Browse", subsection=subsection, series_row_attributes=zip(series, row_attributes), is_conference=conference, **counters)