Skip to content

Commit

Permalink
use webutil.logs.maybe_link() for log links. fixes #767
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Dec 26, 2017
1 parent 3ef0645 commit 81c9d38
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 84 deletions.
17 changes: 7 additions & 10 deletions tasks.py
Expand Up @@ -15,18 +15,18 @@
import random
import urlparse

from oauth_dropins.webutil import logs
from google.appengine.api import memcache
from google.appengine.api import datastore_errors
from google.appengine.api.datastore_types import _MAX_STRING_LENGTH
from google.appengine.ext import ndb
from granary import source as gr_source
from granary.source import Source
import webapp2
from webmentiontools import send

import appengine_config

from oauth_dropins import handlers
from granary.source import Source
# need to import model class definitions since poll creates and saves entities.
import blogger
import facebook
Expand Down Expand Up @@ -67,10 +67,8 @@ class Poll(webapp2.RequestHandler):
RESTART_EXISTING_TASKS = False # overridden in Discover

def _last_poll_url(self, source):
return '%s/log?start_time=%s&key=%s' % (
self.request.host_url,
calendar.timegm(source.last_poll_attempt.utctimetuple()),
source.key.urlsafe())
return '%s/%s' % (self.request.host_url,
logs.url(source.last_poll_attempt, source.key))

def post(self, *path_args):
logging.debug('Params: %s', self.request.params)
Expand Down Expand Up @@ -777,10 +775,9 @@ def post(self):
return
logging.info('Source: %s %s, %s', source.label(), source.key.string_id(),
source.bridgy_url(self))
logging.info('Created by this poll: %s/log?start_time=%s&key=%s',
self.request.host_url,
calendar.timegm(self.entity.created.utctimetuple()) - 61,
source.key.urlsafe())
poll_estimate = self.entity.created - datetime.timedelta(seconds=61)
logging.info('Created by this poll: %s/%s', self.request.host_url,
logs.url(poll_estimate, source.key))

self.activities = [json.loads(a) for a in self.entity.activities_json]
response_obj = json.loads(self.entity.response_json)
Expand Down
4 changes: 1 addition & 3 deletions templates/admin_responses.html
Expand Up @@ -40,9 +40,7 @@ <h2>Active responses</h2>
</a>
{% endfor %}</td>

<td><a target="_blank"
href="/log?start_time={{ timestamp(r.updated) }}&key={{ r.key.urlsafe() }}">
{{ naturaltime(r.updated) }}</a></td>
<td>{{ logs.maybe_link(r.updated, r.key)|safe }}</td>

<td>{{ naturaltime(r.created) }}</td>

Expand Down
10 changes: 2 additions & 8 deletions templates/admin_sources.html
Expand Up @@ -22,17 +22,11 @@ <h2>Poll error sources</h2>
<tr>
<td><a target="_blank" href="{{ s.bridgy_path() }}">{{ s.label() }}</a></td>

<td><a href="/log?start_time={{ timestamp(s.last_poll_attempt) }}&key={{ s.key.urlsafe() }}"
title="{{ s.last_poll_attempt.isoformat() }}" target="_blank">
<time datetime="{{ s.last_poll_attempt.isoformat() }}">
{{ naturaltime(s.last_poll_attempt) }}</time></a></td>
<td>{{ logs.maybe_link(s.last_poll_attempt, s.key)|safe }}</td>

<td>
{% if s.last_polled and s.last_polled > EPOCH %}
<a href="/log?start_time={{ timestamp(s.last_polled) }}&key={{ s.key.urlsafe() }}"
title="{{ s.last_polled.isoformat() }}" target="_blank">
<time datetime="{{ s.last_polled.isoformat() }}">
{{ naturaltime(s.last_polled) }}</time></a></td>
{{ logs.maybe_link(s.last_polled, s.key)|safe }}
{% else %}
never
{% endif %}
Expand Down
32 changes: 12 additions & 20 deletions templates/blog_user.html
Expand Up @@ -74,17 +74,12 @@
{{ blogpost.pretty_url|safe }}

</div><div class="col-sm-4">
<a href="/log?start_time={{ timestamp(blogpost.updated) }}&key={{ blogpost.key.urlsafe() }}"
class="u-bridgy-log">
<time class="dt-updated" datetime="{{ blogpost.updated.isoformat() }}"
title="{{ blogpost.updated.ctime() }}">
{{ naturaltime(blogpost.updated) }}</time>
{% if blogpost.status == 'error' %}
<span title="Error" class="glyphicon glyphicon-exclamation-sign"></span>
{% else %}{% if blogpost.status == 'processing' %}
<span title="Processing" class="glyphicon glyphicon-transfer"></span>
{% endif %}{% endif %}
</a>
{{ logs.maybe_link(blogpost.updated, blogpost.key, 'u-bridgy-log')|safe }}
{% if blogpost.status == 'error' %}
<span title="Error" class="glyphicon glyphicon-exclamation-sign"></span>
{% else %}{% if blogpost.status == 'processing' %}
<span title="Processing" class="glyphicon glyphicon-transfer"></span>
{% endif %}{% endif %}

</div><div class="col-sm-1">
<form method="post" action="/retry">
Expand Down Expand Up @@ -131,15 +126,12 @@
{{ wm.pretty_target|safe }}

</div><div class="col-sm-3">
<a href="/log?start_time={{ timestamp(wm.updated) }}&key={{ wm.key.urlsafe() }}"
title="{{ wm.updated.ctime() }}">
{{ naturaltime(wm.updated) }}
{% if wm.status == 'failed' %}
<span title="Error" class="glyphicon glyphicon-exclamation-sign"></span>
{% else %}{% if wm.status == 'new' %}
<span title="Processing" class="glyphicon glyphicon-transfer"></span>
{% endif %}{% endif %}
</a>
{{ logs.maybe_link(wm.updated, wm.key)|safe }}
{% if wm.status == 'failed' %}
<span title="Error" class="glyphicon glyphicon-exclamation-sign"></span>
{% else %}{% if wm.status == 'new' %}
<span title="Processing" class="glyphicon glyphicon-transfer"></span>
{% endif %}{% endif %}

</div><div class="col-sm-2">
{% if wm.published.url %}
Expand Down
62 changes: 20 additions & 42 deletions templates/social_user.html
Expand Up @@ -97,24 +97,18 @@
<form method="post" action="/poll-now">
<!-- last poll -->
{% if source.last_poll_attempt == EPOCH %}
Not polled yet.
Not polled yet,
{% else %}
{% if source.poll_status == "error" %}
<span title="Error" class="glyphicon glyphicon-exclamation-sign"></span>
{% endif %}
Polled
<a href="/log?start_time={{ timestamp(source.last_poll_attempt) }}&key={{ source.key.urlsafe() }}">
<time class="dt-bridgy-last-polled"
datetime="{{ source.last_poll_attempt.isoformat() }}"
title="{{ source.last_poll_attempt.ctime() }}">
{{ naturaltime(source.last_poll_attempt) }}</time></a>,
{{ logs.maybe_link(source.last_poll_attempt, source.key, time_class='dt-bridgy-last-polled')|safe }},
{% endif %}

<!-- next poll -->
next in
<time class="dt-bridgy-next-poll" datetime="{{ next_poll.isoformat() }}"
title="{{ next_poll.ctime() }}">
{{ naturaltime(next_poll) }}</time>.
{{ logs.maybe_link(next_poll, source.key, time_class="dt-bridgy-next-poll")|safe }}.

<input name="key" type="hidden" value="{{ source.key.urlsafe() }}" />
<button id="poll-now-button" type="submit" class="btn btn-default">Poll now</button>
Expand All @@ -125,12 +119,9 @@
<!-- last_syndication_url -->
{% if source.last_syndication_url and source.last_syndication_url > EPOCH %}
Last <a href="/about#link">syndication link</a> found
<a href="/log?start_time={{ timestamp(source.last_syndication_url) }}&key={{ source.key.urlsafe() }}">
<time class="dt-bridgy-last-syndication-link"
datetime="{{ source.last_syndication_url.isoformat() }}"
title="{{ source.last_syndication_url.ctime() }}">
{{ naturaltime(source.last_syndication_url) }}</time>.
</a><br />
{{ logs.maybe_link(source.last_syndication_url, source.key,
time_class='dt-bridgy-last-syndication-link')|safe }}.
<br />
{% endif %}

<!-- last_webmention_sent -->
Expand All @@ -156,12 +147,8 @@
<a href="/about#link">Crawling</a> now. Check back in a minute!
{% else %}
Web site{{ s }} <a href="/about#link">crawled</a>
<a href="/log?start_time={{ timestamp(source.last_hfeed_refetch) }}&key={{ source.key.urlsafe() }}">
<time class="dt-bridgy-last-refetched"
datetime="{{ source.last_hfeed_refetch.isoformat() }}"
title="{{ source.last_hfeed_refetch.ctime() }}">
{{ naturaltime(source.last_hfeed_refetch) }}</time>.
</a>
{{ logs.maybe_link(source.last_hfeed_refetch, source.key,
time_class='dt-bridgy-last-refetched')|safe }}.
{% endif %}
{% endif %}
{% endwith %}
Expand Down Expand Up @@ -306,17 +293,12 @@
</ul>

</div><div class="col-sm-2">
<a href="/log?start_time={{ timestamp(response.updated) }}&key={{ response.key.urlsafe() }}"
class="u-bridgy-log">
<time class="dt-updated" datetime="{{ response.updated.isoformat() }}"
title="{{ response.updated.ctime() }}">
{{ naturaltime(response.updated) }}</time>
{% if response.status == 'error' %}
<span title="Error" class="glyphicon glyphicon-exclamation-sign"></span>
{% else %}{% if response.status == 'processing' %}
<span title="Processing" class="glyphicon glyphicon-transfer"></span>
{% endif %}{% endif %}
</a>
{{ logs.maybe_link(response.updated, response.key, link_class='u-bridgy-log')|safe }}
{% if response.status == 'error' %}
<span title="Error" class="glyphicon glyphicon-exclamation-sign"></span>
{% else %}{% if response.status == 'processing' %}
<span title="Processing" class="glyphicon glyphicon-transfer"></span>
{% endif %}{% endif %}

</div><div class="col-sm-1">
<form method="post" action="/retry">
Expand Down Expand Up @@ -377,16 +359,12 @@
{{ publish.pretty_page|safe }}

</div><div class="col-sm-4">
<a href="/log?start_time={{ timestamp(publish.updated) }}&key={{ publish.key.urlsafe() }}"
class="u-bridgy-log">
<time class="dt-updated" datetime="{{ publish.updated.isoformat() }}"
title="{{ publish.updated.ctime() }}">
{{ naturaltime(publish.updated) }}</time>
{% if publish.status == 'failed' %}
<span title="Error" class="glyphicon glyphicon-exclamation-sign"></span>
{% else %}{% if publish.status == 'new' %}
<span title="Processing" class="glyphicon glyphicon-transfer"></span>
{% endif %}{% endif %}
{{ logs.maybe_link(publish.updated, publish.key, link_class='u-bridgy-log')|safe }}.
{% if publish.status == 'failed' %}
<span title="Error" class="glyphicon glyphicon-exclamation-sign"></span>
{% else %}{% if publish.status == 'new' %}
<span title="Processing" class="glyphicon glyphicon-transfer"></span>
{% endif %}{% endif %}
</a>

</div><div class="col-sm-4">
Expand Down
2 changes: 1 addition & 1 deletion util.py
Expand Up @@ -7,7 +7,6 @@
import Cookie
import contextlib
import datetime
import humanize
import json
import logging
import re
Expand All @@ -20,6 +19,7 @@
from appengine_config import DEBUG
import bs4
from granary import source as gr_source
import humanize
import mf2py
from oauth_dropins.webutil import handlers as webutil_handlers
from oauth_dropins.webutil.models import StringIdModel
Expand Down

0 comments on commit 81c9d38

Please sign in to comment.