Exemple #1
0
def time_link(match):
    try:
        # full syntax [time:time|display]
        return "<a href='%s'>%s</a>" % (timestamp_to_url(
            match.group(1), anchor="closest"), match.group(2))
    except:
        # abbreviated syntax [time:time]
        return "<a href='%s'>%s</a>" % (timestamp_to_url(
            match.group(1), anchor="closest"), match.group(1))
Exemple #2
0
 def render_to_response(self, context):
     # Ensure that the request is always redirected to:
     # - The first page (timestampless)
     # - The timestamp for the start of an act
     # - The timestamp for the start of an in-act page
     # If the timestamp is already one of these, render as normal
     
     requested_start       = None
     if context['start']:
         requested_start   = timestamp_to_seconds( context['start'] )
     current_act           = context['current_act']
     first_log_line        = context['log_lines'][0]
     prior_log_line        = first_log_line.previous()
     
     # NOTE: is_act_first_page will be false for first act:
     #       that's handled by is_first_page
     is_first_page         = not prior_log_line
     is_act_first_page     = False
     if prior_log_line:
         is_act_first_page = prior_log_line.timestamp < current_act.start \
                          <= first_log_line.timestamp
     
     page_start_url = None
     # If we're on the first page, but have a timestamp,
     # redirect to the bare page URL
     if requested_start and is_first_page:
         if context['transcript_name'] != context['mission_main_transcript']:
             # Split transcript name from [mission]/[transcript]
             transcript = context['transcript_name'].split('/')[1]
             page_start_url = reverse("view_page", kwargs={"transcript": transcript})
         else:
             page_start_url = reverse("view_page")
     # If we're on the first page of an act,
     # but not on the act-start timestamp, redirect to that
     elif is_act_first_page \
     and requested_start != current_act.start:
         page_start_url = timestamp_to_url( context, current_act.start )
     # If we're on any other page and the timestamp doesn't match
     # the timestamp of the first item, redirect to that item's timestamp
     elif requested_start and not is_act_first_page \
     and requested_start != first_log_line.timestamp:
         page_start_url = timestamp_to_url(
             context,
             first_log_line.timestamp
         )
     
     # Redirect to the URL we found
     if page_start_url:
         if self.request.GET:
             page_start_url += '?%s' % self.request.GET.urlencode()
         return HttpResponseRedirect( page_start_url )
     
     return super( PageView, self ).render_to_response( context )
Exemple #3
0
    def render_to_response(self, context):
        # Ensure that the request is always redirected to:
        # - The first page (timestampless)
        # - The timestamp for the start of an act
        # - The timestamp for the start of an in-act page
        # If the timestamp is already one of these, render as normal

        requested_start = None
        if context['start']:
            requested_start = timestamp_to_seconds(context['start'])
        current_act = context['current_act']
        first_log_line = context['log_lines'][0]
        prior_log_line = first_log_line.previous()

        # NOTE: is_act_first_page will be false for first act:
        #       that's handled by is_first_page
        is_first_page = not prior_log_line
        is_act_first_page = False
        if prior_log_line:
            is_act_first_page = prior_log_line.timestamp < current_act.start \
                             <= first_log_line.timestamp

        page_start_url = None
        # If we're on the first page, but have a timestamp,
        # redirect to the bare page URL
        if requested_start and is_first_page:
            if context['transcript_name'] != context['mission_main_transcript']:
                # Split transcript name from [mission]/[transcript]
                transcript = context['transcript_name'].split('/')[1]
                page_start_url = reverse("view_page",
                                         kwargs={"transcript": transcript})
            else:
                page_start_url = reverse("view_page")
        # If we're on the first page of an act,
        # but not on the act-start timestamp, redirect to that
        elif is_act_first_page \
        and requested_start != current_act.start:
            page_start_url = timestamp_to_url(context, current_act.start)
        # If we're on any other page and the timestamp doesn't match
        # the timestamp of the first item, redirect to that item's timestamp
        elif requested_start and not is_act_first_page \
        and requested_start != first_log_line.timestamp:
            page_start_url = timestamp_to_url(context,
                                              first_log_line.timestamp)

        # Redirect to the URL we found
        if page_start_url:
            if self.request.GET:
                page_start_url += '?%s' % self.request.GET.urlencode()
            return HttpResponseRedirect(page_start_url)

        return super(PageView, self).render_to_response(context)
Exemple #4
0
def time_link(match):
    try:
        # full syntax [time:time|display]
        return "<a href='%s'>%s</a>" % (
            timestamp_to_url(match.group(1), anchor="closest"),
            match.group(2)
        )
    except:
        # abbreviated syntax [time:time]
        return "<a href='%s'>%s</a>" % (
            timestamp_to_url(match.group(1), anchor="closest"),
            match.group(1)
        )
Exemple #5
0
    def render_to_response(self, context):
        # Ensure that the request is always redirected to:
        # - The first page (timestampless)
        # - The timestamp for the start of an act
        # - The timestamp for the start of an in-act page
        # If the timestamp is already one of these, render as normal

        requested_start = None
        if context["start"]:
            requested_start = timestamp_to_seconds(context["start"])
        current_act = context["current_act"]
        first_log_line = context["log_lines"][0]
        prior_log_line = first_log_line.previous()

        # NOTE: is_act_first_page will be false for first act:
        #       that's handled by is_first_page
        is_first_page = not prior_log_line
        is_act_first_page = False
        if prior_log_line:
            is_act_first_page = prior_log_line.timestamp < current_act.start <= first_log_line.timestamp

        page_start_url = None
        # If we're on the first page, but have a timestamp,
        # redirect to the bare page URL
        if requested_start and is_first_page:
            page_start_url = reverse("view_page")
        # If we're on the first page of an act,
        # but not on the act-start timestamp, redirect to that
        elif is_act_first_page and requested_start != current_act.start:
            page_start_url = timestamp_to_url(current_act.start)
        # If we're on any other page and the timestamp doesn't match
        # the timestamp of the first item, redirect to that item's timestamp
        elif requested_start and not is_act_first_page and requested_start != first_log_line.timestamp:
            page_start_url = timestamp_to_url(first_log_line.timestamp)

        # Redirect to the URL we found
        if page_start_url:
            if self.request.GET:
                page_start_url += "?%s" % self.request.GET.urlencode()
            return HttpResponseRedirect(page_start_url)

        return super(PageView, self).render_to_response(context)
Exemple #6
0
def linkify(text, request=None):
    # Typographize double quotes
    text = re.sub(r'"([^"]+)"', r"&ldquo;\1&rdquo;", text)
    text = text.replace("'", "&apos;").replace("...", "&hellip;")
    # Time links
    text = re.sub(
        r"\[time:([\d:]+) ([^\]]+)\]",
        lambda m: "<a href='%s'>%s</a>" % (timestamp_to_url(m.group(1), anchor="closest"), m.group(2)),
        text,
    )
    # Glossary links
    text = re.sub(r"\[glossary:([^]]+) (\1)\]", lambda m: glossary_link(m, request), text)
    # Dashing through the text, with a one-space open sleigh
    text = text.replace("- -", "&mdash;").replace(" - ", "&mdash;").replace("--", "&mdash;")
    return mark_safe(text)