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


Python model.User类代码示例

本文整理汇总了Python中mediadrop.model.User的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: _create_user_without_groups

 def _create_user_without_groups(self):
     user = User()
     user.user_name = u"joe"
     user.email_address = u"[email protected]"
     user.display_name = u"Joe"
     user.groups = []
     DBSession.add(user)
     DBSession.flush()
     return user
开发者ID:njZhuMin,项目名称:mediacore-community,代码行数:9,代码来源:filtering_restricted_items_test.py

示例2: permissions_for_user

 def permissions_for_user(cls, user, config):
     if user is None:
         user = User()
         user.display_name = u'Anonymous User'
         user.user_name = u'anonymous'
         user.email_address = '[email protected]'
         anonymous_group = Group.by_name(u'anonymous')
         groups = filter(None, [anonymous_group])
     else:
         meta_groups = Group.query.filter(Group.group_name.in_([u'anonymous', u'authenticated']))
         groups = list(user.groups) + list(meta_groups)
     return UserPermissions(user, cls(config), groups=groups)
开发者ID:FelixSchwarz,项目名称:mediadrop-test-renames,代码行数:12,代码来源:permission_system.py

示例3: test_handles_bad_came_from_parameter_gracefully

 def test_handles_bad_came_from_parameter_gracefully(self):
     user = User.example()
     quoted_came_from = urllib.quote_plus('invalid junk')
     request = self.init_fake_request(server_name='server.example',
         request_uri='/login/post_login?came_from='+quoted_came_from)
     response = self.call_post_login(user, request=request)
     assert_equals('http://server.example:80/', response.location)
开发者ID:knyar,项目名称:mediadrop,代码行数:7,代码来源:login_test.py

示例4: test_can_redirect_to_domains_on_same_domain_after_login

 def test_can_redirect_to_domains_on_same_domain_after_login(self, came_from):
     user = User.example()
     quoted_came_from = urllib.quote_plus(came_from)
     request = self.init_fake_request(server_name='server.example',
         request_uri='/login/post_login?came_from='+quoted_came_from)
     response = self.call_post_login(user, request=request)
     assert_equals(came_from, response.location)
开发者ID:knyar,项目名称:mediadrop,代码行数:7,代码来源:login_test.py

示例5: create_new_user

def create_new_user(username, config):
    from mediadrop.model import DBSession, User, fetch_row, Group

    user = User.by_user_name(username)

    if user is None:
        try:
            print "MIDDLEWARE"
            print config
            l = ldap.initialize(config['ldap_url'])        
            l.simple_bind_s(config['ldap_binddn'], config['ldap_pw'])
            filter = '(samaccountname=%s)' % username
            r = l.search_s(config['ldap_base'],ldap.SCOPE_SUBTREE, filter, ['displayname', 'mail'])
            l.unbind_s()

            user_attrs = {}
            for dn, entry in r:
                for attr, v in entry.iteritems():
                    user_attrs[attr] = v[0]
        except ldap.LDAPError:
            l.unbind_s()

        new_user = fetch_row(User, "new")
        new_user.display_name = user_attrs['displayName']
        new_user.email_address = user_attrs['mail']
        new_user.user_name = username
        query = DBSession.query(Group).filter(Group.group_name.in_(['authenticated']))
        new_user.groups = list(query.all())

        DBSession.add(new_user)
        DBSession.commit()
开发者ID:mkrysiak,项目名称:mediadrop,代码行数:31,代码来源:middleware.py

示例6: test_non_editors_are_redirect_to_home_page_after_login

 def test_non_editors_are_redirect_to_home_page_after_login(self):
     user = User.example()
     perm = MediaDropPermissionSystem.permissions_for_user(user, config)
     assert_false(perm.contains_permission(u'edit'))
     assert_false(perm.contains_permission(u'admin'))
     
     response = self.call_post_login(user)
     assert_equals('http://server.example:80/', response.location)
开发者ID:knyar,项目名称:mediadrop,代码行数:8,代码来源:login_test.py

示例7: test_uses_correct_redirect_url_if_mediadrop_is_mounted_in_subdirectory

    def test_uses_correct_redirect_url_if_mediadrop_is_mounted_in_subdirectory(self):
        user = User.example()

        request = self.init_fake_request(server_name="server.example", request_uri="/login/post_login")
        request.environ["SCRIPT_NAME"] = "my_media"

        response = self.call_post_login(user, request=request)
        assert_equals("http://server.example:80/my_media/", response.location)
开发者ID:GitReadysoft,项目名称:mediadrop,代码行数:8,代码来源:login_test.py

示例8: test_prevent_parameter_base_redirection

    def test_prevent_parameter_base_redirection(self):
        user = User.example()

        came_from = urllib.quote_plus('http://evil.site/malware/')
        request = self.init_fake_request(server_name='server.example',
            request_uri='/login/post_login?came_from='+came_from)
        response = self.call_post_login(user, request=request)
        assert_equals('http://server.example:80/', response.location,
            message='should only redirect to urls on the same domain')
开发者ID:knyar,项目名称:mediadrop,代码行数:9,代码来源:login_test.py

示例9: test_uses_correct_redirect_url_if_mediadrop_is_mounted_in_subdirectory

 def test_uses_correct_redirect_url_if_mediadrop_is_mounted_in_subdirectory(self):
     user = User.example()
     
     request = self.init_fake_request(server_name='server.example',
         request_uri='/login/post_login')
     request.environ['SCRIPT_NAME'] = 'my_media'
     
     response = self.call_post_login(user, request=request)
     assert_equals('http://server.example:80/my_media/', response.location)
开发者ID:knyar,项目名称:mediadrop,代码行数:9,代码来源:login_test.py

示例10: test_can_create_example_user

 def test_can_create_example_user(self):
     user = User.example()
     
     assert_not_none(user.id)
     assert_equals(u'joe', user.user_name)
     assert_equals(u'Joe Smith', user.display_name)
     assert_equals(u'[email protected]', user.email_address)
     assert_almost_equals(datetime.now(), user.created, 
                          max_delta=timedelta(seconds=1))
开发者ID:SmallsLIVE,项目名称:mediadrop,代码行数:9,代码来源:user_example_test.py

示例11: _create_user_with_admin_permission_only

 def _create_user_with_admin_permission_only(self):
     admin_perm = DBSession.query(Permission).filter(Permission.permission_name == u'admin').one()
     second_admin_group = Group.example(name=u'Second admin group')
     admin_perm.groups.append(second_admin_group)
     admin = User.example(groups=[second_admin_group])
     DBSession.commit()
     perm = MediaDropPermissionSystem.permissions_for_user(admin, config)
     assert_true(perm.contains_permission(u'admin'))
     assert_false(perm.contains_permission(u'edit'))
     return admin
开发者ID:knyar,项目名称:mediadrop,代码行数:10,代码来源:login_test.py

示例12: add_default_data

def add_default_data():
    log.info('Adding default data')

    settings = [
        (u'email_media_uploaded', None),
        (u'email_comment_posted', None),
        (u'email_support_requests', None),
        (u'email_send_from', u'[email protected]'),
        (u'wording_user_uploads', N_(u"Upload your media using the form below. We'll review it and get back to you.")),
        (u'wording_administrative_notes', None),
        (u'wording_display_administrative_notes', u''),
        (u'popularity_decay_exponent', u'4'),
        (u'popularity_decay_lifetime', u'36'),
        (u'rich_text_editor', u'tinymce'),
        (u'google_analytics_uacct', u''),
        (u'featured_category', u'1'),
        (u'max_upload_size', u'314572800'),
        (u'ftp_storage', u'false'),
        (u'ftp_server', u'ftp.someserver.com'),
        (u'ftp_user', u'username'),
        (u'ftp_password', u'password'),
        (u'ftp_upload_directory', u'media'),
        (u'ftp_download_url', u'http://www.someserver.com/web/accessible/media/'),
        (u'ftp_upload_integrity_retries', u'10'),
        (u'akismet_key', u''),
        (u'akismet_url', u''),
        (u'req_comment_approval', u''),
        (u'use_embed_thumbnails', u'true'),
        (u'api_secret_key_required', u'true'),
        (u'api_secret_key', random_string(20)),
        (u'api_media_max_results', u'50'),
        (u'api_tree_max_depth', u'10'),
        (u'general_site_name', u'MediaDrop'),
        (u'general_site_title_display_order', u'prepend'),
        (u'sitemaps_display', u'True'),
        (u'rss_display', u'True'),
        (u'vulgarity_filtered_words', u''),
        (u'primary_language', u'en'),
        (u'advertising_banner_html', u''),
        (u'advertising_sidebar_html', u''),
        (u'comments_engine', u'builtin'),
        (u'facebook_appid', u''),
        (u'youtube_apikey', u''),
    ]
    settings.extend(appearance_settings)

    for key, value in settings:
        s = Setting()
        s.key = key
        s.value = value
        DBSession.add(s)

    admin_user = User()
    admin_user.user_name = u'admin'
    admin_user.display_name = u'Admin'
    admin_user.email_address = u'[email protected]'
    admin_user.password = u'admin'
    DBSession.add(admin_user)

    admin_group = Group(name=u'admins', display_name=u'Admins')
    admin_group.users.append(admin_user)
    DBSession.add(admin_group)

    editor_group = Group(name=u'editors', display_name=u'Editors')
    DBSession.add(editor_group)

    anonymous_group = Group(name=u'anonymous', display_name=u'Everyone (including guests)')
    DBSession.add(anonymous_group)

    authenticated_group = Group(name=u'authenticated', display_name=u'Logged in users')
    DBSession.add(authenticated_group)

    admin_perm = Permission(name=u'admin', groups=[admin_group], 
        description=u'Grants access to the admin panel')
    DBSession.add(admin_perm)

    edit_perm = Permission(name=u'edit', groups=[admin_group, editor_group], 
        description=u'Grants access to edit site content')
    DBSession.add(edit_perm)
    
    view_perm = Permission(name=u'view', 
        groups=[admin_group, anonymous_group, editor_group], 
        description=u'View published media')
    DBSession.add(view_perm)

    upload_perm = Permission(name=u'upload', 
        groups=[admin_group, anonymous_group, editor_group], 
        description=u'Can upload new media')
    DBSession.add(upload_perm)
    media_upload_perm = Permission()
    media_upload_perm.permission_name = u'MEDIA_UPLOAD'
    media_upload_perm.description = u'Grants the ability to upload new media'
    media_upload_perm.groups.append(admin_group)
    media_upload_perm.groups.append(editor_group)
    media_upload_perm.groups.append(anonymous_group)
    DBSession.add(edit_perm)


    category = Category(name=u'Featured', slug=u'featured')
    DBSession.add(category)
#.........这里部分代码省略.........
开发者ID:mkrysiak,项目名称:mediadrop,代码行数:101,代码来源:websetup.py

示例13: _create_user_with_edit_permission_only

 def _create_user_with_edit_permission_only(self):
     editor = User.example(groups=[self.editor_group()])
     perm = MediaDropPermissionSystem.permissions_for_user(editor, config)
     assert_true(perm.contains_permission(u'edit'))
     assert_false(perm.contains_permission(u'admin'))
     return editor
开发者ID:knyar,项目名称:mediadrop,代码行数:6,代码来源:login_test.py

示例14: comment

    def comment(self, slug, body='', **kwargs):
        """Post a comment from :class:`~mediadrop.forms.comments.PostCommentForm`.

        :param slug: The media :attr:`~mediadrop.model.media.Media.slug`
        :returns: Redirect to :meth:`view` page for media.

        """
        def result(success, message=None, comment=None):
            if request.is_xhr:
                result = dict(success=success, message=message)
                if comment:
                    result['comment'] = render('comments/_list.html',
                        {'comment_to_render': comment},
                        method='xhtml')
                return result
            elif success:
                return redirect(action='view')
            else:
                return self.view(slug, name=name, email=email, body=body,
                                 **kwargs)

        if request.settings['comments_engine'] != 'builtin':
            abort(404)
        akismet_key = request.settings['akismet_key']
        if akismet_key:
            akismet = Akismet(agent=USER_AGENT)
            akismet.key = akismet_key
            akismet.blog_url = request.settings['akismet_url'] or \
                url_for('/', qualified=True)
            akismet.verify_key()
            data = {'comment_author': name.encode('utf-8'),
                    'user_ip': request.environ.get('REMOTE_ADDR'),
                    'user_agent': request.environ.get('HTTP_USER_AGENT', ''),
                    'referrer': request.environ.get('HTTP_REFERER',  'unknown'),
                    'HTTP_ACCEPT': request.environ.get('HTTP_ACCEPT')}

            if akismet.comment_check(body.encode('utf-8'), data):
                return result(False, _(u'Your comment has been rejected.'))

        media = fetch_row(Media, slug=slug)
        request.perm.assert_permission(u'view', media.resource)

        c = Comment()

        #name = filter_vulgarity(name)
        #c.author = AuthorWithIP(name, email, request.environ['REMOTE_ADDR'])
        user = User.by_user_name(request.environ['HTTP_REMOTE_USER'])
        c.author = AuthorWithIP(user.display_name, None, request.environ['REMOTE_ADDR'])
        c.subject = 'Re: %s' % media.title
        c.body = filter_vulgarity(body)

        require_review = request.settings['req_comment_approval']
        if not require_review:
            c.reviewed = True
            c.publishable = True

        media.comments.append(c)
        DBSession.flush()
        send_comment_notification(media, c)

        if require_review:
            message = _('Thank you for your comment! We will post it just as '
                        'soon as a moderator approves it.')
            return result(True, message=message)
        else:
            return result(True, comment=c)
开发者ID:mkrysiak,项目名称:mediadrop,代码行数:66,代码来源:media.py

示例15: test_can_override_example_data

 def test_can_override_example_data(self):
     user = User.example(display_name=u'Bar Foo')
     
     assert_equals(u'Bar Foo', user.display_name)
开发者ID:SmallsLIVE,项目名称:mediadrop,代码行数:4,代码来源:user_example_test.py


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