def validate(self): sts = True for col in required_talk_columns: if getattr(self, col) is None: sts = False log_error("column %s is None for talk %s/%s" % (col, self.seminar_id, self.seminar_ctr)) if not self.topics: sts = False log_error("No topics set for talk %s/%s" % (self.seminar_id, self.seminar_ctr)) return sts
def show_topics(self): if self.topics: # Don't die just because there is a data issue in the topics/topic-dag try: return " ".join('<span class="topic_label">%s</span>' % topic for topic in topic_dag.leaves(self.topics)) except Exception as err: log_error("Hit exception %s in show_topics for series %s" % (err,self.shortname)) return "" else: return ""
def show_lang_topics(self): if self.language and self.language != "en": language = '<span class="language_label">%s</span>' % languages.show(self.language) else: language = "" if self.topics: try: return language + "".join('<span class="topic_label">%s</span>' % topic for topic in topic_dag.leaves(self.topics)) except Exception as err: log_error("Hit exception %s in show_lang_topics for talk %s/%d" % (err, self.seminar_id, self.seminar_ctr)) return language else: return language
def new_user(self, **kwargs): """ Creates a new user. Required keyword arguments: - email - password - name - affiliation """ for col in ["email", "password"]: assert col in kwargs email = kwargs["email"] = validate_email(kwargs["email"])["email"] kwargs["password"] = self.bchash(kwargs["password"]) if "endorser" not in kwargs: kwargs["endorser"] = None kwargs["admin"] = kwargs["creator"] = False if "subject_admin" not in kwargs: kwargs["subject_admin"] = None for col in ["email_confirmed", "admin", "creator"]: kwargs[col] = kwargs.get(col, False) kwargs["talk_subscriptions"] = kwargs.get("talk_subscriptions", {}) kwargs["seminar_subscriptions"] = kwargs.get("seminar_subscriptions", []) for col in ["name", "affiliation", "homepage", "timezone"]: kwargs[col] = kwargs.get(col, "") tz = kwargs.get("timezone", "") assert tz == "" or tz in all_timezones kwargs["api_access"] = kwargs.get("api_access", 0) kwargs["api_token"] = kwargs.get("api_token", secrets.token_urlsafe(32)) kwargs["created"] = datetime.now(UTC) kwargs["external_ids"] = kwargs.get("external_ids", []) if 'ics_limit_past' in self.col_type: # FIXME after adding columns kwargs['ics_limit_past'] = True kwargs['ics_limit_future'] = False if sorted(list(kwargs) + ['id']) != sorted(self.col_type): log_error("Columns for user creation do not match, %s != %s" % (sorted(list(kwargs) + ['id']), sorted(self.col_type))) self.insert_many([kwargs], restat=False) newuser = SeminarsUser(email=email) return newuser
def show_live_link(self, user=None, raw=False): if user is None: user = current_user now = datetime.now(pytz.utc) if any([self.deleted, not self.online, self.is_really_over()]): return "" link = self.live_link def show_link(self, user=None, raw=False): if user is None: user = current_user link = self.live_link if raw: return link if link else '' if not link: return '<div class=access_button no_link">Livestream link not yet posted by organizers</div>' if self.access_control == 4 and not self.user_is_registered(user): link = url_for("register_for_talk", seminar_id=self.seminar_id, talkid=self.seminar_ctr) if self.is_starting_soon(): return '<div class="access_button is_link starting_soon"><b> <a href="%s">Instantly register and join livestream <i class="play filter-white"></i> </a></b></div>' % link else: return '<div class="access_button is_link"> <a href="%s">Instantly register</a> for livestream access</div>' % link if self.is_starting_soon(): return '<div class="access_button is_link starting_soon"><b> <a href="%s">Join livestream <i class="play filter-white"></i> </a></b></div>' % link else: return '<div class="access_button is_link"> Livestream access <a href="%s">available</a></div>' % link if self.access_control in [0,2]: # password hint will be shown nearby, not our problem return show_link(self, user=user, raw=raw) elif self.access_control == 1: show_link_time = self.start_time - timedelta(minutes=self.access_time) if show_link_time <= now: return show_link(self, user=user, raw=raw) else: return "" if raw else '<div class="access_button no_link">Livestream access available in %s</div>' % how_long(show_link_time-now) elif self.access_control == 2: return show_link(self, user=user, raw=raw) elif self.access_control in [3,4]: if raw: return url_for("show_talk", seminar_id=self.seminar_id, talkid=self.seminar_ctr) if user.is_anonymous: link = url_for("user.info", next=url_for("register_for_talk", seminar_id=self.seminar_id, talkid=self.seminar_ctr)) return '<div class="access_button no_link"><a href="%s">Login required</a> for livestream access</b></div>' % link elif not user.email_confirmed: return '<div class="access_button no_link">Please confirm your email address for livestream access</div>' else: return show_link(self, user=user, raw=raw) elif self.access_control == 5: if not user.is_anonymous and db.seminar_registrations.lucky({'seminar_id':self.seminar_id,'email':user.email}): if not user.email_confirmed: return '<div class="access_button no_link">Please confirm your email address for livestream access</div>' else: return show_link(self, user=user, raw=raw) # If there is a view-only link, show that rather than an external registration link if raw: return url_for("show_talk", seminar_id=self.seminar_id, talkid=self.seminar_ctr) if not self.access_registration: # This should never happen, registration link is required, but just in case... return "" if raw else '<div class="access_button no_link">Registration required, see comments or external site.</a></div>' % link if "@" in self.access_registration: body = """Dear organizers, I am interested in attending the talk {talk} by {speaker}, in the series {series} listed at https://{domain}{url}. Thank you, {user} """.format( talk = self.title, speaker = self.show_speaker(raw=True), series = self.seminar.name, domain = topdomain(), url = url_for('show_talk', seminar_id=self.seminar.shortname, talkid=self.seminar_ctr), user = user.name) msg = { "body": body, "subject": "Request to attend %s" % self.seminar.shortname } link = "mailto:%s?%s" % (self.access_registration, urlencode(msg, quote_via=quote)) else: link = self.access_registration return '<div class="access_button no_link"><a href="%s">Register</a> for livestream access</div>' % link else: # should never happen log_error("invalid or unknown access control value %s for talk %s/%s" % (self.access_control, self.seminar_id, self.seminar_ctr)) return ""
def validate(self): sts = True for col in required_seminar_columns: if getattr(self, col) is None: sts = False log_error("column %s is None for series %s" % (col, self.shortname)) if self.is_conference: for col in ["start_date", "end_date", "per_day"]: if getattr(self, col) is None: sts = False log_error("column %s is None for conference %s" % (col, self.shortname)) else: if getattr(self, "frequency") is None: sts = False log_error("column frequency is None for seminar series %s" % self.shortname) elif self.frequency: for col in ["weekdays", "time_slots"]: if getattr(self, col) is None: sts = False log_error("column %s is None for seminar series %s" % (col, self.shortname)) if self.online: if self.access_control is None: sts = False log_error("access_control is None for online series %s" % self.shortname) elif self.access_control == 1: if self.access_time is None: sts = False log_error( "access_time is None for online series %s with access_control == 1" % self.shortname) elif self.access_control == 2: if self.access_hint is None: sts = False log_error( "access_hint is None for online series %s with access_control == 2" % self.shortname) elif self.access_control == 5: if self.access_registration is None: sts = False log_error( "access_registration is None for online series %s with access_control == 5" % self.shortname) if not self.topics: sts = False log_error("No topics set for series %s" % self.shortname) return sts