本文整理汇总了Python中nive.i18n._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: UpdateSort
def UpdateSort(self, objs, user):
""" update pool_sort values according to list """
if not objs:
return False, _(u"List is empty")
if isinstance(objs, basestring):
objs = ConvertToNumberList(objs)
ids = []
for oi in objs:
# check if listed objects are objects or ids
if not IObject.providedBy(oi):
ids.append(int(oi))
if ids:
# load remaining objects by id
objs2 = self.GetObjsBatch(ids)
pos = 10
processed = []
for obj in objs:
if not IObject.providedBy(obj):
for o in objs2:
if o.id == int(obj):
obj = o
break
if not IObject.providedBy(obj):
continue
if obj.id in processed:
continue
processed.append(obj.id)
obj.meta.set("pool_sort", pos)
obj.CommitInternal(user)
pos += 10
return True, _(u"OK")
示例2: Paste
def Paste(self, ids, pos, user):
"""
Paste the copied object with id to this object
"""
root = self.GetRoot()
new = []
msgs = []
result = True
for id in ids:
id = int(id)
if self.GetID() == id:
continue
obj = root.LookupObj(id, preload="skip")
if not obj:
msgs.append(_(u"Object not found"))
result = False
continue
newobj = self.Duplicate(obj, user)
if not newobj:
raise TypeError, "Duplicate failed"
if ISort.providedBy(self):
self.InsertAfter(newobj.id, pos, user=user)
new.append(newobj)
if not self.app.configuration.autocommit:
for o in new:
o.Commit(user)
if result:
msgs.append(_(u"OK. Copied and pasted."))
return result, msgs
示例3: Update
def Update(self, action, **kw):
"""
Process request data and update object.
returns bool, html
"""
redirectSuccess = kw.get("redirectSuccess")
msgs = []
conf=self.context
result,data,errors = self.Validate(self.request)
if result:
# lookup persistent manager for configuration
storage = self.app.Factory(IModuleConf, "persistence")
if storage:
storage(app=self.app, configuration=conf).Save(data)
msgs.append(_(u"OK. Data saved."))
else:
msgs.append(_(u"No persistent storage for configurations activated. Nothing saved."))
result = False
errors=None
if self.view and redirectSuccess:
redirectSuccess = self.view.ResolveUrl(redirectSuccess, obj)
if self.use_ajax:
self.view.Relocate(redirectSuccess, messages=msgs, raiseException=True)
else:
self.view.Redirect(redirectSuccess, messages=msgs, raiseException=True)
return result, self.Render(data, msgs=msgs, errors=errors)
示例4: _Run
def _Run(self, **values):
result = 1
codepage="utf-8"
app = self.app
datapool = app.db
conf = app.dbConfiguration
conn = datapool.connection
system = values.get("excludeSystem")
self.filename = app.configuration.id + ".json"
if not conn:
self.stream.write(_(u"Database connection error (${name})\n", mapping={u"name": app.dbConfiguration.context}))
return 0
if not conn.IsConnected():
self.stream.write(_(u"Database connection error (${name})\n", mapping={u"name": app.dbConfiguration.context}))
return 0
def mapfields(fields):
a=[]
for f in fields:
a.append(f.id)
return a
export = [(MetaTbl,mapfields(app.GetAllMetaFlds(ignoreSystem=False)))]
for t in app.GetAllObjectConfs():
export.append((t.dbparam, ["id"]+mapfields(t.data)))
for t in Structure.items():
export.append((t[0], mapfields(t[1]["fields"])))
data = {}
for table in export:
#tablename
tablename=table[0]
if system and tablename in system:
continue
#fields
fields=table[1]
columns = (",").join(fields)
sql="select %s from %s" % (columns, tablename)
c = conn.cursor()
c.execute(sql)
tvalues = []
for rec in c.fetchall():
recvalue = {}
pos = 0
for col in rec:
recvalue[fields[pos]] = col
pos+=1
tvalues.append(recvalue)
data[tablename] = tvalues
self.stream.write(JsonDataEncoder().encode(data))
return 1
示例5: delfile
def delfile(self):
file = self.GetFormValue(u"fid")
try:
r=self.context.DeleteFile(file, self.User())
if not r:
m=_(u"Delete failed")
else:
m=_(u"OK")
except Exception, e:
m=str(e)
示例6: _Run
def _Run(self, **values):
result = 1
codepage="utf-8"
app = self.app
datapool = app.db
conf = app.dbConfiguration
conn = datapool.connection
system = values.get("excludeSystem")
self.filename = app.configuration.id + ".sql"
if not conn:
self.stream.write(_(u"Database connection error (${name})\n", mapping={u"name": app.dbConfiguration.context}))
return 0
if not conn.IsConnected():
self.stream.write(_(u"Database connection error (${name})\n", mapping={u"name": app.dbConfiguration.context}))
return 0
def mapfields(fields):
a=[]
for f in fields:
a.append(f.id)
return a
export = [(MetaTbl,mapfields(app.GetAllMetaFlds(ignoreSystem=False)))]
for t in app.GetAllObjectConfs():
export.append((t.dbparam, ["id"]+mapfields(t.data)))
for t in Structure.items():
export.append((t[0], mapfields(t[1]["fields"])))
for table in export:
#tablename
tablename=table[0]
if system and tablename in system:
continue
#fields
fields=table[1]
columns = (",").join(fields)
sql="select %s from %s" % (columns, tablename)
c = conn.cursor()
c.execute(sql)
for rec in c.fetchall():
data = []
for col in rec:
data.append(conn.FmtParam(col))
data = (",").join(data)
if not isinstance(data, unicode):
data = unicode(data, codepage)
value = u"INSERT INTO %s (%s) VALUES (%s);\n"%(tablename, columns, data)
value = value.encode(codepage)
self.stream.write(value)
return 1
示例7: Move
def Move(self, ids, pos, user):
"""
Move the object with id to this object
Events
- beforeAdd(data=obj.meta, type=type)
- afterDelete(id=obj.id)
- moved()
- afterAdd(obj=obj)
"""
root = self.root()
oldParent=None
moved = []
msgs = []
result = True
for id in ids:
id = int(id)
if self.GetID() == id:
continue
obj = root.LookupObj(id, preload="skip")
if not obj:
msgs.append(_(u"Object not found"))
result = False
continue
type=obj.GetTypeID()
# allow subobject
if not self.IsTypeAllowed(type, user):
raise TypeError, "Object cannot be added here"
self.Signal("beforeAdd", data=obj.meta, type=type)
if not oldParent or oldParent.id != obj.GetParent().id:
oldParent = obj.GetParent()
obj.__parent__ = self
obj.meta["pool_unitref"] = self.GetID()
oldParent.Signal("afterDelete", id=obj.id)
obj.Signal("moved")
#obj.Close()
moved.append(obj)
for o in moved:
o.Commit(user)
if ISort.providedBy(self):
self.InsertAfter(o.id, pos, user=user)
self.Signal("afterAdd", obj=o)
if result:
msgs.append(_(u"OK. Cut and pasted."))
return result, msgs
示例8: _Run
def _Run(self, **values):
result = 1
importWf = 1
importSecurity = 0
showSystem = values.get("showSystem")
modify = values.get("modify")
request = values["original"]
ignoreTables = self.app.configuration.get("skipUpdateTables", ())
try:
localizer = get_localizer(get_current_request())
except:
localizer = FakeLocalizer()
# localizer.translate(term)
text = _(
u""" <div class="well">
This tool compares the physically existing database structure (tables, columns) with the current configuration settings.
The database structure is shown on the left, configuration settings on the right. <br><br>
Existing database columns will only be altered if manually selected in the 'Modify' column. Modifying a table may destroy the data
stored (e.g if converted from string to integer), so don't forget to create backups of the database before modifying anything.<br>
By default this tool will only create new tables and columns and never delete any column.
</div> """
)
self.stream.write(localizer.translate(_(text)))
self.stream.write(
u"""<form action="" method="post">
<input type="hidden" name="tag" value="dbStructureUpdater">
<input type="hidden" name="modify" value="1">"""
)
app = self.app
try:
conf = app.dbConfiguration
connection = app.NewConnection()
if not connection:
self.stream.write(
localizer.translate(
_(u"""<div class="alert alert-error">No database connection configured</div>""")
)
)
return 0
except OperationalError, e:
self.stream.write(
localizer.translate(_(u"""<div class="alert alert-error">No database connection configured</div>"""))
)
return 0
示例9: RenderField
def RenderField(self, fld, data=None, context=None):
"""
Render the data field for html display. Rendering depends on the datatype defined
in the field configuration.
If data is None the current context is used.
returns string
"""
if context is None:
context = self.context
if isinstance(fld, basestring):
fld = context.GetFieldConf(fld)
if not fld:
return _(u"<em>Unknown field</em>")
if data is None:
data = context.data.get(fld['id'], context.meta.get(fld['id']))
if fld['datatype']=='file':
url = self.FileUrl(fld['id'])
if not url:
return u""
url2 = url.lower()
if url2.find(u".jpg")!=-1 or url2.find(u".jpeg")!=-1 or url2.find(u".png")!=-1 or url2.find(u".gif")!=-1:
return u"""<img src="%s">""" % (url)
return u"""<a href="%s">download</a>""" % (url)
return FieldRenderer(context).Render(fld, data, context=context)
示例10: editroot
def editroot(self):
root = self.context.app.root(name="")
if not IPersistentRoot.providedBy(root):
return {u"content": _(u"The default root does not support persistent data storage."), u"result": False, u"head": u""}
fields = (
FieldConf(id=u"pool_filename", datatype="string", size=30, required=1, name=_(u"Root url name"),
settings={"validator": RootnameValidator}, default=root.configuration.id),
FieldConf(id=u"title", datatype="string", size=255, required=0, name=_(u"Root title"), default=root.configuration.name),
FieldConf(id=u"description", datatype="text", size=5000, required=0, name=_(u"Root description")),
FieldConf(id="pool_groups", datatype="checkbox", size=250, default="", name=_(u"Permission"),
description=_(u"Only displayed to users in the selected group"))
)
form = RootForm(view=self, context=root, app=self.context)
form.fields = fields
form.Setup()
# process and render the form.
result, data, action = form.Process()
return {u"content": data, u"result": result, u"head": form.HTMLHead()}
示例11: design
def design(self):
fields = (
FieldConf(id=u"columns", datatype="lines", size=100, required=0, name=_(u"Column names"), description=_(u"Column names used in the main template. For multiple columns enter one per line.")),
)
form = ConfigurationForm(view=self, context=self.context.configuration, app=self.context)
form.fields = fields
form.Setup()
# process and render the form.
result, data, action = form.Process()
return {u"content": data, u"result": result, u"head": form.HTMLHead()}
示例12: elementListWidget
def elementListWidget(self, obj=None, elements=None, addResponse=True):
"""
Widget with existing elements list and edit options
call with obj = current object / page
"""
#i18n?
if not obj:
obj=self.context
html = u"""<div>
<h4 onclick="$.fn.editblocks().toggleBlock('#elements%(id)s',event)">%(title)s</h4>
%(blocks)s
</div>
"""
elHtml = u"""<div class="element">
<div class="el_title">%(title)s</div>
<div class="el_options">%(options)s</div>
<br style="clear:both"/>
</div>"""
if not elements:
elements = obj.GetPageElements()
localizer = translator(self.request)
blocks = StringIO()
static = self.StaticUrl("nive.cms.cmsview:static/images/types/")
for el in elements:
t = el.GetTitle()
if not t:
t = u"<em>%s</em>" % (localizer(el.GetTypeName(), self.request))
if el.GetTypeID()=="box":
title = u"<img src='%s%s.png' align='top'/> %s: %s" % (static, el.GetTypeID(), localizer(u"Box"), t)
blocks.write(elHtml % {u"title": title, u"options": self.editBlockList(obj=el, showCCP=True)})
for elb in el.GetPageElements():
t = elb.GetTitle()
if not t:
t = u"<em>%s</em>" % (localizer(elb.GetTypeName()))
title = u"> <img src='%s%s.png' align='top'/> %s" % (static, elb.GetTypeID(), t)
blocks.write(elHtml % {u"title": title, u"options": self.editBlockList(obj=elb, showCCP=True)})
else:
title = u"<img src='%s%s.png' align='top'/> %s" % (static, el.GetTypeID(), t)
blocks.write(elHtml % {u"title": title, u"options": self.editBlockList(obj=el, showCCP=True)})
if not len(elements):
blocks.write(localizer(_(u"<p><i>empty</i></p>")))
data = html % {u"blocks": blocks.getvalue(), u"id": str(obj.GetID()), u"title": localizer(_(u"Page elements"))}
if addResponse:
r = Response(content_type="text/html", conditional_response=True)
r.unicode_body = data
return r
return data
示例13: selectPageElement
def selectPageElement(self):
user = self.User()
lt = self.context.GetAllowedTypes(user)
tmpl = u"""<a href="add?pool_type=%s" rel="niveOverlay" class="nivecms addlink">%s</a> """
html = StringIO()
html.write(u"""<div class="addElements">""")
#opt
for t in lt:
html.write(tmpl % (t[u"id"], _(t[u"name"])))
html.write(u"</div>")
return html.getvalue()
示例14: action
def action(self):
transition = self.GetFormValue(u"t")
url = self.GetFormValue("redirect_url")
if not url:
url = self.PageUrl()
user = self.User()
self.context.WfAction("", user, transition=transition)
self.context.CommitInternal(user)
msg = _(u"OK")
self.Redirect(url, messages=[msg])
示例15: copy
def copy(self):
"""
"""
ids = self.GetFormValue(u"ids")
if not ids:
ids = [self.context.id]
cp = self.SetCopyInfo(u"copy", ids, self.context)
url = self.GetFormValue(u"url")
if not url:
url = self.PageUrl(self.context)
msgs = _(u"OK. Copied.")
return self.Redirect(url, [msgs])