From 81c9d38b72a8979824ffdcc791bd000aca68b000 Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Tue, 26 Dec 2017 09:05:20 -0800 Subject: [PATCH] use webutil.logs.maybe_link() for log links. fixes #767 --- tasks.py | 17 ++++------ templates/admin_responses.html | 4 +-- templates/admin_sources.html | 10 ++---- templates/blog_user.html | 32 +++++++----------- templates/social_user.html | 62 +++++++++++----------------------- util.py | 2 +- 6 files changed, 43 insertions(+), 84 deletions(-) diff --git a/tasks.py b/tasks.py index 25315447..3f4921f6 100644 --- a/tasks.py +++ b/tasks.py @@ -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 @@ -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) @@ -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) diff --git a/templates/admin_responses.html b/templates/admin_responses.html index becd15cc..33bafe56 100644 --- a/templates/admin_responses.html +++ b/templates/admin_responses.html @@ -40,9 +40,7 @@

Active responses

{% endfor %} - - {{ naturaltime(r.updated) }} + {{ logs.maybe_link(r.updated, r.key)|safe }} {{ naturaltime(r.created) }} diff --git a/templates/admin_sources.html b/templates/admin_sources.html index 4e36ef36..a88e9374 100644 --- a/templates/admin_sources.html +++ b/templates/admin_sources.html @@ -22,17 +22,11 @@

Poll error sources

{{ s.label() }} - - + {{ logs.maybe_link(s.last_poll_attempt, s.key)|safe }} {% if s.last_polled and s.last_polled > EPOCH %} - - + {{ logs.maybe_link(s.last_polled, s.key)|safe }} {% else %} never {% endif %} diff --git a/templates/blog_user.html b/templates/blog_user.html index b6395901..2629c6c4 100644 --- a/templates/blog_user.html +++ b/templates/blog_user.html @@ -74,17 +74,12 @@ {{ blogpost.pretty_url|safe }}
- - - {% if blogpost.status == 'error' %} - - {% else %}{% if blogpost.status == 'processing' %} - - {% endif %}{% endif %} - + {{ logs.maybe_link(blogpost.updated, blogpost.key, 'u-bridgy-log')|safe }} + {% if blogpost.status == 'error' %} + + {% else %}{% if blogpost.status == 'processing' %} + + {% endif %}{% endif %}
@@ -131,15 +126,12 @@ {{ wm.pretty_target|safe }}
- - {{ naturaltime(wm.updated) }} - {% if wm.status == 'failed' %} - - {% else %}{% if wm.status == 'new' %} - - {% endif %}{% endif %} - + {{ logs.maybe_link(wm.updated, wm.key)|safe }} + {% if wm.status == 'failed' %} + + {% else %}{% if wm.status == 'new' %} + + {% endif %}{% endif %}
{% if wm.published.url %} diff --git a/templates/social_user.html b/templates/social_user.html index fa340254..c8238c5a 100644 --- a/templates/social_user.html +++ b/templates/social_user.html @@ -97,24 +97,18 @@ {% if source.last_poll_attempt == EPOCH %} - Not polled yet. + Not polled yet, {% else %} {% if source.poll_status == "error" %} {% endif %} Polled - - , + {{ logs.maybe_link(source.last_poll_attempt, source.key, time_class='dt-bridgy-last-polled')|safe }}, {% endif %} next in - . + {{ logs.maybe_link(next_poll, source.key, time_class="dt-bridgy-next-poll")|safe }}. @@ -125,12 +119,9 @@ {% if source.last_syndication_url and source.last_syndication_url > EPOCH %} Last syndication link found - - . -
+ {{ logs.maybe_link(source.last_syndication_url, source.key, + time_class='dt-bridgy-last-syndication-link')|safe }}. +
{% endif %} @@ -156,12 +147,8 @@ Crawling now. Check back in a minute! {% else %} Web site{{ s }} crawled - - . - + {{ logs.maybe_link(source.last_hfeed_refetch, source.key, + time_class='dt-bridgy-last-refetched')|safe }}. {% endif %} {% endif %} {% endwith %} @@ -306,17 +293,12 @@
- - - {% if response.status == 'error' %} - - {% else %}{% if response.status == 'processing' %} - - {% endif %}{% endif %} - + {{ logs.maybe_link(response.updated, response.key, link_class='u-bridgy-log')|safe }} + {% if response.status == 'error' %} + + {% else %}{% if response.status == 'processing' %} + + {% endif %}{% endif %}
@@ -377,16 +359,12 @@ {{ publish.pretty_page|safe }}
- - - {% if publish.status == 'failed' %} - - {% else %}{% if publish.status == 'new' %} - - {% endif %}{% endif %} + {{ logs.maybe_link(publish.updated, publish.key, link_class='u-bridgy-log')|safe }}. + {% if publish.status == 'failed' %} + + {% else %}{% if publish.status == 'new' %} + + {% endif %}{% endif %}
diff --git a/util.py b/util.py index 45d365e2..672b37a7 100644 --- a/util.py +++ b/util.py @@ -7,7 +7,6 @@ import Cookie import contextlib import datetime -import humanize import json import logging import re @@ -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