3535except ImportError :
3636 import StringIO
3737try :
38- import StructuredText
38+ from StructuredText . StructuredText import HTML as StructuredText
3939except ImportError :
40- StructuredText = None
40+ try : # older version
41+ import StructuredText
42+ except ImportError :
43+ StructuredText = None
4144
4245# bring in the templating support
4346from roundup .cgi .PageTemplates import PageTemplate , GlobalTranslationService
@@ -648,7 +651,7 @@ def classhelp(self, properties=None, label=''"(list)", width='500',
648651
649652 If the "property" arg is given, it's passed through to the
650653 javascript help_window function.
651-
654+
652655 You can use inputtype="radio" to display a radio box instead
653656 of the default checkbox (useful for entering Link-properties)
654657
@@ -1080,6 +1083,29 @@ def download_url(self):
10801083 url = '%s%s/%s' % (self ._classname , self ._nodeid , name )
10811084 return urllib .quote (url )
10821085
1086+ def copy_url (self , exclude = ("messages" , "files" )):
1087+ """Construct a URL for creating a copy of this item
1088+
1089+ "exclude" is an optional list of properties that should
1090+ not be copied to the new object. By default, this list
1091+ includes "messages" and "files" properties. Note that
1092+ "id" property cannot be copied.
1093+
1094+ """
1095+ exclude = ("id" , "activity" , "actor" , "creation" , "creator" ) \
1096+ + tuple (exclude )
1097+ query = {
1098+ "@template" : "item" ,
1099+ "@note" : self ._ ("Copy of %(class)s %(id)s" ) % {
1100+ "class" : self ._ (self ._classname ), "id" : self ._nodeid },
1101+ }
1102+ for name in self ._props .keys ():
1103+ if name not in exclude :
1104+ query [name ] = self [name ].plain ()
1105+ return self ._classname + "?" + "&" .join (
1106+ ["%s=%s" % (key , urllib .quote (value ))
1107+ for key , value in query .items ()])
1108+
10831109class _HTMLUser (_HTMLItem ):
10841110 '''Add ability to check for permissions on users.
10851111 '''
@@ -1217,20 +1243,20 @@ def plain(self, escape=0, hyperlink=0):
12171243 s = self .hyper_re .sub (self ._hyper_repl , s )
12181244 return s
12191245
1220- def stext (self , escape = 0 ):
1246+ def stext (self , escape = 0 , hyperlink = 1 ):
12211247 ''' Render the value of the property as StructuredText.
12221248
12231249 This requires the StructureText module to be installed separately.
12241250 '''
12251251 if not self .is_view_ok ():
12261252 return self ._ ('[hidden]' )
12271253
1228- s = self .plain (escape = escape )
1254+ s = self .plain (escape = escape , hyperlink = hyperlink )
12291255 if not StructuredText :
12301256 return s
12311257 return StructuredText (s ,level = 1 ,header = 0 )
12321258
1233- def field (self , size = 30 ):
1259+ def field (self , ** kwargs ):
12341260 ''' Render the property as a field in HTML.
12351261
12361262 If not editable, just display the value via plain().
@@ -1244,7 +1270,10 @@ def field(self, size = 30):
12441270 value = cgi .escape (str (self ._value ))
12451271
12461272 value = '"' .join (value .split ('"' ))
1247- return self .input (name = self ._formname ,value = value ,size = size )
1273+
1274+ kwargs .setdefault ("size" , 30 )
1275+ kwargs .update ({"name" : self ._formname , "value" : value })
1276+ return self .input (** kwargs )
12481277
12491278 def multiline (self , escape = 0 , rows = 5 , cols = 40 ):
12501279 ''' Render a multiline form edit field for the property.
@@ -1532,12 +1561,12 @@ def pretty(self, format=_marker):
15321561 '''
15331562 if not self .is_view_ok ():
15341563 return self ._ ('[hidden]' )
1535-
1564+
15361565 if self ._offset is None :
15371566 offset = self ._db .getUserTimezone ()
15381567 else :
15391568 offset = self ._offset
1540-
1569+
15411570 if not self ._value :
15421571 return ''
15431572 elif format is not self ._marker :
0 commit comments