Sfoglia il codice sorgente

More work on the settings page.

pull/24/head
Ben Kurtovic 12 anni fa
parent
commit
9677390ea3
4 ha cambiato i file con 69 aggiunte e 11 eliminazioni
  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 Vedi 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>
<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>
<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>
% 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"/>

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

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

from earwigbot.bot import Bot

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

def main(context, environ):
@@ -16,8 +14,8 @@ def main(context, environ):
if query.project:
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
if query.lang and query.project and query.title:
site = get_site(bot, query, all_projects)


+ 4
- 0
toolserver/misc.py Vedi File

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

from earwigbot.bot import Bot
import oursql

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

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

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


+ 1
- 1
toolserver/sites.py Vedi File

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

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


Caricamento…
Annulla
Salva