-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from google/gimite-zero-rating2
Make ToS page a proxy to the actual ToS page, to make it zero-rating mode friendly. #7
- Loading branch information
Showing
8 changed files
with
111 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,3 +43,5 @@ handlers: | |
libraries: | ||
- name: django | ||
version: "1.2" | ||
- name: lxml | ||
version: "2.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,40 @@ | ||
{# Terms of Service page for a new site. Fill in content below. #} | ||
{# Copyright 2015 Google Inc. Licensed under the Apache License, Version #} | ||
{# 2.0 (the "License"); you may not use this file except in compliance with #} | ||
{# the License. You may obtain a copy of the License at: #} | ||
{# http://www.apache.org/licenses/LICENSE-2.0 #} | ||
{# Unless required by applicable law or agreed to in writing, software #} | ||
{# distributed under the License is distributed on an "AS IS" BASIS, #} | ||
{# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #} | ||
{# See the License for the specific language governing permissions and #} | ||
{# limitations under the License. #} | ||
|
||
{# Template for the Terms of Service page. #} | ||
|
||
{% extends "static-base.html.template" %} | ||
{% load i18n %} | ||
|
||
{% block content %} | ||
<h1>Terms of Service</h1> | ||
|
||
<p> | ||
(This page has not been filled in by the site owner. | ||
It is recommended that site owners specify their Terms of Service | ||
when launching a Person Finder site. Site owners should see the | ||
<a href="https://github.com/google/personfinder">project page</a> | ||
for instructions on filling in the content of this page.) | ||
{% endblock content %} | ||
|
||
{% if article_html %} | ||
|
||
{{article_html|safe}} | ||
|
||
{% else %}{% if tos_url %} | ||
|
||
<h1>Terms of Service</h1> | ||
|
||
{# In case we fail to fetch/parse the ToS page (e.g., the page has #} | ||
{# changed its layout), we fall back to show a link to the page instead. #} | ||
<p><a href="{{tos_url}}">Click here to see the terms of service (external site)</a></p> | ||
|
||
{% else %} | ||
|
||
<h1>Terms of Service</h1> | ||
|
||
<p>The term of service is not specified by the site owner.</p> | ||
|
||
<p>If you are the site owner, you can specify the URL of the terms of service to "tos_url" config. See <a href="https://github.com/google/personfinder/wiki/DeveloperFaq#how-to-readwrite-config-values">here</a> to learn how to update configs.</p> | ||
|
||
{% endif %}{% endif %} | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/python2.7 | ||
# Copyright 2015 Google Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Terms of Services page.""" | ||
|
||
__author__ = 'ichikawa@google.com (Hiroshi Ichikawa)' | ||
|
||
import logging | ||
import traceback | ||
import urllib2 | ||
import urlparse | ||
|
||
import lxml.etree | ||
|
||
import utils | ||
|
||
|
||
class Handler(utils.BaseHandler): | ||
|
||
repo_required = False | ||
|
||
def get(self): | ||
article_html = None | ||
|
||
# Fetches the ToS page and embed it in the page. We do this instead of | ||
# just redirecting to the ToS page because we need to host the content | ||
# in our domain in zero-rating mode. See "Zero-rating" section of the | ||
# admin page (app/resources/admin.html.template) for details of | ||
# zero-rating mode. | ||
try: | ||
if self.config.tos_url: | ||
res = urllib2.urlopen(self.config.tos_url) | ||
tos_html = res.read() | ||
doc = lxml.etree.HTML(tos_html) | ||
articles = doc.xpath("//div[@class='maia-article']") | ||
if articles: | ||
article = articles[0] | ||
for anchor in article.xpath('.//a'): | ||
href = anchor.attrib.get('href') | ||
if href and anchor.text: | ||
# Converts relative URLs to absolute URLs. | ||
anchor.attrib['href'] = urlparse.urljoin( | ||
res.geturl(), href) | ||
anchor.text += ' (external site)' | ||
article_html = lxml.etree.tostring(article, method='html') | ||
|
||
except: | ||
logging.error( | ||
'Error during fetching/parsing the ToS page from %s\n%s', | ||
self.config.tos_url, | ||
traceback.format_exc()) | ||
|
||
self.render( | ||
'tos.html', | ||
article_html=article_html, | ||
tos_url=self.config.tos_url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters