Browse Source

Support general/update notices.

pull/24/head
Ben Kurtovic 8 years ago
parent
commit
b325ef84cd
4 changed files with 41 additions and 5 deletions
  1. +4
    -2
      app.py
  2. +11
    -1
      copyvios/misc.py
  3. +21
    -2
      static/style.css
  4. +5
    -0
      templates/index.mako

+ 4
- 2
app.py View File

@@ -16,7 +16,7 @@ from flask.ext.mako import MakoTemplates, render_template, TemplateError
from copyvios.api import format_api_error, handle_api_request
from copyvios.checker import do_check
from copyvios.cookies import parse_cookies
from copyvios.misc import cache
from copyvios.misc import cache, get_notice
from copyvios.settings import process_settings
from copyvios.sites import update_sites

@@ -80,9 +80,11 @@ def close_databases(error):
@app.route("/")
@catch_errors
def index():
notice = get_notice()
update_sites()
query = do_check()
return render_template("index.mako", query=query, result=query.result)
return render_template(
"index.mako", notice=notice, query=query, result=query.result)

@app.route("/settings", methods=["GET", "POST"])
@catch_errors


+ 11
- 1
copyvios/misc.py View File

@@ -8,7 +8,7 @@ from sqlalchemy.pool import manage

oursql = manage(oursql)

__all__ = ["Query", "cache", "get_db", "httpsfix", "urlstrip"]
__all__ = ["Query", "cache", "get_db", "get_notice", "httpsfix", "urlstrip"]

class Query(object):
def __init__(self, method="GET"):
@@ -49,6 +49,16 @@ def get_db():
g._db = oursql.connect(**args)
return g._db

def get_notice():
try:
with open(expanduser("~/copyvios_notice.html")) as fp:
lines = fp.read().decode("utf8").strip().splitlines()
if lines[0] == "<!-- active -->":
return "\n".join(lines[1:])
return None
except IOError:
return None

def httpsfix(context, url):
if url.startswith("http://"):
url = url[len("http:"):]


+ 21
- 2
static/style.css View File

@@ -44,9 +44,23 @@ div#footer {
background: #DDDDDD;
}

div#notice-box {
padding: 10px;
margin: 10px 5px;
}

div#notice-box p {
margin: 0.25em 0;
}

div#notice-box ul {
padding-left: 1.5em;
margin: 0;
}

div#info-box {
padding: 0 10px 0 10px;
margin: 10px 5px 10px 5px;
padding: 0 10px;
margin: 10px 5px;
}

div#cv-result {
@@ -235,6 +249,11 @@ div.red-box {
border: 1px solid #F77;
}

div.gray-box {
background-color: #EEE;
border: 1px solid #AAA;
}

div.indentable {
white-space: pre-wrap;
}


+ 5
- 0
templates/index.mako View File

@@ -6,6 +6,11 @@
<%include file="/support/header.mako" args="title='Earwig\'s Copyvio Detector'"/>
<%namespace module="copyvios.highlighter" import="highlight_delta"/>\
<%namespace module="copyvios.misc" import="httpsfix, urlstrip"/>\
% if notice:
<div id="notice-box" class="gray-box">
${notice}
</div>
% endif
% if query.submitted:
% if query.error:
<div id="info-box" class="red-box"><p>


Loading…
Cancel
Save