本文整理汇总了Python中pyvac.models.User类的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: render
def render(self):
settings = self.request.registry.settings
use_ldap = False
if 'pyvac.use_ldap' in settings:
use_ldap = asbool(settings.get('pyvac.use_ldap'))
user_attr = {}
users_teams = {}
if use_ldap:
# synchronise user groups/roles
User.sync_ldap_info(self.session)
ldap = LdapCache()
user_attr = ldap.get_users_units()
users_teams = {}
for team, members in ldap.list_teams().iteritems():
for member in members:
users_teams.setdefault(member, []).append(team)
return {u'user_count': User.find(self.session, count=True),
u'users': User.find(self.session, order_by=[User.dn]),
'use_ldap': use_ldap,
'ldap_info': user_attr,
'users_teams': users_teams,
}
开发者ID:doyousoft,项目名称:pyvac,代码行数:25,代码来源:account.py
示例2: render
def render(self):
from datetime import datetime
today = datetime.now()
end_date = datetime(today.year, 10, 31)
previsions = Request.get_previsions(self.session, end_date)
users_per_id = dict([(user.id, user)
for user in User.find(self.session)])
settings = self.request.registry.settings
use_ldap = False
if 'pyvac.use_ldap' in settings:
use_ldap = asbool(settings.get('pyvac.use_ldap'))
user_attr = {}
users_teams = {}
if use_ldap:
# synchronise user groups/roles
User.sync_ldap_info(self.session)
ldap = LdapCache()
user_attr = ldap.get_users_units()
users_teams = {}
for team, members in ldap.list_teams().iteritems():
for member in members:
users_teams.setdefault(member, []).append(team)
return {'users_per_id': users_per_id,
'use_ldap': use_ldap,
'ldap_info': user_attr,
'users_teams': users_teams,
'previsions': previsions,
'today': today,
'end_date': end_date,
}
开发者ID:doyousoft,项目名称:pyvac,代码行数:35,代码来源:request.py
示例3: test_by_country
def test_by_country(self):
from pyvac.models import User
country_id = 1
users = User.by_country(self.session, country_id)
self.assertEqual(len(users), 5)
country_id = 3
users = User.by_country(self.session, country_id)
self.assertEqual(len(users), 1)
开发者ID:doyousoft,项目名称:pyvac,代码行数:8,代码来源:test_models.py
示例4: test_get_rtt_taken_year
def test_get_rtt_taken_year(self):
from pyvac.models import User
user = User.by_login(self.session, u'jdoe')
self.assertIsInstance(user, User)
self.assertEqual(user.login, u'jdoe')
self.assertEqual(user.name, u'John Doe')
self.assertEqual(user.role, u'user')
self.assertEqual(user.get_rtt_taken_year(self.session, 2014), 0.5)
# no RTT for us country
user = User.by_login(self.session, u'manager3')
self.assertIsInstance(user, User)
self.assertEqual(user.country, u'us')
self.assertEqual(user.get_rtt_taken_year(self.session, 2014), 0)
开发者ID:doyousoft,项目名称:pyvac,代码行数:14,代码来源:test_models.py
示例5: update_view
def update_view(self, model, view):
settings = self.request.registry.settings
ldap = False
if 'pyvac.use_ldap' in settings:
ldap = asbool(settings.get('pyvac.use_ldap'))
if view['errors']:
self.request.session.flash('error;%s' % ','.join(view['errors']))
view['groups'] = Group.all(self.session, order_by=Group.name)
view['managers'] = User.by_role(self.session, 'manager')
if ldap:
ldap = LdapCache()
login = self.get_model().login
if login:
view['ldap_user'] = ldap.search_user_by_login(login)
else:
view['ldap_user'] = {}
view['managers'] = ldap.list_manager()
view['units'] = ldap.list_ou()
view['countries'] = Countries.all(self.session,
order_by=Countries.name)
# generate a random password for the user, he must change it later
password = randomstring()
log.info('temporary password generated: %s' % password)
view['password'] = password
view['view_name'] = self.__class__.__name__.lower()
view['myself'] = (self.user.id == self.get_model().id)
开发者ID:grigouze,项目名称:pyvac,代码行数:29,代码来源:account.py
示例6: authenticated_userid
def authenticated_userid(self, request):
auth = request.environ.get('HTTP_AUTHORIZATION')
try:
authmeth, auth = auth.split(' ', 1)
except AttributeError as ValueError: # not enough values to unpack
return None
if authmeth.lower() != 'basic':
return None
try:
# Python 3's string is already unicode
auth = auth.strip().decode('base64')
if sys.version_info[0] == 2:
auth = unicode(auth)
except binascii.Error: # can't decode
return None
try:
login, password = auth.split(':', 1)
except ValueError: # not enough values to unpack
return None
if User.by_credentials(DBSession(), login, password):
return login
return None
开发者ID:doyousoft,项目名称:pyvac,代码行数:27,代码来源:authentication.py
示例7: test_post_send_rtt_usage_not_enough_ko
def test_post_send_rtt_usage_not_enough_ko(self):
self.config.testing_securitypolicy(userid=u'janedoe',
permissive=True)
from pyvac.models import Request, User
from pyvac.views.request import Send
total_req = Request.find(self.session, count=True)
def mock_get_rtt_usage(self, session):
""" Get rrt usage for a user """
return {'allowed': 10, 'left': 0.5, 'state': 'error',
'taken': 9.5, 'year': 2014}
orig_get_rtt_usage = User.get_rtt_usage
User.get_rtt_usage = mock_get_rtt_usage
user = User.by_login(self.session, u'janedoe')
rtt_data = user.get_rtt_usage(self.session)
self.assertTrue(rtt_data)
request = self.create_request({'days': 1,
'date_from': '05/05/2015 - 05/05/2015',
'type': '2',
'breakdown': 'FULL',
})
view = Send(request)()
self.assertIsRedirect(view)
# no new requests were made
self.assertEqual(Request.find(self.session, count=True), total_req)
expected = ['error;You only have 0.5 RTT to use.']
self.assertEqual(request.session.pop_flash(), expected)
User.get_rtt_usage = orig_get_rtt_usage
开发者ID:doyousoft,项目名称:pyvac,代码行数:30,代码来源:test_request.py
示例8: process
def process(self, data):
""" denied by last_action_user_id
send mail to user
"""
req = Request.by_id(self.session, data['req_id'])
# retrieve user who performed last action
action_user = User.by_id(self.session, req.last_action_user_id)
# send mail to user
src = action_user.email
dst = req.user.email
content = """You request has been refused for the following reason: %s
Request details: %s""" % (req.reason, req.summarymail)
try:
self.send_mail(sender=src, target=dst, request=req,
content=content)
# update request status after sending email
req.notified = True
except Exception as err:
self.log.exception('Error while sending mail')
req.flag_error(str(err))
self.session.flush()
transaction.commit()
开发者ID:baloo,项目名称:pyvac,代码行数:25,代码来源:worker.py
示例9: test_by_credentials_ok
def test_by_credentials_ok(self):
from pyvac.models import User
user = User.by_credentials(self.session, u'jdoe', u'changeme')
self.assertIsInstance(user, User)
self.assertEqual(user.login, u'jdoe')
self.assertEqual(user.name, u'John Doe')
self.assertEqual(user.role, u'user')
开发者ID:doyousoft,项目名称:pyvac,代码行数:7,代码来源:test_models.py
示例10: test_get_rtt_usage
def test_get_rtt_usage(self):
from pyvac.models import User
user = User.by_login(self.session, u"jdoe")
self.assertIsInstance(user, User)
self.assertEqual(user.login, u"jdoe")
self.assertEqual(user.name, u"John Doe")
self.assertEqual(user.role, u"user")
with freeze_time("2014-12-25", ignore=["celery", "psycopg2", "sqlalchemy", "icalendar"]):
expected = {"allowed": 10, "left": 9.5, "state": "warning", "taken": 0.5, "year": 2014}
self.assertEqual(user.get_rtt_usage(self.session), expected)
# no RTT for us country
user = User.by_login(self.session, u"manager3")
self.assertIsInstance(user, User)
self.assertEqual(user.country, u"us")
self.assertIsNone(user.get_rtt_usage(self.session))
开发者ID:baloo,项目名称:pyvac,代码行数:16,代码来源:test_models.py
示例11: test_post_send_rtt_usage_empty_ok
def test_post_send_rtt_usage_empty_ok(self):
self.config.testing_securitypolicy(userid=u'janedoe',
permissive=True)
from pyvac.models import Request, User
from pyvac.views.request import Send
total_req = Request.find(self.session, count=True)
def mock_get_rtt_usage(self, session):
""" Get rrt usage for a user """
return
orig_get_rtt_usage = User.get_rtt_usage
User.get_rtt_usage = mock_get_rtt_usage
user = User.by_login(self.session, u'janedoe')
rtt_data = user.get_rtt_usage(self.session)
self.assertIsNone(rtt_data)
view = Send(self.create_request({
'days': 1,
'date_from': '05/05/2015 - 05/05/2015',
'type': '2',
'breakdown': 'AM',
}))()
self.assertIsRedirect(view)
self.assertEqual(Request.find(self.session, count=True), total_req + 1)
User.get_rtt_usage = orig_get_rtt_usage
开发者ID:doyousoft,项目名称:pyvac,代码行数:26,代码来源:test_request.py
示例12: test_by_name_country_rtt_ok
def test_by_name_country_rtt_ok(self):
from pyvac.models import User, VacationType
jdoe = User.by_login(self.session, u"jdoe")
with freeze_time("2014-12-25", ignore=["celery", "psycopg2", "sqlalchemy", "icalendar"]):
vac = VacationType.by_name_country(self.session, u"RTT", jdoe.country)
self.assertEqual(vac, 10)
开发者ID:baloo,项目名称:pyvac,代码行数:7,代码来源:test_models.py
示例13: test_by_country_ok
def test_by_country_ok(self):
from pyvac.models import User, VacationType
manager3 = User.by_login(self.session, u'manager3')
vac_types = VacationType.by_country(self.session, manager3.country)
self.assertEqual(len(vac_types), 5)
# take the first
vac_type = vac_types.pop()
self.assertIsInstance(vac_type, VacationType)
开发者ID:doyousoft,项目名称:pyvac,代码行数:8,代码来源:test_models.py
示例14: test_by_manager
def test_by_manager(self):
from pyvac.models import User, Request
manager1 = User.by_login(self.session, u'manager1')
requests = Request.by_manager(self.session, manager1)
self.assertEqual(len(requests), 2)
# take the first
request = requests.pop()
self.assertIsInstance(request, Request)
开发者ID:soulshake,项目名称:pyvac,代码行数:8,代码来源:test_models.py
示例15: test_alias_ko
def test_alias_ko(self):
from pyvac.models import Sudoer
from pyvac.models import User
user = User.by_login(self.session, u'jdoe')
self.assertIsInstance(user, User)
sudoers = Sudoer.alias(self.session, user)
self.assertEqual(sudoers, [])
开发者ID:doyousoft,项目名称:pyvac,代码行数:8,代码来源:test_models.py
示例16: test_by_name_country_rtt_ok
def test_by_name_country_rtt_ok(self):
from pyvac.models import User, VacationType
jdoe = User.by_login(self.session, u'jdoe')
with freeze_time('2014-12-25',
ignore=['celery', 'psycopg2', 'sqlalchemy',
'icalendar']):
vac = VacationType.by_name_country(self.session, u'RTT',
jdoe.country)
self.assertEqual(vac, 10)
开发者ID:doyousoft,项目名称:pyvac,代码行数:9,代码来源:test_models.py
示例17: test_get_rtt_usage
def test_get_rtt_usage(self):
from pyvac.models import User
user = User.by_login(self.session, u'jdoe')
self.assertIsInstance(user, User)
self.assertEqual(user.login, u'jdoe')
self.assertEqual(user.name, u'John Doe')
self.assertEqual(user.role, u'user')
with freeze_time('2014-12-25',
ignore=['celery', 'psycopg2', 'sqlalchemy',
'icalendar']):
expected = {'allowed': 10, 'left': 9.5, 'state': 'warning',
'taken': 0.5, 'year': 2014}
self.assertEqual(user.get_rtt_usage(self.session), expected)
# no RTT for us country
user = User.by_login(self.session, u'manager3')
self.assertIsInstance(user, User)
self.assertEqual(user.country, u'us')
self.assertIsNone(user.get_rtt_usage(self.session))
开发者ID:doyousoft,项目名称:pyvac,代码行数:18,代码来源:test_models.py
示例18: test_alias
def test_alias(self):
from pyvac.models import Sudoer
from pyvac.models import User
user = User.by_login(self.session, u'janedoe')
self.assertIsInstance(user, User)
sudoers = Sudoer.alias(self.session, user)
self.assertEqual(len(sudoers), 1)
sudoer = sudoers[0]
self.assertIsInstance(sudoer, User)
开发者ID:doyousoft,项目名称:pyvac,代码行数:10,代码来源:test_models.py
示例19: render
def render(self):
settings = self.request.registry.settings
use_ldap = False
if 'pyvac.use_ldap' in settings:
use_ldap = asbool(settings.get('pyvac.use_ldap'))
user_attr = {}
if use_ldap:
# synchronise user groups/roles
User.sync_ldap_info(self.session)
ldap = LdapCache()
user_attr = ldap.get_users_units()
return {u'user_count': User.find(self.session, count=True),
u'users': User.find(self.session, order_by=[User.dn]),
'use_ldap': use_ldap,
'ldap_info': user_attr,
}
开发者ID:grigouze,项目名称:pyvac,代码行数:19,代码来源:account.py
示例20: populate
def populate(engine, ldap):
""" Retrieve users from ldap directory and import them in local database
"""
session = DBSession()
# retrieve managers from dedicated group
managers = ldap.list_manager()
# retrieve users
searchFilter = '(&(objectClass=inetOrgPerson)(employeetype=Employee))'
required = ['objectClass', 'employeeType', 'cn', 'givenName', 'sn',
'manager', 'mail', 'ou', 'uid', 'userPassword']
users = ldap._search(searchFilter, required)
for user_dn, user_entry in users:
user_data = ldap.parse_ldap_entry(user_dn, user_entry)
login = user_data['login'].decode('utf-8')
# check what type of user it is
group = u'user'
# if it's a manager he should be in manager group
if user_data['dn'] in managers:
group = u'manager'
# if it's an admin he should be in admin group
what = '(member=%s)' % user_data['dn']
if len(ldap._search_admin(what, None)) > 0:
group = u'admin'
user = User.by_login(session, login)
if not user:
user = User.create_from_ldap(session, user_data, group)
else:
# update user with ldap informations in case it changed
user.email = user_data['email'].decode('utf-8')
user.firstname = user_data['firstname'].decode('utf-8')
user.lastname = user_data['lastname'].decode('utf-8')
user.manager_dn = user_data['manager_dn'].decode('utf-8')
user.dn = user_data['dn'].decode('utf-8')
user.role = group
session.add(user)
session.commit()
开发者ID:doyousoft,项目名称:pyvac,代码行数:43,代码来源:importldap.py
注:本文中的pyvac.models.User类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论