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


Python UserAttribute.get_user_attribute方法代码示例

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


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

示例1: test_command_by_activation_keys

# 需要导入模块: from student.models import UserAttribute [as 别名]
# 或者: from student.models.UserAttribute import get_user_attribute [as 别名]
    def test_command_by_activation_keys(self):
        """
        Test population of created_on_site attribute by activation keys.
        """
        call_command(
            "populate_created_on_site_user_attribute",
            "--activation-keys", self.activation_keys,
            "--site-domain", self.site.domain
        )

        for register_user in self.registered_users:
            self.assertEqual(UserAttribute.get_user_attribute(register_user.user, CREATED_ON_SITE), self.site.domain)

        # Populate 'created_on_site' attribute with different site domain
        call_command(
            "populate_created_on_site_user_attribute",
            "--activation-keys", self.activation_keys,
            "--site-domain", self.site_other.domain
        )

        for register_user in self.registered_users:
            # 'created_on_site' attribute already exists. Attribute's value will not change
            self.assertNotEqual(
                UserAttribute.get_user_attribute(register_user.user, CREATED_ON_SITE),
                self.site_other.domain
            )
开发者ID:AlexxNica,项目名称:edx-platform,代码行数:28,代码来源:test_populate_created_on_site_user_attribute.py

示例2: test_get_set_attribute

# 需要导入模块: from student.models import UserAttribute [as 别名]
# 或者: from student.models.UserAttribute import get_user_attribute [as 别名]
 def test_get_set_attribute(self):
     self.assertIsNone(UserAttribute.get_user_attribute(self.user, self.name))
     UserAttribute.set_user_attribute(self.user, self.name, self.value)
     self.assertEqual(UserAttribute.get_user_attribute(self.user, self.name), self.value)
     new_value = 'new_value'
     UserAttribute.set_user_attribute(self.user, self.name, new_value)
     self.assertEqual(UserAttribute.get_user_attribute(self.user, self.name), new_value)
开发者ID:Stanford-Online,项目名称:edx-platform,代码行数:9,代码来源:tests.py

示例3: handle

# 需要导入模块: from student.models import UserAttribute [as 别名]
# 或者: from student.models.UserAttribute import get_user_attribute [as 别名]
    def handle(self, *args, **options):
        site_domain = options['site_domain']
        user_ids = options['users'].split(',') if options['users'] else []
        activation_keys = options['activation_keys'].split(',') if options['activation_keys'] else []

        if not user_ids and not activation_keys:
            raise CommandError('You must provide user ids or activation keys.')

        try:
            Site.objects.get(domain__exact=site_domain)
        except Site.DoesNotExist:
            question = "The site you specified is not configured as a Site in the system. " \
                       "Are you sure you want to continue? (y/n):"
            if str(raw_input(question)).lower().strip()[0] != 'y':
                return

        for user_id in user_ids:
            try:
                user = User.objects.get(id=user_id)
                if UserAttribute.get_user_attribute(user, CREATED_ON_SITE):
                    self.stdout.write("created_on_site attribute already exists for user id: {id}".format(id=user_id))
                else:
                    UserAttribute.set_user_attribute(user, CREATED_ON_SITE, site_domain)
            except User.DoesNotExist:
                self.stdout.write("This user id [{id}] does not exist in the system.".format(id=user_id))

        for key in activation_keys:
            try:
                user = Registration.objects.get(activation_key=key).user
                if UserAttribute.get_user_attribute(user, CREATED_ON_SITE):
                    self.stdout.write("created_on_site attribute already exists for user id: {id}".format(id=user.id))
                else:
                    UserAttribute.set_user_attribute(user, CREATED_ON_SITE, site_domain)
            except Registration.DoesNotExist:
                self.stdout.write("This activation key [{key}] does not exist in the system.".format(key=key))
开发者ID:AlexxNica,项目名称:edx-platform,代码行数:37,代码来源:populate_created_on_site_user_attribute.py

示例4: _get_unsynced_users

# 需要导入模块: from student.models import UserAttribute [as 别名]
# 或者: from student.models.UserAttribute import get_user_attribute [as 别名]
    def _get_unsynced_users(self, site_domain, last_synced_user, days_threshold):
        """
        Args:
            site_domain: site where we need unsynced users
            last_synced_user: last synced user
            days_threshold: number of days threshold to sync users in case we don't have last synced user

        Returns: Ordered list of users needs to be synced

        """
        if last_synced_user:
            users = User.objects.select_related('profile').filter(id__gt=last_synced_user.id).order_by('pk')
        else:
            # If we don't have last synced user get all users who joined on between today and threshold days ago
            start_date = datetime.now().date() - timedelta(days_threshold)
            self.stdout.write(
                'Started pulling unsynced contacts for site {site} from {start_date}'.format(
                    site=site_domain, start_date=start_date
                )
            )
            users = User.objects.select_related('profile').filter(date_joined__date__gte=start_date).order_by('pk')

        unsynced_users = [
            user for user in use_read_replica_if_available(users)
            if UserAttribute.get_user_attribute(user, 'created_on_site') == site_domain
        ]
        return unsynced_users
开发者ID:jolyonb,项目名称:edx-platform,代码行数:29,代码来源:sync_hubspot_contacts.py

示例5: test_with_invalid_site_domain

# 需要导入模块: from student.models import UserAttribute [as 别名]
# 或者: from student.models.UserAttribute import get_user_attribute [as 别名]
    def test_with_invalid_site_domain(self, populate):
        """
        Test management command with invalid site domain.
        """
        fake_site_domain = 'fake-site-domain'
        with mock.patch('__builtin__.raw_input', return_value=populate):
            call_command(
                "populate_created_on_site_user_attribute",
                "--users", self.user_ids,
                "--site-domain", fake_site_domain
            )

        for user in self.users:
            if populate == 'y':
                self.assertEqual(UserAttribute.get_user_attribute(user, CREATED_ON_SITE), fake_site_domain)
            else:
                self.assertIsNone(UserAttribute.get_user_attribute(user, CREATED_ON_SITE))
开发者ID:AlexxNica,项目名称:edx-platform,代码行数:19,代码来源:test_populate_created_on_site_user_attribute.py

示例6: test_affiliate_referral_attribution

# 需要导入模块: from student.models import UserAttribute [as 别名]
# 或者: from student.models.UserAttribute import get_user_attribute [as 别名]
 def test_affiliate_referral_attribution(self):
     """
     Verify that a referral attribution is recorded if an affiliate
     cookie is present upon a new user's registration.
     """
     affiliate_id = 'test-partner'
     self.client.cookies[settings.AFFILIATE_COOKIE_NAME] = affiliate_id
     user = self.create_account_and_fetch_profile().user
     self.assertEqual(UserAttribute.get_user_attribute(user, REGISTRATION_AFFILIATE_ID), affiliate_id)
开发者ID:edx,项目名称:edx-platform,代码行数:11,代码来源:test_register.py

示例7: test_command_with_invalid_arguments

# 需要导入模块: from student.models import UserAttribute [as 别名]
# 或者: from student.models.UserAttribute import get_user_attribute [as 别名]
    def test_command_with_invalid_arguments(self):
        """
        Test management command with invalid user ids and activation keys.
        """
        user = self.users[0]
        call_command(
            "populate_created_on_site_user_attribute",
            "--users", '9{id}'.format(id=user.id),  # invalid id
            "--site-domain", self.site.domain
        )
        self.assertIsNone(UserAttribute.get_user_attribute(user, CREATED_ON_SITE))

        register_user = self.registered_users[0]
        call_command(
            "populate_created_on_site_user_attribute",
            "--activation-keys", "invalid-{key}".format(key=register_user.activation_key),  # invalid key
            "--site-domain", self.site.domain
        )
        self.assertIsNone(UserAttribute.get_user_attribute(register_user.user, CREATED_ON_SITE))
开发者ID:AlexxNica,项目名称:edx-platform,代码行数:21,代码来源:test_populate_created_on_site_user_attribute.py

示例8: test_no_referral

# 需要导入模块: from student.models import UserAttribute [as 别名]
# 或者: from student.models.UserAttribute import get_user_attribute [as 别名]
    def test_no_referral(self):
        """Verify that no referral is recorded when a cookie is not present."""
        utm_cookie_name = 'edx.test.utm'
        with mock.patch('student.models.RegistrationCookieConfiguration.current') as config:
            instance = config.return_value
            instance.utm_cookie_name = utm_cookie_name

            self.assertIsNone(self.client.cookies.get(settings.AFFILIATE_COOKIE_NAME))
            self.assertIsNone(self.client.cookies.get(utm_cookie_name))
            user = self.create_account_and_fetch_profile().user
            self.assertIsNone(UserAttribute.get_user_attribute(user, REGISTRATION_AFFILIATE_ID))
            self.assertIsNone(UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_source')))
            self.assertIsNone(UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_medium')))
            self.assertIsNone(UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_campaign')))
            self.assertIsNone(UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_term')))
            self.assertIsNone(UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_content')))
            self.assertIsNone(UserAttribute.get_user_attribute(user, REGISTRATION_UTM_CREATED_AT))
开发者ID:edx,项目名称:edx-platform,代码行数:19,代码来源:test_register.py

示例9: test_utm_referral_attribution

# 需要导入模块: from student.models import UserAttribute [as 别名]
# 或者: from student.models.UserAttribute import get_user_attribute [as 别名]
    def test_utm_referral_attribution(self):
        """
        Verify that a referral attribution is recorded if an affiliate
        cookie is present upon a new user's registration.
        """
        utm_cookie_name = 'edx.test.utm'
        with mock.patch('student.models.RegistrationCookieConfiguration.current') as config:
            instance = config.return_value
            instance.utm_cookie_name = utm_cookie_name

            timestamp = 1475521816879
            utm_cookie = {
                'utm_source': 'test-source',
                'utm_medium': 'test-medium',
                'utm_campaign': 'test-campaign',
                'utm_term': 'test-term',
                'utm_content': 'test-content',
                'created_at': timestamp
            }

            created_at = datetime.fromtimestamp(timestamp / float(1000), tz=pytz.UTC)

            self.client.cookies[utm_cookie_name] = json.dumps(utm_cookie)
            user = self.create_account_and_fetch_profile().user
            self.assertEqual(
                UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_source')),
                utm_cookie.get('utm_source')
            )
            self.assertEqual(
                UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_medium')),
                utm_cookie.get('utm_medium')
            )
            self.assertEqual(
                UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_campaign')),
                utm_cookie.get('utm_campaign')
            )
            self.assertEqual(
                UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_term')),
                utm_cookie.get('utm_term')
            )
            self.assertEqual(
                UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_content')),
                utm_cookie.get('utm_content')
            )
            self.assertEqual(
                UserAttribute.get_user_attribute(user, REGISTRATION_UTM_CREATED_AT),
                str(created_at)
            )
开发者ID:edx,项目名称:edx-platform,代码行数:50,代码来源:test_register.py

示例10: _get_batched_users

# 需要导入模块: from student.models import UserAttribute [as 别名]
# 或者: from student.models.UserAttribute import get_user_attribute [as 别名]
    def _get_batched_users(self, site_domain, users_queryset, offset, users_query_batch_size):
        """
        Args:
            site_domain: site where we need unsynced users
            users_queryset: users_queryset to slice
            users_query_batch_size: slice size

        Returns: site users

        """

        self.stdout.write(
            u'Fetching Users for site {site} from {start} to {end}'.format(
                site=site_domain, start=offset, end=offset + users_query_batch_size
            )
        )
        users = users_queryset.select_related('profile')[offset: offset + users_query_batch_size]
        site_users = [
            user for user in users
            if UserAttribute.get_user_attribute(user, 'created_on_site') == site_domain
        ]
        self.stdout.write(u'\tSite Users={count}'.format(count=len(site_users)))

        return site_users
开发者ID:edx,项目名称:edx-platform,代码行数:26,代码来源:sync_hubspot_contacts.py

示例11: test_incomplete_utm_referral

# 需要导入模块: from student.models import UserAttribute [as 别名]
# 或者: from student.models.UserAttribute import get_user_attribute [as 别名]
    def test_incomplete_utm_referral(self):
        """Verify that no referral is recorded when a cookie is not present."""
        utm_cookie_name = 'edx.test.utm'
        with mock.patch('student.models.RegistrationCookieConfiguration.current') as config:
            instance = config.return_value
            instance.utm_cookie_name = utm_cookie_name

            utm_cookie = {
                'utm_source': 'test-source',
                'utm_medium': 'test-medium',
                # No campaign
                'utm_term': 'test-term',
                'utm_content': 'test-content',
                # No created at
            }

            self.client.cookies[utm_cookie_name] = json.dumps(utm_cookie)
            user = self.create_account_and_fetch_profile().user

            self.assertEqual(
                UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_source')),
                utm_cookie.get('utm_source')
            )
            self.assertEqual(
                UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_medium')),
                utm_cookie.get('utm_medium')
            )
            self.assertEqual(
                UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_term')),
                utm_cookie.get('utm_term')
            )
            self.assertEqual(
                UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_content')),
                utm_cookie.get('utm_content')
            )
            self.assertIsNone(
                UserAttribute.get_user_attribute(user, REGISTRATION_UTM_PARAMETERS.get('utm_campaign'))
            )
            self.assertIsNone(
                UserAttribute.get_user_attribute(user, REGISTRATION_UTM_CREATED_AT)
            )
开发者ID:edx,项目名称:edx-platform,代码行数:43,代码来源:test_register.py

示例12: test_created_on_site_user_attribute_set

# 需要导入模块: from student.models import UserAttribute [as 别名]
# 或者: from student.models.UserAttribute import get_user_attribute [as 别名]
 def test_created_on_site_user_attribute_set(self):
     profile = self.create_account_and_fetch_profile(host=self.site.domain)
     self.assertEqual(UserAttribute.get_user_attribute(profile.user, 'created_on_site'), self.site.domain)
开发者ID:edx,项目名称:edx-platform,代码行数:5,代码来源:test_register.py

示例13: test_no_referral

# 需要导入模块: from student.models import UserAttribute [as 别名]
# 或者: from student.models.UserAttribute import get_user_attribute [as 别名]
 def test_no_referral(self):
     """Verify that no referral is recorded when a cookie is not present."""
     self.assertIsNone(self.client.cookies.get(settings.AFFILIATE_COOKIE_NAME))  # pylint: disable=no-member
     user = self.create_account_and_fetch_profile().user
     self.assertIsNone(UserAttribute.get_user_attribute(user, REGISTRATION_AFFILIATE_ID))
开发者ID:tanmaykm,项目名称:edx-platform,代码行数:7,代码来源:test_create_account.py


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