本文整理汇总了Python中etgen.html.E.pre方法的典型用法代码示例。如果您正苦于以下问题:Python E.pre方法的具体用法?Python E.pre怎么用?Python E.pre使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类etgen.html.E
的用法示例。
在下文中一共展示了E.pre方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_change_desc_html
# 需要导入模块: from etgen.html import E [as 别名]
# 或者: from etgen.html.E import pre [as 别名]
def get_change_desc_html(self, f, old, new):
from lino.core.choicelists import ChoiceListField
if isinstance(f, models.TextField):
old = old or ''
new = new or ''
if False:
diff = difflib.unified_diff(
old.splitlines(), new.splitlines(),
fromfile="before", tofile="after", lineterm='')
txt = E.pre('\n'.join(diff))
else:
labels = {
'+': _("lines added"),
'-': _("lines removed"),
'?': _("modifications"),
' ': _("lines changed")}
diff = list(difflib.ndiff(
old.splitlines(), new.splitlines()))
counters = {}
for ln in diff:
if ln:
k = ln[0]
c = counters.get(k, 0)
counters[k] = c + 1
txt = ', '.join([
"{0} {1}".format(n, labels[op])
for op, n in counters.items()])
return E.li(
E.b(str(f.verbose_name)), " : ", txt)
if isinstance(f, models.DateTimeField):
return
if isinstance(f, models.ForeignKey):
if old:
old = f.remote_field.model.objects.get(pk=old)
if new:
new = f.remote_field.model.objects.get(pk=new)
elif isinstance(f, ChoiceListField):
if isinstance(old, six.string_types):
old = f.choicelist.get_by_value(old)
if isinstance(new, six.string_types):
new = f.choicelist.get_by_value(new)
else:
old = obj2unicode(old)
new = obj2unicode(new)
return E.li(
E.b(str(f.verbose_name)), " : ",
u"{0} --> {1}".format(old, new))