template-inheritance&white-template(wip)

This commit is contained in:
Martijn Voncken 2008-03-09 19:13:09 +00:00
parent b5e4fdaa04
commit 5c02a9cb82
27 changed files with 507 additions and 148 deletions

View File

@ -72,6 +72,7 @@ menu_manager.register_admin_page("logout", _("Logout"), "/logout")
menu_manager.register_detail_tab("details", _("Details"), "tab_meta") menu_manager.register_detail_tab("details", _("Details"), "tab_meta")
menu_manager.register_detail_tab("files", _("Files"), "tab_files") menu_manager.register_detail_tab("files", _("Files"), "tab_files")
menu_manager.register_detail_tab("options", _("Options"), "tab_options") menu_manager.register_detail_tab("options", _("Options"), "tab_options")
menu_manager.register_detail_tab("trackers", _("Trackers"), "tab_trackers")
menu_manager.register_toolbar_item("add", _("Add"), "list-add.png" , TB.generic, menu_manager.register_toolbar_item("add", _("Add"), "list-add.png" , TB.generic,
"GET","/torrent/add/", True) "GET","/torrent/add/", True)
@ -132,7 +133,8 @@ urls = [
#default-pages #default-pages
"/", "home", "/", "home",
"", "home", "", "home",
"/robots.txt","robots" "/robots.txt","robots",
"/template_style.css","template_style"
] ]
#/routing #/routing
@ -464,6 +466,12 @@ class robots:
web.header("Content-Type", "text/plain") web.header("Content-Type", "text/plain")
print "User-agent: *\nDisallow:/\n" print "User-agent: *\nDisallow:/\n"
class template_style:
def GET(self):
web.header("Content-Type", "text/css")
style = Storage()
print render.template_style(style)
#/pages #/pages
#for plugins.. #for plugins..

View File

@ -34,13 +34,13 @@ from webserver_common import ws,REVNO,VERSION
from utils import * from utils import *
#/relative #/relative
from deluge import common from deluge import common
from lib.webpy022 import changequery as self_url, template from lib.webpy022 import changequery as self_url, template, Storage
import os import os
class subclassed_render(object): class subclassed_render(object):
""" """
try to use the html template in configured dir. adds limited subclassing for templates.
not available : use template in /deluge/ see: meta.cfg in the template-directory.
""" """
def __init__(self): def __init__(self):
self.apply_cfg() self.apply_cfg()
@ -51,13 +51,15 @@ class subclassed_render(object):
self.plugin_renderers = [] self.plugin_renderers = []
self.template_cache = {} self.template_cache = {}
#future: better/more subclassing. #load template-meta-data
self.renderers.append(template.render( cfg_template = ws.config.get('template')
os.path.join(ws.webui_path, 'templates/%s/' % ws.config.get('template')), template_path = os.path.join(ws.webui_path, 'templates/%s/' % cfg_template)
cache=False)) self.meta = Storage(eval(open(os.path.join(template_path,'meta.cfg')).read()))
self.renderers.append(template.render( #load renerders
os.path.join(ws.webui_path, 'templates/deluge/'),cache=False)) for template_name in [cfg_template] + list(reversed(self.meta.inherits)):
self.renderers.append(template.render(
os.path.join(ws.webui_path, 'templates/%s/' % template_name),cache=False))
@logcall @logcall
def register_template_path(self, path): def register_template_path(self, path):

View File

@ -1,11 +1,11 @@
$def with (title) $def with (title, active_tab=None)
<html> <html>
<head> <head>
<title>Deluge:$title</title> <title>Deluge:$title</title>
<link rel="icon" href="/static/images/deluge_icon.gif" type="image/gif" /> <link rel="icon" href="/static/images/deluge_icon.gif" type="image/gif" />
<link rel="shortcut icon" href="/static/images/deluge_icon.gif" type="image/gif" /> <link rel="shortcut icon" href="/static/images/deluge_icon.gif" type="image/gif" />
<link rel="stylesheet" type="text/css" href="/template/static/advanced.css" /> <link rel="stylesheet" type="text/css" href="/template/static/advanced.css" />
<script language="javascript" src="/template/static/deluge.js"></script> <script language="javascript" src="/static/deluge.js"></script>
<!--<link rel="stylesheet" type="text/css" href="/template/static/scrolling_table.css" /> <!--<link rel="stylesheet" type="text/css" href="/template/static/scrolling_table.css" />
--> -->

View File

@ -1,112 +1,16 @@
$def with (torrent_list, organize_filters) $def with (torrent_list, organize_filters)
$:render.header(_('Torrent list')) $:render.header(_('Torrent list'))
<script language="javascript">
/*for select_all shortcut/button*/
var all_torrents = [
$for t in torrent_list:
"$t.id",
]
</script>
<div class="panel" id="toolbar"> <div class="panel" id="toolbar">
$:render.part_toolbar()
$for id, title, image, flag, method, url, important in toolbar_items:
$if important:
<a class='toolbar_btn' href="#"
onclick='toolbar_$(method.lower()) ("$url",$flag)'
title='$title'><img class='toolbar_btn'
src='/static/images/tango/$image'></a>
$if organize_filters: $if organize_filters:
$:render.part_categories(organize_filters) $:render.part_organize(organize_filters)
</div>
<div id="tableContainer" class="tableContainer">
<table class="torrent_list" border=0 cellspacing=0 cellpadding=2 id="torrent_list" >
<thead class="fixedHeader">
<tr>
$:(sort_head('calc_state_str', 'S'))
$:(sort_head('queue', '#'))
$:(sort_head('name', _('Name')))
$:(sort_head('total_size', _('Size')))
$:(sort_head('progress', _('Progress')))
$if organize_filters:
<!--HACK:
abusing organize_filters to check if the Orgnize plugin is enabled
-->
$:(sort_head('tracker_name', _('Tracker')))
$:(sort_head('num_seeds', _('Seeders')))
$:(sort_head('num_peers', _('Peers')))
$:(sort_head('download_rate', _('Download')))
$:(sort_head('upload_rate', _('Upload')))
$:(sort_head('eta', _('Eta')))
$:(sort_head('distributed_copies', _('Ava')))
$:(sort_head('ratio', _('Ratio')))
</tr>
</thead>
<tbody class="scrollContent">
$altrow(True)
$#4-space indentation is mandatory for for-loops in templetor!
$for torrent in torrent_list:
<tr class="$altrow()" onclick="on_click_row(event, '$torrent.id')" id="torrent_$torrent.id">
<td>
<form action="/torrent/$torrent.action/$torrent.id" method="POST"
class="pause_resume">
<input type="image"
src="/static/images/$(torrent.calc_state_str)16.png"
name="pauseresume" value="submit" />
</form>
</td>
<td>$torrent.queue</td>
<td style="width:100px; overflow:hidden;white-space: nowrap">
$(crop(torrent.name, 40))</td>
<td>$fsize(torrent.total_size)</td>
<td class="progress_bar">
<div class="progress_bar_outer">
<div class="progress_bar" style="width:$(torrent.progress)%;overflow:hidden">
$torrent.message $int(torrent.progress) %
</div>
</div>
</td>
$if organize_filters:
<td>$torrent.tracker_name</td>
<td>
$if torrent.total_seeds != -1:
$torrent.num_seeds ($torrent.total_seeds)
$else:
0
</td>
<td>
$if torrent.total_peers != -1:
$torrent.num_peers ($torrent.total_peers)</td>
$else:
0
<td>
$if (torrent.download_rate):
$fspeed(torrent.download_rate)
$else:
&nbsp;
</td>
<td>
$if (torrent.upload_rate):
$fspeed(torrent.upload_rate)
$else:
&nbsp;
</td>
<td>$ftime(torrent.eta)</td>
<td>$("%.3f" % torrent.distributed_copies)</td>
<td>$("%.3f" % torrent.ratio)</td\>
</tr>
</tbody>
</table>
</div> </div>
$:render.part_torrent_list(torrent_list, organize_filters)
$:render.part_auto_refresh()
$:part_stats() $:part_stats()
<div class="panel" id="info_panel_div"> <div class="panel" id="info_panel_div">

View File

@ -0,0 +1,10 @@
{
'authors':['Martijn Voncken <mvoncken@gmail.com>'],
'inherits':['deluge'],
'comment':"""
The default template.
Uses advanced css/javascript.
You need a newer standards compliant browser.
"""
}

View File

@ -0,0 +1,16 @@
<div class="panel" id='refresh_panel'>
[
$_('Auto refresh:')
$if getcookie('auto_refresh') == '1':
($getcookie('auto_refresh_secs')) $_('seconds') &nbsp;
<a href="/refresh/set">$_('Set')</a>
<a href="/refresh/off">$_('Disable')</a><!--WRONG, setting things on a GET-->
$else:
$_('Off') &nbsp;
<a href="/refresh/on">$_('Enable')</a><!--WRONG, setting things on a GET-->
]
<a href="/config/">$_('Admin') </a>&nbsp;
</div>

View File

@ -1,23 +1,6 @@
$def with (stats) $def with (stats)
<div class="panel" id='refresh_panel'>
[
$_('Auto refresh:')
$if getcookie('auto_refresh') == '1':
($getcookie('auto_refresh_secs')) $_('seconds') &nbsp;
<a href="/refresh/set">$_('Set')</a>
<a href="/refresh/off">$_('Disable')</a><!--WRONG, setting things on a GET-->
$else:
$_('Off') &nbsp;
<a href="/refresh/on">$_('Enable')</a><!--WRONG, setting things on a GET-->
]
<a href="/config/">$_('Admin') </a>&nbsp;
</div>
<div class="panel" id='stats_panel'> <div class="panel" id='stats_panel'>
<!--<a href='/config'>--> <!--<a href='/config'>-->
@ -36,10 +19,3 @@ $else:
<!--</a>--> <!--</a>-->
</div> </div>
<div id='about'>
<a href='/about'>$_('About')</a>
</div>

View File

@ -0,0 +1,6 @@
$for id, title, image, flag, method, url, important in toolbar_items:
$if important:
<a class='toolbar_btn' href="#"
onclick='toolbar_$(method.lower()) ("$url",$flag)'
title='$title'><img class='toolbar_btn'
src='/static/images/tango/$image'></a>

View File

@ -0,0 +1,90 @@
$def with (torrent_list, organize_filters)
<script language="javascript">
/*for select_all shortcut/button*/
var all_torrents = [
$for t in torrent_list:
"$t.id",
]
</script>
<table class="torrent_list" id="torrent_table" border=0 cellspacing=0 cellpadding=2 id="torrent_list" >
<thead class="fixedHeader">
<tr>
$:(sort_head('calc_state_str', 'S'))
$:(sort_head('queue', '#'))
$:(sort_head('name', _('Name')))
$:(sort_head('total_size', _('Size')))
$:(sort_head('progress', _('Progress')))
$if organize_filters:
<!--HACK:
abusing organize_filters to check if the Orgnize plugin is enabled
-->
$:(sort_head('tracker_name', _('Tracker')))
$:(sort_head('num_seeds', _('Seeders')))
$:(sort_head('num_peers', _('Peers')))
$:(sort_head('download_rate', _('Download')))
$:(sort_head('upload_rate', _('Upload')))
$:(sort_head('eta', _('Eta')))
$:(sort_head('distributed_copies', _('Ava')))
$:(sort_head('ratio', _('Ratio')))
</tr>
</thead>
<tbody class="scrollContent">
$altrow(True)
$#4-space indentation is mandatory for for-loops in templetor!
$for torrent in torrent_list:
<tr class="$altrow()" onclick="on_click_row(event, '$torrent.id')" id="torrent_$torrent.id">
<td>
<form action="/torrent/$torrent.action/$torrent.id" method="POST"
class="pause_resume">
<input type="image"
src="/static/images/$(torrent.calc_state_str)16.png"
name="pauseresume" value="submit" />
</form>
</td>
<td>$torrent.queue</td>
<td style="width:100px; overflow:hidden;white-space: nowrap">
$(crop(torrent.name, 40))</td>
<td>$fsize(torrent.total_size)</td>
<td class="progress_bar">
<div class="progress_bar_outer">
<div class="progress_bar" style="width:$(torrent.progress)%;overflow:hidden">
$torrent.message $int(torrent.progress) %
</div>
</div>
</td>
$if organize_filters:
<td>$torrent.tracker_name</td>
<td>
$if torrent.total_seeds != -1:
$torrent.num_seeds ($torrent.total_seeds)
$else:
0
</td>
<td>
$if torrent.total_peers != -1:
$torrent.num_peers ($torrent.total_peers)</td>
$else:
0
<td>
$if (torrent.download_rate):
$fspeed(torrent.download_rate)
$else:
&nbsp;
</td>
<td>
$if (torrent.upload_rate):
$fspeed(torrent.upload_rate)
$else:
&nbsp;
</td>
<td>$ftime(torrent.eta)</td>
<td>$("%.3f" % torrent.distributed_copies)</td>
<td>$("%.3f" % torrent.ratio)</td\>
</tr>
</tbody>
</table>

View File

@ -71,7 +71,7 @@ div.error {
} }
tr.torrent_table:hover { #torrent_table tr:hover {
background-color:#68a; background-color:#68a;
} }

View File

@ -1,8 +1,15 @@
$:render.header(_('About')) $:render.header(_('About'), 'about')
$:render.admin_toolbar('about') $:render.admin_toolbar('about')
<div class="panel" style="text-align:left"> <div class="panel" style="text-align:left">
<h2>Version</h2> <h2>Version</h2>
<pre>$version </pre> <pre>$version </pre>
<h2>Template</h2>
Name: $get_config('template')<br />
Authors: $render.meta.authors<br />
Inherits: $render.meta.inherits<br />
Comment: $render.meta.comment
<h2>Links</h2> <h2>Links</h2>
<ul> <ul>
<li><a href="http://deluge-torrent.org">Deluge</a></li> <li><a href="http://deluge-torrent.org">Deluge</a></li>
@ -34,6 +41,13 @@ $:render.admin_toolbar('about')
<ul> <ul>
<li>Slurdge</li> <li>Slurdge</li>
</ul> </ul>
<h3>Console UI</h3>
<ul>
<li>sadrul</li>
</ul>
</div> </div>
*and all other authors/helpers/contributors I forgot to mention</li> *and all other authors/helpers/contributors I forgot to mention</li>

View File

@ -1,6 +1,6 @@
$def with (groups, pages, form, selected, message, error) $def with (groups, pages, form, selected, message, error)
$:render.header(_("Config")) $:render.header(_("Config"), 'config')
$:render.admin_toolbar('config') $:render.admin_toolbar('config')
<!--left block--> <!--left block-->

View File

@ -1,6 +1,6 @@
$def with (connect_list, connected) $def with (connect_list, connected)
$:render.header(_("Connect to Daemon")) $:render.header(_("Connect to Daemon"), 'connect')
$:render.admin_toolbar('connect') $:render.admin_toolbar('connect')

View File

@ -1,4 +1,4 @@
$def with (title) $def with (title, active_tab="NONE")
<html> <html>
<head> <head>
<title>Deluge:$title</title> <title>Deluge:$title</title>

View File

@ -1,5 +1,9 @@
$def with (torrent_list, organize_filter) $def with (torrent_list, organize_filters)
$:render.header(_('Torrent list')) $:render.header(_('Torrent list'), 'home')
$if organize_filters:
$:render.part_organize(organize_filters)
<table class="torrent_list" border=0 id='torrent_table'> <table class="torrent_list" border=0 id='torrent_table'>
<tr> <tr>

View File

@ -0,0 +1,10 @@
{
'authors':['Martijn Voncken <mvoncken@gmail.com>'],
'inherits':[],
'comment':"""Fail-safe template.
Most other templetes inherit from this template.
Should work on ANY browser.
thanks to "somedude" for some help/enhancements in header/footer/css.
"""
}

View File

@ -0,0 +1,16 @@
$def with (torrent)
<table width="95%">
$altrow(True)
<tr class="tab_$altrow()">
<th width="10px">#</th>
<th width="100%">$_("Tracker")</th>
$for tracker in torrent.trackers:
<tr class="tab_$altrow()" >
<td >
$tracker['tier']
</td>
<td title="tracker">$crop(tracker['url'], 60)</td>
</tr>
</table>

View File

@ -34,9 +34,4 @@ function toggle_dump(){
</div> </div>
$:part_stats()
$:render.footer() $:render.footer()

View File

@ -0,0 +1,3 @@
$def with (active_tab)
<!--no admin toolbar, already done in header.-->

View File

@ -0,0 +1,46 @@
$def with (title, active_tab="NONE")
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Deluge:$_('Torrent list')</title>
<link rel="icon" href="/static/images/deluge_icon.gif" type="image/gif" />
<link rel="shortcut icon" href="/static/images/deluge_icon.gif" type="image/gif" />
<link rel="stylesheet" type="text/css" href="/template_style.css" />
<script language="javascript" src="/static/deluge.js"></script>
</head>
<body>
<div id="page">
<table width="100%"><tr>
<td>
<div id="home_top">
<a
$if 'home' == active_tab:
class="tab_button_active"
$else:
class="tab_button"
href='/home'>Home</a>
<!--ADMIN-TABS-->
$for id, title, url in admin_pages:
<a
$if id == active_tab:
class="tab_button_active"
$else:
class="tab_button"
href='$url'>$title</a>
</div>
</td><td align="right">
$#:render.part_auto_refresh()
</td><td>
</td><td align="right" width="320px">
$:part_stats()
</td></tr><table>
<hr>

View File

@ -0,0 +1,80 @@
$def with (torrent_list, organize_filters)
<html>
<head>
<title>Deluge:$_('Torrent list')</title>
<link rel="icon" href="/static/images/deluge_icon.gif" type="image/gif" />
<link rel="shortcut icon" href="/static/images/deluge_icon.gif" type="image/gif" />
<link rel="stylesheet" type="text/css" href="/template_style.css" />
<script language="javascript" src="/static/deluge.js"></script>
</head>
<body>
<div id="page">
<table width="100%"><tr>
<td>
<div id="home_top">
<a class="tab_button_active" href='/home'>Home</a>
$for id, title, url in admin_pages:
<a class="tab_button" href='$url'>$title</a>
</td><td align="right">
$#:render.part_auto_refresh()
</td><td>
</td><td align="right" width="320px">
$:part_stats()
</td></tr><table>
<hr>
<div id="organize_block">
$if organize_filters:
$:render.part_organize(organize_filters)
</div>
<table id="torrent_list_block">
<tr><td>
<div id="toolbar">
$:render.part_toolbar()
</div>
</td></tr><tr><td>
$:render.part_torrent_list(torrent_list, organize_filters)
</td></tr>
</table>
<div class="panel" id="info_panel_div" style="width:780px;">
<iframe
style="border-style:hidden;width:740px;height:200px;"
id="torrent_info">
</iframe>
</div>
<br />
<script language='javascript'>
/*on_click_action = open_details;*/
on_click_action = on_click_row_js;
reselect_rows();
var id = state.selected_rows[0];
if (id) {
open_inner_details(id);
}
</script>
<form id='toolbar_form' method="POST" action="changed by javascript">
</form>
$:render.footer()

View File

@ -0,0 +1,34 @@
$def with (error)
<html>
<head>
<title>Deluge:$_('Login')</title>
<link rel="icon" href="/static/images/deluge_icon.gif" type="image/gif" />
<link rel="shortcut icon" href="/static/images/deluge_icon.gif" type="image/gif" />
<link rel="stylesheet" type="text/css" href="/template_style.css" />
<script language="javascript" src="/static/deluge.js"></script>
</head>
<body>
<div id="page">
<div class="panel">
$if error > 0:
<div class="error">$_("Password is invalid,try again")</div>
<form method="POST" id="loginform" action='/login'>
<input type="hidden" name="redir" value="$get('redir')">
<div id="loginpanel">
<div class="form_row">
<span class="form_label">$_('Password')</span>
<input type="password" name="pwd" id="pwd" class="form_input">
</div>
<div class="form_row">
<span class="form_label"></span>
<input type="submit" name="submit"
id="submit" value="Submit" class="form_input">
</div>
</div>
</form>
</div>
$:render.footer()

View File

@ -0,0 +1,11 @@
{
'authors':['Martijn Voncken <mvoncken@gmail.com>'],
'inherits':['deluge','advanced'],
'comment':"""
A more conventional template.
css written from scratch
templated-css with variables.
Inspried by (but not copied from) gmail.
"""
}

View File

@ -0,0 +1,115 @@
$def with (style)
/*
preprocessed style.
avoid copy and paste of colours.
*/
/*global:*/
body, th, td,tr ,hr, div,table , div{
font-family: Bitstream Vera Sans, verdana, arial, sans-serif;
font-size:12px;
padding:0px;
margin:0px;
border-style: hidden;
border-spacing:0px;
}
a { color: #0000AA;}
a:visited { color: #0000AA;}
th {font-weight:normal}
form {
display:inline;
}
img{
border:0;
}
/*controls:*/
a.tab_button_active {
color: #0000AA;
text-decoration:none;
font-weight:bold;
color:#000;
}
div.deluge_button{
display:inline;
}
/*page from top to bottom:*/
/*top part :*/
#admin_toolbar {
text-align:right;
float;
}
#home_top {
text-align:left;
float;
}
/*toolbar*/
#toolbar {
background-color:#E0ECFF;
}
#torrent_list_block{
border-style:solid;
border-width:12px;
border-color:#C3D9FF;
-moz-border-radius:8px;
/*float: right;*/
}
/*torrent table*/
XX#torrent_table td {
border-bottom-style:solid;
border-bottom-width:1px;
border-bottom-color:#000000;
}
#torrent_table th {
background-color:#C3D9FF;
}
tr.altrow1 {
background-color:#F0F0F0;
}
tr.torrent_table_selected {
background-color:#FFFFCC;
}
div.progress_bar{
background-color:#E0ECFF;
/*color:blue;*/
/*-moz-border-radius:5px;*/ /*ff only setting*/
}
/*info panel:*/
#info_panel_div {
border-style:solid;
border-width:12px;
border-color:#B5EDBC;
-moz-border-radius:8px;
/*float: right;*/
}
#organize_block {
border-style:solid;
border-width:12px;
border-color:#B5EDBC;
-moz-border-radius:8px;
float: left;
}
/*config:*/

View File

@ -0,0 +1,19 @@
$def with (torrent, active_tab)
<!--for iframe in javascript mode.-->
<html>
<head>
<title>Deluge:$torrent.name</title>
<link rel="stylesheet" type="text/css" href="/template_style.css" />
</head>
<body class="inner">
$for id, title, tab in detail_tabs:
&nbsp;
$:render.part_tab_button(id, title, active_tab)
$for id, title, tab in detail_tabs:
$if active_tab == id:
$:render[tab](torrent)
</body>
</html>