Permalink
Browse files

integrate template better, move in form

  • Loading branch information...
1 parent 55adf3a commit cbb981ef540bf371cf9231d686e74372589890c3 aaronsw committed May 23, 2006
Showing with 28 additions and 26 deletions.
  1. +2 −1 trunk/web/__init__.py
  2. +22 −21 { → trunk/web}/form.py
  3. +4 −4 trunk/web/template.py
View
3 trunk/web/__init__.py
@@ -11,7 +11,8 @@
# todo:
# - some sort of accounts system
-import utils, db, net, wsgi, http, webapi, request, httpserver, template
+import utils, db, net, wsgi, http, webapi, request, httpserver
+import template, form
from utils import *
from db import *
View
43 form.py → trunk/web/form.py
@@ -1,10 +1,11 @@
-"""form.py: A simple Python form library."""
-__version__ = '0.22'
-__license__ = "Public domain"
-__author__ = ['Aaron Swartz <me@aaronsw.com>', 'Steve Huffman <http://spez.name/>']
+"""
+HTML forms
+(part of web.py)
+"""
import copy, re
-import web
+import webapi as web
+import utils, net
def attrget(obj, attr, value=None):
if hasattr(obj, 'has_key') and obj.has_key(attr): return obj[attr]
@@ -59,7 +60,7 @@ def __getitem__(self, i):
raise KeyError, i
def _get_d(self): #@@ should really be form.attr, no?
- return web.storage([(i.name, i.value) for i in self.inputs])
+ return utils.storage([(i.name, i.value) for i in self.inputs])
d = property(_get_d)
class Input(object):
@@ -86,33 +87,33 @@ def render(self): raise NotImplementedError
def addatts(self):
str = ""
for (n, v) in self.attrs.items():
- str += ' %s="%s"' % (n, web.websafe(v))
+ str += ' %s="%s"' % (n, net.websafe(v))
return str
#@@ quoting
class Textbox(Input):
def render(self):
- x = '<input type="text" name="%s"' % web.websafe(self.name)
- if self.value: x += ' value="%s"' % web.websafe(self.value)
+ x = '<input type="text" name="%s"' % net.websafe(self.name)
+ if self.value: x += ' value="%s"' % net.websafe(self.value)
x += self.addatts()
x += ' />'
return x
class Password(Input):
def render(self):
- x = '<input type="password" name="%s"' % web.websafe(self.name)
- if self.value: x += ' value="%s"' % web.websafe(self.value)
+ x = '<input type="password" name="%s"' % net.websafe(self.name)
+ if self.value: x += ' value="%s"' % net.websafe(self.value)
x += self.addatts()
x += ' />'
return x
class Textarea(Input):
def render(self):
- x = '<textarea name="%s"' % web.websafe(self.name)
+ x = '<textarea name="%s"' % net.websafe(self.name)
x += self.addatts()
x += '>'
- if self.value is not None: x += web.websafe(self.value)
+ if self.value is not None: x += net.websafe(self.value)
x += '</textarea>'
return x
@@ -122,11 +123,11 @@ def __init__(self, name, args, *validators, **attrs):
super(Dropdown, self).__init__(name, *validators, **attrs)
def render(self):
- x = '<select name="%s"%s>\n' % (web.websafe(self.name), self.addatts())
+ x = '<select name="%s"%s>\n' % (net.websafe(self.name), self.addatts())
for arg in self.args:
if self.value == arg: select_p = ' selected="selected"'
else: select_p = ''
- x += " <option"+select_p+">%s</option>\n" % web.websafe(arg)
+ x += " <option"+select_p+">%s</option>\n" % net.websafe(arg)
x += '</select>\n'
return x
@@ -140,33 +141,33 @@ def render(self):
for arg in self.args:
if self.value == arg: select_p = ' checked="checked"'
else: select_p = ''
- x += '<input type="radio" name="%s" value="%s"%s%s /> %s ' % (web.websafe(self.name), web.websafe(arg), select_p, self.addatts(), web.websafe(arg))
+ x += '<input type="radio" name="%s" value="%s"%s%s /> %s ' % (net.websafe(self.name), net.websafe(arg), select_p, self.addatts(), net.websafe(arg))
return x+'</span>'
class Checkbox(Input):
def render(self):
- x = '<input name="%s" type="checkbox"' % web.websafe(self.name)
+ x = '<input name="%s" type="checkbox"' % net.websafe(self.name)
if self.value: x += ' checked="checked"'
x += self.addatts()
x += ' />'
return x
class Button(Input):
def render(self):
- safename = web.websafe(self.name)
+ safename = net.websafe(self.name)
x = '<button name="%s"%s>%s</button>' % (safename, self.addatts(), safename)
return x
class Hidden(Input):
def render(self):
- x = '<input type="hidden" name="%s' % web.websafe(self.name)
- if self.value: x += ' value="%s"' % web.websafe(self.value)
+ x = '<input type="hidden" name="%s' % net.websafe(self.name)
+ if self.value: x += ' value="%s"' % net.websafe(self.value)
x += ' />'
return x
class Validator:
def __deepcopy__(self, memo): return copy.copy(self)
- def __init__(self, msg, test, jstest=None): web.autoassign(self, locals())
+ def __init__(self, msg, test, jstest=None): utils.autoassign(self, locals())
def valid(self, value):
try: return self.test(value)
except: return False
View
8 trunk/web/template.py
@@ -1,7 +1,7 @@
-"""template.py: simple, elegant templating"""
-__author__ = "Aaron Swartz <me@aaronsw.com>"
-__license__ = "Public domain"
-__version__ = 0.2
+"""
+simple, elegant templating
+(part of web.py)
+"""
import re, glob
from types import FunctionType as function

0 comments on commit cbb981e

Please sign in to comment.