本文整理汇总了Python中uliweb.i18n._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: to_python
def to_python(self, data):
for format in self.formats:
try:
return datetime.datetime(*time.strptime(data, format)[:6])
except ValueError:
continue
raise Exception, _("The datetime is not a valid datetime format.")
示例2: login
def login():
from uliweb.contrib.auth import authenticate, login
from forms import LoginForm
from uliweb.form import Submit, Tag
LoginForm.form_buttons = [Submit(value=_('Login'), _class="button")]
form = LoginForm()
if request.method == 'GET':
form.next.data = request.GET.get('next', '/')
return {'form':form, 'msg':''}
if request.method == 'POST':
flag = form.validate(request.params)
if flag:
f, d = authenticate(username=form.username.data, password=form.password.data)
if f:
request.session.remember = form.rememberme.data
login(form.username.data)
next = request.POST.get('next', '/')
return redirect(next)
else:
data = d
msg = form.errors.get('_', '') or _('Login failed!')
return {'form':form, 'msg':str(msg)}
示例3: edit
def edit(self, id):
"""
Edit the role
"""
from uliweb.utils.generic import EditView
from uliweb.orm import get_model
obj = self.model.get(int(id))
# def get_form_field(name, obj):
# from uliweb.form import SelectField
#
# if name == 'users':
# choices = [(x.id, x.username) for x in obj.users.all()]
# return SelectField('用户', name=name, choices=choices,
# multiple=True, html_attrs={'url':'/config/users/search'},
# datatype=int)
fields = [
{'name':'name', 'verbose_name':_('Name')},
{'name':'description', 'verbose_name':_('Description')},
]
view = EditView(self.model, url_for(PermissionView.view, id=int(id)),
obj=obj, fields=fields)
return view.run()
示例4: _get_title
def _get_title(self, action, obj=None):
name = getattr(self.model, '__verbose_name__', '')
if action == 'add':
return _("Add") + safe_unicode(name)
elif action == 'edit':
return _("Edit") + safe_unicode(name)
elif action == 'view':
return _("View") + safe_unicode(name)
示例5: form_validate
def form_validate(self, all_data):
from uliweb import settings
from uliweb.orm import get_model
User = get_model('user')
user = User.get(User.c.username==all_data['username'])
if not user:
return {'username': _('User "%s" is not existed!') % all_data['username']}
if not user.check_password(all_data['password']):
return {'password' : _('Password is not right.')}
示例6: form_validate
def form_validate(self, all_data):
from uliweb import request
error = {}
if not request.user.check_password(all_data.oldpassword):
error['oldpassword'] = _('Password is not right.')
if all_data.password != all_data.password1:
error['password1'] = _('Passwords are not the same between two types.')
return error
示例7: f
def f(data):
import Image
try:
try:
image = Image.open(data.file)
if size:
if image.size[0]>size[0] or image.size[1]>size[1]:
return _("The image file size exceeds the limit.")
except Exception, e:
return _("The file is not a valid image.")
finally:
data.file.seek(0)
示例8: _check_permission
def _check_permission(self, perm, acl=None, user=None, page=None,
err_msg=_("You have no right to access the page."), raise_exception=True):
from uliweb.orm import Model
if not user:
user = request.user
#superuser can do everything
if user and user.is_superuser:
return True
if not user:
err_msg = _("You are not logged in. ") + err_msg
if isinstance(acl, Model):
acl = acl.acl
else:
acl = acl
if page:
pagename = page.name
else:
pagename = ''
result, _perms = self._find_permissions(perm, acl, user, check_default=False, pagename=pagename)
while _perms:
if page:
parent = page.get_parent()
if parent:
_result, _perms = self._find_permissions(_perms, parent.acl, user, check_default=False, pagename=page.name)
result.update(_result)
page = parent
if not _perms:
break
else:
_result, _perms = self._find_permissions(_perms, None, user)
result.update(_result)
break
else:
_result, _perms = self._find_permissions(_perms, None, user)
result.update(_result)
break
if user:
log.debug('check permission perm=%s, user=%s, result=%r', perm, user.username, result)
else:
log.debug('check permission perm=%s, result=%r', perm, result)
if not result.get(perm, False):
if raise_exception:
error(err_msg)
else:
return False
return True
示例9: validate_username
def validate_username(self, data):
from uliweb.orm import get_model
if any((x in data for x in '<>& ')):
return _("Username can't include illegal characters, such as '<>&' and blank.")
if not r_username.match(data):
return _("Username can only include letter, number and '._/'.")
User = get_model('user')
user = User.get((User.c.username == data) & (User.c.id != self.object.id))
if user:
return _('Username is already existed.')
示例10: default_authenticate
def default_authenticate(username, password):
User = get_model('user')
if isinstance(username, (str, unicode)):
user = User.get(User.c.username==username)
else:
user = username
if user:
if user.check_password(password):
return True, user
else:
return False, {'password': _("Password isn't correct!")}
else:
return False, {'username': _('Username is not existed!')}
示例11: default_authenticate
def default_authenticate(username, password):
User = get_model("user")
if isinstance(username, (str, unicode)):
user = User.get(User.c.username == username)
else:
user = username
if user:
if user.check_password(password):
return True, user
else:
return False, {"password": _("Password isn't correct!")}
else:
return False, {"username": _('"{}" is not existed!').format(username)}
示例12: action
def action(value, obj):
from uliweb.core.html import Tag
actions = [
Tag('a', '<i class="fa fa-eye"></i>', title=_('查看'),
href=url_for(self.__class__.view, sheet_id=obj.id),
_class="btn btn-xs btn-flat btn-primary"),
Tag('a', '<i class="fa fa-remove"></i>', title=_('删除'),
href=url_for(self.__class__.delete, sheet_id=obj.id),
_class="btn btn-xs btn-flat btn-danger action-delete"),
]
return ' '.join(map(str, actions))
示例13: authenticate
def authenticate(username, password):
from ldap_login import ldapauth_handler
if not settings.LDAP.user_case_sensitive:
username = username.lower()
ldap_auth_ok, ldap_dict = ldapauth_handler.login(**{'username':username,'password':password})
if not ldap_auth_ok:
return False,{'password' : _('LDAP error:user does not exist or password is not correct!')}
User = get_model('user')
user = User.get(User.c.username==username)
if not user:
if settings.LDAP.user_auto_create:
user = User(username=username, password="")
user.set_password("")
user.save()
else:
return False,{'username': _('User "%s" does not existed!') % username}
class cresult:
pass
cresult.changed = False
#update user info
def update_user_with_ldap_attr(setting_attrname,user_attrname):
attrname = settings.LDAP.auth.get(setting_attrname,None)
if attrname:
attr = ldap_dict.get(attrname,None)
if attr:
if type(attr)==type([]):
attr = attr[0]
setattr(user,user_attrname,attr)
cresult.changed = True
update_user_with_ldap_attr('aliasname_attribute','nickname')
update_user_with_ldap_attr('email_attribute','email')
#sync groups
if settings.LDAP.sync_user_groups:
attrname = settings.LDAP.auth.get("memberof_attribute",None)
if attrname:
memberof = ldap_dict.get(attrname,None)
if memberof:
gnames = []
for i in memberof:
try:
gname = i.split(",")[0].split("=")[1]
gnames.append(gname)
except IndexError,e:
logging.error("error when handle memberOf( %s ): %s"%(i,e))
update_user_groups(user,gnames)
示例14: __get_choices_keys
def __get_choices_keys(choices):
if callable(choices):
choices = choices()
if isinstance(choices, dict):
keys = set(choices.keys())
elif isinstance(choices, (list, tuple)):
keys = set([])
for v in choices:
if isinstance(v, (list, tuple)):
keys.add(v[0])
else:
keys.add(v)
else:
raise Exception, _('Choices need a dict, tuple or list data.')
return keys
示例15: view
def view(self, id):
"""
Role display
"""
from uliweb.utils.generic import DetailView
fields = [
{'name':'name', 'verbose_name':_('Name')},
{'name':'description', 'verbose_name':_('Description')},
]
obj = self.model.get(int(id))
view = DetailView(self.model, obj=obj, fields=fields)
return view.run()