Skip to content

Commit c5b111e

Browse files
author
Richard Jones
committed
more documentation, fixed bug in request/description
1 parent 2d580ec commit c5b111e

File tree

2 files changed

+191
-10
lines changed

2 files changed

+191
-10
lines changed

doc/customizing.txt

Lines changed: 141 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Customising Roundup
33
===================
44

5-
:Version: $Revision: 1.28 $
5+
:Version: $Revision: 1.29 $
66

77
.. This document borrows from the ZopeBook section on ZPT. The original is at:
88
http://www.zope.org/Documentation/Books/ZopeBook/current/ZPT.stx
@@ -778,9 +778,8 @@ The following variables are available to templates.
778778
.. taken from roundup.cgi.templating.RoundupPageTemplate docstring
779779

780780
*context*
781-
The current context. This is either None, a wrapper around a
782-
hyperdb class (an HTMLClass) or a wrapper around a hyperdb item (an
783-
HTMLItem).
781+
The current context. This is either None, a
782+
`hyperdb class wrapper`_ or a `hyperdb item wrapper`_
784783
*request*
785784
Includes information about the current request, including:
786785
- the url
@@ -818,15 +817,20 @@ The following variables are available to templates.
818817

819818
<span>Hello, World!</span>
820819

820+
*utils*
821+
This variable makes available some utility functions like batching.
822+
821823
The context variable
822824
~~~~~~~~~~~~~~~~~~~~
823825

824826
The *context* variable is one of three things based on the current context
825827
(see `determining web context`_ for how we figure this out):
826828

827829
1. if we're looking at a "home" page, then it's None
828-
2. if we're looking at a specific hyperdb class, it's an HTMLClass instance
829-
3. if we're looking at a specific hyperdb item, it's an HTMLItem instance
830+
2. if we're looking at a specific hyperdb class, it's a
831+
`hyperdb class wrapper`_.
832+
3. if we're looking at a specific hyperdb item, it's a
833+
`hyperdb item wrapper`_.
830834

831835
If the context is not None, we can access the properties of the class or item.
832836
The only real difference between cases 2 and 3 above are:
@@ -838,10 +842,128 @@ The only real difference between cases 2 and 3 above are:
838842
a real, or true value in the third. Thus we can determine whether we're
839843
looking at a real item from the hyperdb by testing "context/id".
840844

845+
Hyperdb class wrapper
846+
:::::::::::::::::::::
847+
848+
Note: this is implemented by the roundup.cgi.templating.HTMLClass class.
849+
850+
This wrapper object provides access to a hyperb class. It is used primarily
851+
in both index view and new item views, but it's also usable anywhere else that
852+
you wish to access information about a class, or the items of a class, when
853+
you don't have a specific item of that class in mind.
854+
855+
We allow access to properties. There will be no "id" property. The value
856+
accessed through the property will be the current value of the same name from
857+
the CGI form.
858+
859+
There are several methods available on these wrapper objects:
860+
861+
=========== =============================================================
862+
Method Description
863+
=========== =============================================================
864+
properties return a `hyperdb property wrapper`_ for all of this class'
865+
properties.
866+
list lists all of the active (not retired) items in the class.
867+
csv return the items of this class as a chunk of CSV text.
868+
propnames lists the names of the properties of this class.
869+
filter lists of items from this class, filtered and sorted
870+
by the current *request* filterspec/filter/sort/group args
871+
classhelp display a link to a javascript popup containing this class'
872+
"help" template.
873+
submit generate a submit button (and action hidden element)
874+
renderWith render this class with the given template.
875+
history returns 'New node - no history' :)
876+
=========== =============================================================
877+
878+
Note that if you have a property of the same name as one of the above methods,
879+
you'll need to access it using a python "item access" expression. For example::
880+
881+
python:context['list']
882+
883+
will access the "list" property, rather than the list method.
884+
885+
886+
Hyperdb item wrapper
887+
::::::::::::::::::::
888+
889+
Note: this is implemented by the roundup.cgi.templating.HTMLItem class.
890+
891+
This wrapper object provides access to a hyperb item.
892+
893+
We allow access to properties. There will be no "id" property. The value
894+
accessed through the property will be the current value of the same name from
895+
the CGI form.
896+
897+
There are several methods available on these wrapper objects:
898+
899+
=============== =============================================================
900+
Method Description
901+
=============== =============================================================
902+
submit generate a submit button (and action hidden element)
903+
journal return the journal of the current item (**not implemented**)
904+
history render the journal of the current item as HTML
905+
renderQueryForm specific to the "query" class - render the search form for
906+
the query
907+
hasPermission specific to the "user" class - determine whether the user
908+
has a Permission
909+
=============== =============================================================
910+
911+
912+
Note that if you have a property of the same name as one of the above methods,
913+
you'll need to access it using a python "item access" expression. For example::
914+
915+
python:context['journal']
916+
917+
will access the "journal" property, rather than the journal method.
918+
919+
920+
Hyperdb property wrapper
921+
::::::::::::::::::::::::
922+
923+
Note: this is implemented by subclasses roundup.cgi.templating.HTMLProperty
924+
class (HTMLStringProperty, HTMLNumberProperty, and so on).
925+
926+
This wrapper object provides access to a single property of a class. Its
927+
value may be either:
928+
929+
1. if accessed through a `hyperdb item wrapper`_, then it's a value from the
930+
hyperdb
931+
2. if access through a `hyperdb class wrapper`_, then it's a value from the
932+
CGI form
933+
934+
935+
The property wrapper has some useful attributes:
936+
937+
=============== =============================================================
938+
Attribute Description
939+
=============== =============================================================
940+
_name the name of the property
941+
_value the value of the property if any
942+
=============== =============================================================
943+
944+
There are several methods available on these wrapper objects:
945+
946+
=========== =============================================================
947+
Method Description
948+
=========== =============================================================
949+
plain render a "plain" representation of the property
950+
field render a form edit field for the property
951+
stext specific to String properties - render the value of the
952+
property as StructuredText (requires the StructureText module
953+
to be installed separately)
954+
multiline specific to String properties - render a multiline form edit
955+
field for the property
956+
email specific to String properties - render the value of the
957+
property as an obscured email address
958+
=========== =============================================================
959+
960+
XXX do the other properties
841961

842962
The request variable
843963
~~~~~~~~~~~~~~~~~~~~
844964

965+
Note: this is implemented by the roundup.cgi.templating.HTMLRequest class.
966+
845967
The request variable is packed with information about the current request.
846968

847969
.. taken from roundup.cgi.templating.HTMLRequest docstring
@@ -874,6 +996,19 @@ filterspec values to filter the index on
874996
search_text text to perform a full-text search on for an index
875997
=========== ================================================================
876998

999+
The db variable
1000+
~~~~~~~~~~~~~~~
1001+
1002+
Note: this is implemented by the roundup.cgi.templating.HTMLDatabase class.
1003+
1004+
Allows access to all hyperdb classes as attributes of this variable. If you
1005+
want access to the "user" class, for example, you would use::
1006+
1007+
db/user
1008+
python:db.user
1009+
1010+
The access results in a `hyperdb class wrapper`_.
1011+
8771012

8781013
Displaying Properties
8791014
---------------------

roundup/cgi/templating.py

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def __getattr__(self, attr):
277277
raise AttributeError, attr
278278

279279
def properties(self):
280-
''' Return HTMLProperty for all props
280+
''' Return HTMLProperty for all of this class' properties.
281281
'''
282282
l = []
283283
for name, prop in self._props.items():
@@ -291,6 +291,8 @@ def properties(self):
291291
return l
292292

293293
def list(self):
294+
''' List all items in this class.
295+
'''
294296
if self.classname == 'user':
295297
klass = HTMLUser
296298
else:
@@ -635,7 +637,7 @@ def hasPermission(self, role, classname=_marker):
635637
class HTMLProperty:
636638
''' String, Number, Date, Interval HTMLProperty
637639
638-
Hase useful attributes:
640+
Has useful attributes:
639641
640642
_name the name of the property
641643
_value the value of the property if any
@@ -660,19 +662,27 @@ def __cmp__(self, other):
660662

661663
class StringHTMLProperty(HTMLProperty):
662664
def plain(self, escape=0):
665+
''' Render a "plain" representation of the property
666+
'''
663667
if self._value is None:
664668
return ''
665669
if escape:
666670
return cgi.escape(str(self._value))
667671
return str(self._value)
668672

669673
def stext(self, escape=0):
674+
''' Render the value of the property as StructuredText.
675+
676+
This requires the StructureText module to be installed separately.
677+
'''
670678
s = self.plain(escape=escape)
671679
if not StructuredText:
672680
return s
673681
return StructuredText(s,level=1,header=0)
674682

675683
def field(self, size = 30):
684+
''' Render a form edit field for the property
685+
'''
676686
if self._value is None:
677687
value = ''
678688
else:
@@ -681,6 +691,8 @@ def field(self, size = 30):
681691
return '<input name="%s" value="%s" size="%s">'%(self._name, value, size)
682692

683693
def multiline(self, escape=0, rows=5, cols=40):
694+
''' Render a multiline form edit field for the property
695+
'''
684696
if self._value is None:
685697
value = ''
686698
else:
@@ -690,7 +702,8 @@ def multiline(self, escape=0, rows=5, cols=40):
690702
self._name, rows, cols, value)
691703

692704
def email(self, escape=1):
693-
''' fudge email '''
705+
''' Render the value of the property as an obscured email address
706+
'''
694707
if self._value is None: value = ''
695708
else: value = str(self._value)
696709
value = value.replace('@', ' at ')
@@ -701,18 +714,26 @@ def email(self, escape=1):
701714

702715
class PasswordHTMLProperty(HTMLProperty):
703716
def plain(self):
717+
''' Render a "plain" representation of the property
718+
'''
704719
if self._value is None:
705720
return ''
706721
return _('*encrypted*')
707722

708723
def field(self, size = 30):
724+
''' Render a form edit field for the property
725+
'''
709726
return '<input type="password" name="%s" size="%s">'%(self._name, size)
710727

711728
class NumberHTMLProperty(HTMLProperty):
712729
def plain(self):
730+
''' Render a "plain" representation of the property
731+
'''
713732
return str(self._value)
714733

715734
def field(self, size = 30):
735+
''' Render a form edit field for the property
736+
'''
716737
if self._value is None:
717738
value = ''
718739
else:
@@ -722,11 +743,15 @@ def field(self, size = 30):
722743

723744
class BooleanHTMLProperty(HTMLProperty):
724745
def plain(self):
746+
''' Render a "plain" representation of the property
747+
'''
725748
if self.value is None:
726749
return ''
727750
return self._value and "Yes" or "No"
728751

729752
def field(self):
753+
''' Render a form edit field for the property
754+
'''
730755
checked = self._value and "checked" or ""
731756
s = '<input type="radio" name="%s" value="yes" %s>Yes'%(self._name,
732757
checked)
@@ -740,11 +765,15 @@ def field(self):
740765

741766
class DateHTMLProperty(HTMLProperty):
742767
def plain(self):
768+
''' Render a "plain" representation of the property
769+
'''
743770
if self._value is None:
744771
return ''
745772
return str(self._value)
746773

747774
def field(self, size = 30):
775+
''' Render a form edit field for the property
776+
'''
748777
if self._value is None:
749778
value = ''
750779
else:
@@ -764,6 +793,8 @@ def reldate(self, pretty=1):
764793

765794
class IntervalHTMLProperty(HTMLProperty):
766795
def plain(self):
796+
''' Render a "plain" representation of the property
797+
'''
767798
if self._value is None:
768799
return ''
769800
return str(self._value)
@@ -772,6 +803,8 @@ def pretty(self):
772803
return self._value.pretty()
773804

774805
def field(self, size = 30):
806+
''' Render a form edit field for the property
807+
'''
775808
if self._value is None:
776809
value = ''
777810
else:
@@ -802,6 +835,8 @@ def __getattr__(self, attr):
802835
return getattr(i, attr)
803836

804837
def plain(self, escape=0):
838+
''' Render a "plain" representation of the property
839+
'''
805840
if self._value is None:
806841
return ''
807842
linkcl = self._db.classes[self._prop.classname]
@@ -812,6 +847,8 @@ def plain(self, escape=0):
812847
return value
813848

814849
def field(self):
850+
''' Render a form edit field for the property
851+
'''
815852
linkcl = self._db.getclass(self._prop.classname)
816853
if linkcl.getprops().has_key('order'):
817854
sort_on = 'order'
@@ -928,6 +965,8 @@ def reverse(self):
928965
return [klass(self._client, self._prop.classname, value) for value in l]
929966

930967
def plain(self, escape=0):
968+
''' Render a "plain" representation of the property
969+
'''
931970
linkcl = self._db.classes[self._prop.classname]
932971
k = linkcl.labelprop(1)
933972
labels = []
@@ -939,6 +978,8 @@ def plain(self, escape=0):
939978
return value
940979

941980
def field(self, size=30, showid=0):
981+
''' Render a form edit field for the property
982+
'''
942983
sortfunc = make_sort_function(self._db, self._prop.classname)
943984
linkcl = self._db.getclass(self._prop.classname)
944985
value = self._value[:]
@@ -1168,7 +1209,12 @@ def description(self):
11681209
if self.client.nodeid:
11691210
s.append('- %s%s'%(self.classname, self.client.nodeid))
11701211
else:
1171-
s.append('- index of '+self.classname)
1212+
if self.template == 'item':
1213+
s.append('- new %s'%self.classname)
1214+
elif self.template == 'index':
1215+
s.append('- %s index'%self.classname)
1216+
else:
1217+
s.append('- %s %s'%(self.classname, self.template))
11721218
else:
11731219
s.append('- home')
11741220
return ' '.join(s)

0 commit comments

Comments
 (0)