|
|
@@ -13,20 +13,90 @@
|
|
|
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
## See the License for the specific language governing permissions and
|
|
|
## limitations under the License.
|
|
|
-<%def name="render_field(field, hidden=False, notitle=False)">
|
|
|
+<%!
|
|
|
+ from desktop.lib.django_util import extract_field_data
|
|
|
+%>
|
|
|
+
|
|
|
+<%def name="render_field(
|
|
|
+ field,
|
|
|
+ render_default=False,
|
|
|
+ data_filters=None,
|
|
|
+ hidden=False,
|
|
|
+ notitle=False,
|
|
|
+ tag='input',
|
|
|
+ klass=None,
|
|
|
+ attrs=None,
|
|
|
+ value=None,
|
|
|
+ help=False,
|
|
|
+ help_attrs=None,
|
|
|
+ dd_attrs=None,
|
|
|
+ dt_attrs=None,
|
|
|
+ title_klass=None,
|
|
|
+ button_text=False
|
|
|
+ )">
|
|
|
<%
|
|
|
- cls = ""
|
|
|
+ if value is None:
|
|
|
+ value = extract_field_data(field)
|
|
|
+
|
|
|
+ def make_attr_str(attributes):
|
|
|
+ if attributes is None:
|
|
|
+ attributes = {}
|
|
|
+ ret_str = ""
|
|
|
+ for key, value in attributes.iteritems():
|
|
|
+ if key == "klass":
|
|
|
+ key = "class"
|
|
|
+ ret_str += "%s='%s'" % (key.replace("_", "-"), unicode(value))
|
|
|
+ return ret_str
|
|
|
+
|
|
|
+ if not attrs:
|
|
|
+ attrs = {}
|
|
|
+ if not render_default:
|
|
|
+ attrs.setdefault('type', 'text')
|
|
|
+
|
|
|
+ if data_filters:
|
|
|
+ attrs.data_filters = data_filters
|
|
|
+
|
|
|
+ classes = []
|
|
|
+ if klass:
|
|
|
+ classes.append(klass)
|
|
|
if hidden:
|
|
|
- cls = "ccs-hidden"
|
|
|
- titlecls = ""
|
|
|
+ classes.append("ccs-hidden")
|
|
|
+ cls = ' '.join(classes)
|
|
|
+
|
|
|
+ title_classes = []
|
|
|
+ if title_klass:
|
|
|
+ title_classes.append(title_klass)
|
|
|
if notitle or hidden:
|
|
|
- titlecls = "ccs-hidden"
|
|
|
+ title_classes.append("ccs-hidden")
|
|
|
+ titlecls = ' '.join(title_classes)
|
|
|
%>
|
|
|
- <dt class="${titlecls}">${field.label_tag() | n}</dt>
|
|
|
- <dd class="${cls}">${unicode(field) | n}</dd>
|
|
|
- % if len(field.errors):
|
|
|
- <dd class="beeswax_error">
|
|
|
- ${unicode(field.errors) | n}
|
|
|
- </dd>
|
|
|
+ % if field.is_hidden:
|
|
|
+ ${unicode(field) | n}
|
|
|
+ % else:
|
|
|
+ <dt class="${titlecls}" ${make_attr_str(dt_attrs) | n}>${field.label_tag() | n}</dt>
|
|
|
+ <dd class="${cls}" ${make_attr_str(dd_attrs) | n}>
|
|
|
+ % if render_default:
|
|
|
+ ${unicode(field) | n}
|
|
|
+ % else:
|
|
|
+ % if tag == 'textarea':
|
|
|
+ <textarea name="${field.html_name | n}" ${make_attr_str(attrs) | n} />${extract_field_data(field) or ''}</textarea>
|
|
|
+ % elif tag == 'button':
|
|
|
+ <button name="${field.html_name | n}" ${make_attr_str(attrs) | n} value="${value}"/>${button_text or field.name or ''}</button>
|
|
|
+ % elif tag == 'checkbox':
|
|
|
+ <input type="checkbox" name="${field.html_name | n}" ${make_attr_str(attrs) | n} ${value and "CHECKED" or ""}/>${button_text or field.name or ''}</input>
|
|
|
+ % else:
|
|
|
+ <${tag} name="${field.html_name | n}" value="${extract_field_data(field) or ''}" ${make_attr_str(attrs) | n} />
|
|
|
+ % endif
|
|
|
+ % endif
|
|
|
+ % if help:
|
|
|
+ <p class="ccs-inline" data-filters="HelpTip" ${make_attr_str(help_attrs) | n}>${help}</p>
|
|
|
+ % endif
|
|
|
+ </dd>
|
|
|
+ % if len(field.errors):
|
|
|
+ <dd class="beeswax_error ccs-error">
|
|
|
+ ${unicode(field.errors) | n}
|
|
|
+ </dd>
|
|
|
+ % endif
|
|
|
% endif
|
|
|
</%def>
|
|
|
+
|