Exemplo n.º 1
0
    def show_time_and_duration(self, adapt=True):
        start = self.start_time
        end = self.end_time
        now = datetime.now(pytz.utc)
        newtz = None if adapt else self.tz

        def ans(rmk):
            return "%s-%s (%s)" % (
                adapt_datetime(start,
                               newtz=newtz).strftime("%a %b %-d, %H:%M"),
                adapt_datetime(end, newtz=newtz).strftime("%H:%M"),
                rmk,
            )

        # Add remark on when this is
        if start <= now <= end:
            return ans("ongoing")
        elif now < start:
            delta = start - now
            return ans("starts in " + how_long(delta)) if delta < timedelta(
                hours=36) else ans(how_long(delta) + " from now")
        else:
            delta = now - end
            return ans("ended " + how_long(delta) +
                       " ago") if delta < timedelta(
                           hours=36) else ans(how_long(delta) + " ago")
Exemplo n.º 2
0
    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 ""