Author: duncan
Date: Sun Dec 31 18:55:07 2006
New Revision: 8885
Modified:
branches/rel-1/freevo/src/www/web_types.py
Log:
[ 1625393 ] Added comments to web_types.py
Patch by Tanja applied
Modified: branches/rel-1/freevo/src/www/web_types.py
==============================================================================
--- branches/rel-1/freevo/src/www/web_types.py (original)
+++ branches/rel-1/freevo/src/www/web_types.py Sun Dec 31 18:55:07 2006
@@ -60,24 +60,51 @@
class FreevoResource(Resource):
+ """ Base class of webpages which handels the authentication.
+
+ All webpages should be subclasses of this class.
+ The subclasses must not have a render methode
+ but they need a _render methode instead.
+ When a webpage is opened by the user then first the render methode
+ of this base class is called and then if the authentication was successfull
+ the _render methode of the subclass is called.
+ Otherwise a error messages is returned and shown to the user.
+ """
def render(self, request):
- print 'render(self, request=\"%s\")' % (request)
+ """ render methode of this class.
+
+ This methode will be called when a user requests this page.
+ It only handels the authentication but does not present any
+ content.If authentication is successfull this methode returns the
+ _render methode, which does the actuall work.
+ """
+ # get username and password from the user
username = request.getUser()
password = request.getPassword()
if not self.auth_user(username, password):
+ # authentication fails, thus we send 401 error
request.setResponseCode(401, 'Authentication needed')
- # request.setHeader('Connection', 'close')
+ # still we have to create a few things for the header
request.setHeader('WWW-Authenticate', 'Basic realm="unknown"')
request.setHeader('Content-Length', str(len('401: = Authorization
needed.')))
request.setHeader('Content-Type', 'text/html')
+ # this is for the body of the html document
return '<h1>401 Authentication required</h1>'
else:
+ # authentication was successfull
+ # thus we return the self._render methode
+ # which hopefully will do something usefull
return self._render(request)
def auth_user(self, username, password):
+ """ check of username and password
+
+ This methode validates username and password.
+ If authentication is successfull it returns True otherwise False.
+ """
print 'auth_user(self, username=\"%s\", password=\"%s\")' % (username,
'******')
realpass = config.WWW_USERS.get(username)
if not realpass:
@@ -86,49 +113,88 @@
md5pass = md5.new(password + username)
password = base64.b32encode(md5pass.digest())
if realpass == password:
- return TRUE
+ return True
else:
- return FALSE
+ return False
class HTMLResource:
-
+ """ HTML elements of a freevo webpage
+
+ This class provides many usefull elements which can be used
+ in a webpage. It provides a string called res which should be used to
+ build up the html string that should form the content of a webpage.
+ Usage: Create a instance of this class in the _render methode of the
+ subclass which represents the webpage, use all this methodes to build
+ the html string and return HTMLResource.res in the end.
+ """
def __init__(self):
- print '__init__(self)'
- self.res = ''
+ # create empty result string which must be filled with life
+ self.res =''
def printContentType(self, content_type='text/html'):
+ """ Content"""
+ # debug print
print 'printContentType(self, content_type=\"%s\")' % (content_type)
+ # adding new text
self.res += 'Content-type: %s\n\n' % content_type
def printHeader(self, title='unknown page', style=None, script=None,
selected='Help', prefix=0):
+ """ Header
+
+ This produces the header of a freevo page with the navigation bar.
+ Parameter:
+ title = title of the webpage
+ style = style sheet to use for this page
+ script = java script to use for this page
+ selected = which tab in the tabline should be highlighed
+ prefix = how many directory levels is this file below the main
level
+ this is needed for the links in the navigation bar.
+ """
+
+ # debug print
print 'printHeader(self, title=\"%s\", style=\"%s\", script=\"%s\",
selected=\"%s\", prefix=\"%s\")' % \
(title, style, script, selected, prefix)
+ # we are prefix level below the main directory thus we must go prefix
times up,
+ # before we are in the same directory than those pages that are in the
navigation bar.
+ # This is needed for creating the links in the navigation bar.
strprefix = '../' * prefix
+ # now we can start to create the header:
+
+ # doc type
self.res += '<?xml version="1.0" encoding="'+ config.encoding +'"?>\n'
self.res += '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" '
self.res +=
'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n'
- #self.res += '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Strict//EN"\n'
- #self.res += '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
+
+ # <html> and <head> tag
self.res += '<html>\n\t<head>\n'
+ # <title>
self.res += '\t<title>Freevo | '+title+'</title>\n'
+ # meta tags, encoding is taken from the users config
self.res += '\t<meta http-equiv="Content-Type" content= "text/html;
charset='+ config.encoding +'"/>\n'
+ # css style sheet
if style != None:
self.res += '\t<link rel="stylesheet" href="styles/main.css"
type="text/css" />\n'
+ # java script
if script != None:
self.res += '\t<script language="JavaScript"
type="text/JavaScript" src="'+script+'"></script>\n'
+ # end of <head>
self.res += '</head>\n'
+ # here starts the body
self.res += '\n\n\n\n<body>\n'
- # Header
+ # header of the page with tab bar
self.res += '<!-- Header Logo and Status Line -->\n'
+ # headline
self.res += '<div id="titlebar"><span class="name">'\
+'<a href="http://freevo.sourceforge.net/"
target="_blank">Freevo</a></span></div>\n'
-
+ # start the bar, it is build as a list
+ self.res += '<div id="header">\n<ul>'
+ # this items should be shown in the tab bar
items = [(_('Home'),_('Home'),'%sindex.rpy' % str(strprefix)),
(_('TV Guide'),_('View TV Listings'),'%sguide.rpy' %
str(strprefix)),
(_('Scheduled Recordings'),_('View Scheduled
Recordings'),'%srecord.rpy' % str(strprefix)),
@@ -137,76 +203,117 @@
(_('Manual Recording'),_('Schedule a Manual
Recording'),'%smanualrecord.rpy' % str(strprefix)),
(_('Search'),_('Advanced Search Page'),'%ssearch.rpy' %
str(strprefix)),
(_('Help'),_('View Online Help and Documentation'),'%shelp/'
% str(strprefix))]
-
+ # maybe also the ICECAST_WWW_PAGE
try:
if config.ICECAST_WWW_PAGE:
items.append((_('Icecast List'),_('Change Icecast
List'),'%siceslistchanger.rpy' % (strprefix)))
except AttributeError:
pass
-
- self.res += '<div id="header">\n<ul>'
-
+ # go through the items and create the bar
for i in items:
if selected == i[0]:
+ # this item is selected, thus we highlight the tab
self.res += '<li id="current">'
else:
self.res += '<li>'
self.res += "<a href=\"%s\" title=\"%s\">%s</a></li>\n" % (i[2],
i[1],i[0])
+ # end of the bar list
self.res += '</ul>\n</div>'
+ # now we are ready for the main content
self.res += '\n<!-- Main Content -->\n';
def tableOpen(self, opts=''):
+ """ Opens a table
+
+ opts are additional parameters for the <table> tag.
+ """
print 'tableOpen(self, opts=\"%s\")' % (opts)
self.res += "<table "+opts+">\n"
def tableClose(self):
+ """
+ Close a table
+ """
print 'tableClose(self)'
self.res += "</table>\n"
def tableHeadOpen(self, opts=''):
+ """ Open a table header line
+
+ opts are additional parameters for the <thead> tag.
+ """
print 'tableHeadOpen(self, opts=\"%s\")' % (opts)
self.res += " <thead "+opts+">\n"
def tableHeadClose(self, opts=''):
+ """
+ Closes a table header line
+ """
print 'tableHeadClose(self, opts=\"%s\")' % (opts)
self.res += " </thead>\n"
def tableBodyOpen(self, opts=''):
+ """ Opens a table body
+
+ opts are additional parameter for the <tbody> tag
+ """
print 'tableBodyOpen(self, opts=\"%s\")' % (opts)
self.res += " <tbody "+opts+">\n"
def tableBodyClose(self, opts=''):
+ """
+ Closes a table body
+ """
print 'tableBodyClose(self, opts=\"%s\")' % (opts)
self.res += " </tbody>\n"
def tableFootOpen(self, opts=''):
+ """ Opens a table footer
+
+ opts are additional parameters for the <tfoot> tag.
+ """
print 'tableFootOpen(self, opts=\"%s\")' % (opts)
self.res += " <tfoot "+opts+">\n"
def tableFootClose(self, opts=''):
+ """
+ Closes a table footer.
+ """
print 'tableFootClose(self, opts=\"%s\")' % (opts)
self.res += " </tfoot>\n"
def tableRowOpen(self, opts=''):
+ """ Opens a table row
+
+ opts are additonal parameters for the <tr> tag
+ """
print 'tableRowOpen(self, opts=\"%s\")' % (opts)
self.res += " <tr "+opts+">\n"
def tableRowClose(self):
+ """
+ Closes a table row
+ """
print 'tableRowClose(self)'
self.res += " </tr>\n"
def tableCell(self, data='', opts=''):
+ """ Creates a table cell
+
+ opts are additonal parameters for the <td>.
+ data is the content of this table cell.
+ """
print 'tableCell(self, data=\"%s\", opts=\"%s\")' % (data, opts)
self.res += " <td "+opts+">"+data+"</td>\n"
@@ -215,7 +322,6 @@
print 'formValue(self, form=\"%s\", key=\"%s\")' % (form, key)
if not form or not key:
return None
-
try:
val = form[key][0]
except:
@@ -225,11 +331,16 @@
def printFooter(self):
+ """
+ Closes the html document
+ """
print 'printFooter(self)'
self.res += '</body>\n</html>\n'
def printSearchForm(self):
+ """ Creates the simple search form"""
+
print 'printSearchForm(self)'
self.res += """
<form id="SearchForm" action="search.rpy" method="get">
@@ -238,6 +349,11 @@
"""
def printAdvancedSearchForm(self):
+ """ Creates the advanced search form.
+
+ This search form has an additonal checkbox and a go button
+ """
+
print 'printAdvancedSearchForm(self)'
self.res += """
<form id="SearchForm" action="search.rpy" method="get">
@@ -249,6 +365,9 @@
"""
def printMessages(self, messages):
+ """
+ Prints a message
+ """
print 'printMessages(self, messages=\"%s\")' % (messages)
self.res += "<h4>"+_("Messages")+":</h4>\n"
self.res += "<ul>\n"
@@ -267,6 +386,10 @@
self.printFooter()
def printLinks(self, prefix=0):
+ """
+ Print Link
+ """
+ # seems to do nothing at the moment ????
print 'printLinks(self, prefix=\"%s\")' % (prefix)
#
#try:
@@ -277,6 +400,9 @@
return
def printBreadcrumb(self, media, mediadirs, dir):
+ """
+ ???
+ """
print 'printBreadcrumb(self, media=\"%s\", mediadirs=\"%s\", dir=%r)'
% (media, mediadirs, dir)
breadcrumb='<a href="library.rpy">Home: </a><a
href="library.rpy?media='+media+'&dir=">'+media+'</a>'
_url = ""
@@ -290,6 +416,9 @@
return breadcrumb
def printPassword(self, password):
+ """
+ ???
+ """
print 'printPassword(self, password=\"%s\")' % (password)
self.res += """<script language="JavaScript"> <!--
@@ -307,6 +436,9 @@
</script>"""
def printImagePopup(self):
+ """
+ Opens a Popup to display an image
+ """
print 'printImagePopup(self)'
self.res += """<script language="JavaScript" type="text/javascript"
style="display:none;">
function openfoto(loc,width,height){
@@ -316,6 +448,12 @@
</script> """
def printWebRemote(self):
+ """ Prints web remote
+
+ If configured to do so,
+ then this displays a remote to control freevo
+ via the web browser
+ """
if not (config.ENABLE_NETWORK_REMOTE == 1 and
config.REMOTE_CONTROL_PORT):
self.res += "no remote enabled"
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog