本文整理汇总了Python中uliweb.i18n._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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.")
开发者ID:victorlv,项目名称:uliweb,代码行数:7,代码来源:uliform.py
示例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)}
开发者ID:datakungfu,项目名称:uliweb,代码行数:25,代码来源:views.py
示例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()
开发者ID:limodou,项目名称:plugs,代码行数:27,代码来源:views.py
示例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)
开发者ID:chyhutu,项目名称:plugs,代码行数:8,代码来源:views.py
示例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.')}
开发者ID:bobgao,项目名称:uliweb,代码行数:10,代码来源:forms.py
示例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
开发者ID:chyhutu,项目名称:plugs,代码行数:11,代码来源:forms.py
示例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)
开发者ID:biluo1989,项目名称:uliweb,代码行数:12,代码来源:validators.py
示例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
开发者ID:chyhutu,项目名称:plugs,代码行数:52,代码来源:views.py
示例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.')
开发者ID:chyhutu,项目名称:plugs,代码行数:13,代码来源:forms.py
示例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!')}
开发者ID:28sui,项目名称:uliweb,代码行数:13,代码来源:__init__.py
示例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)}
开发者ID:limodou,项目名称:uliweb,代码行数:13,代码来源:__init__.py
示例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))
开发者ID:naomhan,项目名称:uliweb-peafowl,代码行数:13,代码来源:views.py
示例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)
开发者ID:chu888chu888,项目名称:Python-shapps,代码行数:51,代码来源:__init__.py
示例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
开发者ID:biluo1989,项目名称:uliweb,代码行数:15,代码来源:validators.py
示例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()
开发者ID:limodou,项目名称:plugs,代码行数:15,代码来源:views.py
示例16: form_validate
def form_validate(self, data):
from uliweb.utils.common import import_attr, log
from uliweb.orm import Model
errors = {}
if data['basemodel']:
try:
m = functions.get_model(data['basemodel'])
if not (isinstance(m, type) and issubclass(m, Model)):
errors['basemodel'] = _("Object is not a subclass of Model")
except Exception as e:
log.exception(e)
errors['basemodel'] = _("Model can't be imported")
return errors
开发者ID:naomhan,项目名称:uliweb-peafowl,代码行数:16,代码来源:views.py
示例17: get_buttons
def get_buttons(self):
b = Buf()
if self._buttons is None:
b << [Button(value=_("Submit"), _class="btn btn-primary", name="submit", type="submit")]
else:
b << self._buttons
return str(b)
开发者ID:victorlv,项目名称:uliweb,代码行数:7,代码来源:uliform.py
示例18: login
def login(self):
from uliweb.contrib.auth import login
form = functions.get_form('auth.LoginForm')()
if request.user:
next = request.GET.get('next','/admin')
if next:
return redirect(next)
if request.method == 'GET':
form.next.data = request.GET.get('next', request.referrer or '/')
return {'form':form, 'msg':''}
if request.method == 'POST':
flag = form.validate(request.params)
if flag:
f, d = functions.authenticate(username=form.username.data, password=form.password.data)
if f:
request.session.remember = form.rememberme.data
login(form.username.data)
next = urllib.unquote(request.POST.get('next', '/admin'))
return redirect(next)
else:
form.errors.update(d)
msg = form.errors.get('_', '') or _('Login failed!')
return {'msg':str(msg)}
开发者ID:vaneoooo,项目名称:SailYX,代码行数:26,代码来源:views.py
示例19: generic_add
def generic_add(model=None, get_url=get_url, layout='layout.html',
template=None, title=None, view=None, data=None):
from uliweb.utils.generic import AddView
from uliweb import response
if not view:
Model = get_model(model)
if not model or not Model:
return error("Can't find model [%s], please check it" % model)
get_url = partial(get_url, action='view')
view = AddView(model, get_url)
result = view.run()
if isinstance(result, dict):
template = template or 'generic_add.html'
response.template = template
if not title:
name = getattr(model, '__verbose_name__', '')
title = _("Add") + safe_unicode(name)
elif callable(title):
title = title('add')
data = data or {}
result['get_url'] = get_url
result['title'] = title
result.update(data)
return render_template(template, layout, result)
else:
return result
开发者ID:chyhutu,项目名称:plugs,代码行数:29,代码来源:views.py
示例20: login
def login():
from uliweb.contrib.auth import login
form = functions.get_form('auth.LoginForm')()
if request.user:
next = request.values.get('next')
if next:
return redirect(next)
next = request.values.get('next')
if not next:
next = add_prefix('/')
if request.method == 'GET':
form.next.data = next
return {'next': next}
if request.method == 'POST':
flag = form.validate(request.values)
if flag:
f, d = functions.authenticate(username=form.username.data, password=form.password.data)
if f:
request.session.remember = form.rememberme.data
login(form.username.data)
next = unquote(next)
return redirect(next)
else:
form.errors.update(d)
if request.is_xhr:
return json({'success': False, '_': 'Login Failed', 'errors': form.errors})
else:
msg = form.errors.get('_', '') or _('Login failed!')
return {'form': form, 'msg': str(msg)}
开发者ID:limodou,项目名称:uliweb-apps,代码行数:32,代码来源:views.py
注:本文中的uliweb.i18n._函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论