当前位置: 首页>>代码示例>>Python>>正文


Python UserSession.connect方法代码示例

本文整理汇总了Python中larper.UserSession.connect方法的典型用法代码示例。如果您正苦于以下问题:Python UserSession.connect方法的具体用法?Python UserSession.connect怎么用?Python UserSession.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在larper.UserSession的用法示例。


在下文中一共展示了UserSession.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _edit_profile

# 需要导入模块: from larper import UserSession [as 别名]
# 或者: from larper.UserSession import connect [as 别名]
def _edit_profile(request, unique_id, new_account):
    ldap = UserSession.connect(request)
    person = ldap.get_by_unique_id(unique_id)

    del_form = forms.DeleteForm(
        initial=dict(unique_id=unique_id))

    if person:
        if request.method == 'POST':
            form = forms.ProfileForm(request.POST, request.FILES)
            if form.is_valid():
                ldap = UserSession.connect(request)
                ldap.update_person(unique_id, form.cleaned_data)
                ldap.update_profile_photo(unique_id, form.cleaned_data)
                if new_account:
                    return redirect('confirm_register')
                else:
                    return redirect('profile', unique_id)
        else:
            initial = dict(first_name=person.first_name,
                           last_name=person.last_name,
                           biography=person.biography,)

            initial.update(_get_services_fields(ldap, unique_id))
            form = forms.ProfileForm(initial)

        return jingo.render(request, 'phonebook/edit_profile.html', dict(
                form=form,
                delete_form=del_form,
                person=person,
                registration_flow=new_account,
                ))
    else:
        raise Http404
开发者ID:ozten,项目名称:mozillians,代码行数:36,代码来源:views.py

示例2: f

# 需要导入模块: from larper import UserSession [as 别名]
# 或者: from larper.UserSession import connect [as 别名]
 def f():
     if not hasattr(user, 'person'):
         directory = UserSession.connect(request)
         # Stale data okay
         user.person = directory.get_by_unique_id(user.unique_id)
     # Presence of voucher DN is enough, don't validate
     return bool(user.person.voucher_unique_id)
开发者ID:evilpie,项目名称:mozillians,代码行数:9,代码来源:middleware.py

示例3: _with_temp_user

# 需要导入模块: from larper import UserSession [as 别名]
# 或者: from larper.UserSession import connect [as 别名]
def _with_temp_user(fn):
    """
    Runs a function in the context of a newly created user.
    It will cleanup the user after fn is run, unless it
    has already been deleted.

    fn - A callable function. First parameter should be
    a unique_id string.
    """
    regi = RegistrarSession.connect(
        _mock_request('/en-US/search?q=David'))
    username = '%[email protected]' % str(uuid4())[0:8]
    data = dict(first_name='Jane', last_name='Doe',
                email=username, password='secret password',
                biography='Keeping it real.',
                         irc_nickname='',
                         irc_nickname_unique_id='')
    new_unique_id = regi.create_person(data)
    fn(new_unique_id)

    directory = UserSession.connect(_mock_request('/en-US/search?q=David'))
    try:
        directory.get_by_unique_id(new_unique_id)

        admin = AdminSession.connect(_mock_request('/en-US/search?q=David'))
        admin.delete_person(new_unique_id)
    except:
        pass
    finally:
        pass
开发者ID:tantek,项目名称:mozillians,代码行数:32,代码来源:test_larper.py

示例4: photo

# 需要导入模块: from larper import UserSession [as 别名]
# 或者: from larper.UserSession import connect [as 别名]
def photo(request, unique_id):
    ldap = UserSession.connect(request)
    image = ldap.profile_photo(unique_id)
    if image:
        return HttpResponse(image, mimetype="image/jpeg")
    else:
        return redirect('/media/img/unknown.png')
开发者ID:ozten,项目名称:mozillians,代码行数:9,代码来源:views.py

示例5: _profile

# 需要导入模块: from larper import UserSession [as 别名]
# 或者: from larper.UserSession import connect [as 别名]
def _profile(request, person, use_master):
    vouch_form = None
    ldap = UserSession.connect(request)

    if person.voucher_unique_id or cache.get('vouched_' + person.unique_id):
        try:
            # Stale data okay
            person.voucher = ldap.get_by_unique_id(person.voucher_unique_id)
        except NO_SUCH_PERSON:
            # Bug#688788 Invalid voucher is okay
            person.voucher = BAD_VOUCHER
    elif request.user.unique_id != person.unique_id:
        voucher = request.user.unique_id
        vouch_form = forms.VouchForm(initial=dict(
                vouchee=person.unique_id))

    services = ldap.profile_service_ids(person.unique_id, use_master)
    person.irc_nickname = None
    if MOZILLA_IRC_SERVICE_URI in services:
        person.irc_nickname = services[MOZILLA_IRC_SERVICE_URI]
        del services[MOZILLA_IRC_SERVICE_URI]

    # Get user groups from their profile.
    groups = person.get_profile().groups.all()

    data = dict(person=person, vouch_form=vouch_form, services=services,
                groups=groups)
    return render(request, 'phonebook/profile.html', data)
开发者ID:evilpie,项目名称:mozillians,代码行数:30,代码来源:views.py

示例6: _profile

# 需要导入模块: from larper import UserSession [as 别名]
# 或者: from larper.UserSession import connect [as 别名]
def _profile(request, person, use_master):
    vouch_form = None
    ldap = UserSession.connect(request)

    if person.voucher_unique_id:
        try:
            # Stale data okay
            person.voucher = ldap.get_by_unique_id(person.voucher_unique_id)
        except NO_SUCH_PERSON:
            # Bug#688788 Invalid voucher is okay
            person.voucher = BAD_VOUCHER
    elif request.user.unique_id != person.unique_id:
        voucher = request.user.unique_id
        vouch_form = forms.VouchForm(initial=dict(
                voucher=voucher,
                vouchee=person.unique_id))

    services = ldap.profile_service_ids(person.unique_id, use_master)
    person.irc_nickname = None
    if MOZILLA_IRC_SERVICE_URI in services:
        person.irc_nickname = services[MOZILLA_IRC_SERVICE_URI]
        del services[MOZILLA_IRC_SERVICE_URI]

    return jingo.render(request, 'phonebook/profile.html',
                        dict(absolutify=absolutify,
                             person=person,
                             vouch_form=vouch_form,
                             services=services))
开发者ID:tantek,项目名称:mozillians,代码行数:30,代码来源:views.py

示例7: vouch_person

# 需要导入模块: from larper import UserSession [as 别名]
# 或者: from larper.UserSession import connect [as 别名]
    def vouch_person(self, new_unique_id):
        request = _mock_request('/en-US/', username='[email protected]')
        directory = self.d = UserSession.connect(request)

        ok_(directory.record_vouch('7f3a67u000001', new_unique_id))
        newbie = directory.get_by_unique_id(new_unique_id)
        eq_('7f3a67u000001', newbie.voucher_unique_id)
开发者ID:tantek,项目名称:mozillians,代码行数:9,代码来源:test_larper.py

示例8: test_update_person

# 需要导入模块: from larper import UserSession [as 别名]
# 或者: from larper.UserSession import connect [as 别名]
    def test_update_person(self):
        unique_id = '7f3a67u000098'
        username = '[email protected]'
        request = _mock_request('/en-US/search?q=David',
                                username=username,
                                unique_id='7f3a67u000098')

        directory = self.d = UserSession.connect(request)

        amandeep = directory.get_by_unique_id(unique_id)
        first_name = amandeep.first_name
        last_name = amandeep.last_name
        eq_('Amandeep', first_name)
        eq_('McIlrath', last_name)
        eq_('Amandeep McIlrath', amandeep.full_name)

        form_data = dict(first_name='Deep',
                         last_name=last_name,
                         biography='',
                         irc_nickname='',
                         irc_nickname_unique_id='',)

        ok_(directory.update_person(unique_id, form_data))

        amandeep = directory.get_by_unique_id(unique_id)
        eq_('Deep', amandeep.first_name, 'First name edit worked')
        eq_(last_name, amandeep.last_name, 'No change')

        form_data['first_name'] = first_name
        ok_(directory.update_person(unique_id, form_data))
        amandeep = directory.get_by_unique_id(unique_id)
        eq_(first_name, amandeep.first_name)
开发者ID:tantek,项目名称:mozillians,代码行数:34,代码来源:test_larper.py

示例9: test_person_with_no_given_name

# 需要导入模块: from larper import UserSession [as 别名]
# 或者: from larper.UserSession import connect [as 别名]
    def test_person_with_no_given_name(self):
        request = _mock_request('/en-US/')
        directory = self.d = UserSession.connect(request)
        matt = directory.get_by_unique_id("7f3a67u000002")

        eq_('[email protected]', matt.username)
        eq_('7f3a67u000002', matt.unique_id)
        eq_('', matt.first_name)
开发者ID:tantek,项目名称:mozillians,代码行数:10,代码来源:test_larper.py

示例10: test_search_is_fun

# 需要导入模块: from larper import UserSession [as 别名]
# 或者: from larper.UserSession import connect [as 别名]
    def test_search_is_fun(self):
        request = _mock_request('/en-US/search?q=David')
        directory = self.d = UserSession.connect(request)
        rs = directory.search("Bridget Hill")
        eq_(1, len(rs))

        rs = directory.search("[email protected]")
        eq_(1, len(rs))
开发者ID:tantek,项目名称:mozillians,代码行数:10,代码来源:test_larper.py

示例11: test_search_by_irc_nick

# 需要导入模块: from larper import UserSession [as 别名]
# 或者: from larper.UserSession import connect [as 别名]
 def test_search_by_irc_nick(self):
     request = _mock_request('/en-US/')
     directory = UserSession.connect(request)
     rs = directory.search("andrew_f")
     eq_(1, len(rs))
     person = rs[0]
     eq_('Andrew Findlay', person.full_name)
     eq_('8', person.unique_id)
开发者ID:camd,项目名称:mozillians,代码行数:10,代码来源:test_larper.py

示例12: vouch

# 需要导入模块: from larper import UserSession [as 别名]
# 或者: from larper.UserSession import connect [as 别名]
def vouch(request):
    form = forms.VouchForm(request.POST)
    if form.is_valid():
        ldap = UserSession.connect(request)
        data = form.cleaned_data
        vouchee = data.get('vouchee')
        ldap.record_vouch(data.get('voucher'), vouchee)
        return redirect(reverse('profile', args=[vouchee]))
开发者ID:ozten,项目名称:mozillians,代码行数:10,代码来源:views.py

示例13: photo

# 需要导入模块: from larper import UserSession [as 别名]
# 或者: from larper.UserSession import connect [as 别名]
def photo(request, unique_id):
    needs_master = (request.user.unique_id == unique_id)

    ldap = UserSession.connect(request)
    image = ldap.profile_photo(unique_id, use_master=needs_master)
    if image:
        return HttpResponse(image, mimetype="image/jpeg")
    else:
        return redirect('/media/img/unknown.png')
开发者ID:evilpie,项目名称:mozillians,代码行数:11,代码来源:views.py

示例14: search

# 需要导入模块: from larper import UserSession [as 别名]
# 或者: from larper.UserSession import connect [as 别名]
def search(request):
    limit = None
    nonvouched_only = False
    people = []
    size_exceeded = False
    show_pagination = False
    form = forms.SearchForm(request.GET)

    if form.is_valid():
        query = form.cleaned_data.get("q", "")
        limit = form.cleaned_data["limit"]
        nonvouched_only = form.cleaned_data["nonvouched_only"]

        if request.user.is_authenticated():
            ldap = UserSession.connect(request)
            try:
                # Stale data okay
                sortk = attrgetter("full_name")
                people = sorted(ldap.search(query, nonvouched_only=nonvouched_only), key=sortk)

                # Search based on group name as well
                groups = Group.objects.filter(name__icontains=query)[:limit]
                for group in groups:
                    for user in users_from_groups(
                        request, group, limit=forms.PAGINATION_LIMIT, nonvouched_only=nonvouched_only
                    ):
                        if not user.unique_id in [p.unique_id for p in people]:
                            people.append(user)

                paginator = Paginator(people, limit)
                page = request.GET.get("page", 1)
                try:
                    people = paginator.page(page)
                except PageNotAnInteger:
                    people = paginator.page(1)
                except EmptyPage:
                    people = paginator.page(paginator.num_pages)

                if paginator.count > forms.PAGINATION_LIMIT:
                    show_pagination = True

            except SIZELIMIT_EXCEEDED:
                size_exceeded = True

            if len(people) == 1 and not show_pagination:
                return redirect(reverse("profile", args=[people[0].unique_id]))

    d = dict(
        people=people,
        form=form,
        limit=limit,
        nonvouched_only=nonvouched_only,
        show_pagination=show_pagination,
        size_exceeded_error=size_exceeded,
    )
    return render(request, "phonebook/search.html", d)
开发者ID:ahrokib,项目名称:mozillians,代码行数:58,代码来源:views.py

示例15: test_connection_pooling

# 需要导入模块: from larper import UserSession [as 别名]
# 或者: from larper.UserSession import connect [as 别名]
    def test_connection_pooling(self):
        # Don't use _mock_request, nor TestLarper since we want full control
        # over the request to find pooling bugs
        rf = RequestFactory()
        request = rf.get('/en-US')
        request.session = {}
        request.user = MockUser('[email protected]', '7f3a67u000001')

        larper.store_password(request, 'secret')

        R = larper.READ
        W = larper.WRITE

        directory = UserSession.connect(request)
        self.assertFalse(hasattr(request, 'larper_conns'))

        regi = RegistrarSession.connect(request)
        self.assertFalse(hasattr(request, 'larper_conns'))

        regi_W_conn = regi._ensure_conn(W)
        regi_W_conn2 = regi._ensure_conn(W)

        self.assertIs(regi_W_conn, regi_W_conn2)
        self.assertTrue(hasattr(request, 'larper_conns'))
        self.assertEqual(len(request.larper_conns[R].keys()), 0)
        self.assertEqual(len(request.larper_conns[W].keys()), 1)

        dir_W_conn = directory._ensure_conn(W)
        dir_W_conn2 = directory._ensure_conn(W)

        self.assertIs(dir_W_conn, dir_W_conn2)
        self.assertEqual(len(request.larper_conns[R].keys()), 0)
        self.assertEqual(len(request.larper_conns[W].keys()), 2)

        dir_R_conn = directory._ensure_conn(R)

        admin = AdminSession.connect(request)
        admin_R_conn = admin._ensure_conn(R)
        admin_R_conn2 = admin._ensure_conn(R)
        admin_W_conn = admin._ensure_conn(W)

        self.assertIs(admin_R_conn, admin_R_conn2)
        self.assertIsNot(admin_R_conn, admin_W_conn)

        for conn in (regi_W_conn, dir_R_conn, admin_R_conn, admin_W_conn):
            # nor is it dir_R_conn2 or admin_R_conn2
            self.assertIsNot(dir_W_conn, conn)

        self.assertEqual(len(request.larper_conns[R].keys()), 2)
        self.assertEqual(len(request.larper_conns[W].keys()), 3)

        directory.disconnect(request)

        self.assertEqual(len(request.larper_conns[R].keys()), 0)
        self.assertEqual(len(request.larper_conns[W].keys()), 0)
开发者ID:tantek,项目名称:mozillians,代码行数:57,代码来源:test_larper.py


注:本文中的larper.UserSession.connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。