Browse Source

More work on the settings page.

pull/24/head
Ben Kurtovic 14 years ago
parent
commit
9677390ea3
4 changed files with 69 additions and 11 deletions
  1. +61
    -5
      pages/settings.mako
  2. +3
    -5
      toolserver/copyvios/__init__.py
  3. +4
    -0
      toolserver/misc.py
  4. +1
    -1
      toolserver/sites.py

+ 61
- 5
pages/settings.mako View File

@@ -1,10 +1,66 @@
<%include file="/support/header.mako" args="environ=environ, title='Settings'"/>
<%include file="/support/header.mako" args="environ=environ, title='Settings'"/>\
<%namespace module="toolserver.misc" import="get_bot, parse_cookies"/>\
<%namespace module="toolserver.sites" import="get_sites"/>\
<% cookies = parse_cookies(environ) %>
<% langs, projects = get_sites(get_bot()) %>
<h1>Settings</h1> <h1>Settings</h1>
<p>This page contains some configurable options for this Toolserver site. Settings are saved as cookies. You can view and delete all cookies generated by this site at the bottom of this page.</p> <p>This page contains some configurable options for this Toolserver site. Settings are saved as cookies. You can view and delete all cookies generated by this site at the bottom of this page.</p>
<h2>Options</h2> <h2>Options</h2>
<ul>
<li>Default site:</li>
<li>Background</li>
</ul>
<table>
<tr>
<form action="${environ['PATH_INFO']}" method="post">
<input type="hidden" name="action" value="setDefaultSite">
<td>Default site:</td>
<td>
<tt>http://</tt>
<select name="lang">
% for code, name in langs:
% if "EarwigDefaultLang" in cookies and code == cookies["EarwigDefaultLang"].value:
<option value="${code}" selected="selected">${name}</option>
% else:
<option value="${code}">${name}</option>
% endif
% endfor
</select>
<tt>.</tt>
<select name="project">
% for code, name in projects:
% if "EarwigDefaultProject" in cookies and code == cookies["EarwigDefaultProject"].value:
<option value="${code}" selected="selected">${name}</option>
% else:
<option value="${code}">${name}</option>
% endif
% endfor
</select>
<tt>.org</tt>
</td>
<td><button type="submit">Save</button></td>
</form>
</tr>
<tr>
<td>Background:</td>
</tr>
</table>
<h2>Cookies</h2> <h2>Cookies</h2>
% if cookies:
<ul>
% for cookie in cookies:
<li>
<tt>${cookie.name | h}</tt>: <tt>${cookie.value | h}</tt>
<form action="${environ['PATH_INFO']}" method="post">
<input type="hidden" name="action" value="deleteCookie">
<input type="hidden" name="cookie" value="${cookie.name | h}">
<button type="submit">Delete</button>
</form>
</li>
% endfor
</ul>
<form action="${environ['PATH_INFO']}" method="post">
<input type="hidden" name="action" value="deleteCookie">
<input type="hidden" name="all" value="1">
<button type="submit">Delete all</button>
</form>
% else:
<p>No cookies!</p>
% endif
<%include file="/support/footer.mako" args="environ=environ"/> <%include file="/support/footer.mako" args="environ=environ"/>

+ 3
- 5
toolserver/copyvios/__init__.py View File

@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-


from earwigbot.bot import Bot

from .checker import get_results from .checker import get_results
from .highlighter import highlight_delta from .highlighter import highlight_delta
from ..misc import Query
from ..misc import get_bot, Query
from ..sites import get_site, get_sites from ..sites import get_site, get_sites


def main(context, environ): def main(context, environ):
@@ -16,8 +14,8 @@ def main(context, environ):
if query.project: if query.project:
query.project = query.project.lower() query.project = query.project.lower()


bot = Bot(".earwigbot")
all_langs, all_projects = get_sites(bot)
bot = get_bot(context)
all_langs, all_projects = get_sites(context, bot)
page = result = None page = result = None
if query.lang and query.project and query.title: if query.lang and query.project and query.title:
site = get_site(bot, query, all_projects) site = get_site(bot, query, all_projects)


+ 4
- 0
toolserver/misc.py View File

@@ -4,6 +4,7 @@ from Cookie import CookieError, SimpleCookie
from os.path import expanduser from os.path import expanduser
from urlparse import parse_qs from urlparse import parse_qs


from earwigbot.bot import Bot
import oursql import oursql


class Query(object): class Query(object):
@@ -47,6 +48,9 @@ def urlstrip(context, url):
url = url[:-1] url = url[:-1]
return url return url


def get_bot(context):
return Bot(".earwigbot")

def parse_cookies(context, environ): def parse_cookies(context, environ):
try: try:
return SimpleCookie(environ["HTTP_COOKIE"]) return SimpleCookie(environ["HTTP_COOKIE"])


+ 1
- 1
toolserver/sites.py View File

@@ -27,7 +27,7 @@ def get_site(bot, query, all_projects):
except (exceptions.APIError, exceptions.LoginError): except (exceptions.APIError, exceptions.LoginError):
return None return None


def get_sites(bot):
def get_sites(context, bot):
max_staleness = 60 * 60 * 24 * 7 max_staleness = 60 * 60 * 24 * 7
conn = open_sql_connection(bot, "globals") conn = open_sql_connection(bot, "globals")
query1 = "SELECT update_time FROM updates WHERE update_service = ?" query1 = "SELECT update_time FROM updates WHERE update_service = ?"


Loading…
Cancel
Save