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


Python models.Site方法代码示例

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


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

示例1: test_get

# 需要导入模块: from django.contrib.sites import models [as 别名]
# 或者: from django.contrib.sites.models import Site [as 别名]
def test_get(self, query_params, filter_args):
        qp_msg = 'query_params={query_params}'
        expected_data = Site.objects.filter(**filter_args)
        request = APIRequestFactory().get(self.request_path + query_params)
        request.user = self.staff_user
        view = self.view_class.as_view({'get': 'list'})
        response = view(request)
        assert response.status_code == 200, qp_msg.format(query_params=query_params)
        assert set(response.data.keys()) == set(
            ['count', 'next', 'previous', 'results'])
        assert len(response.data['results']) == len(expected_data), qp_msg.format(
            query_params=query_params)
        results = response.data['results']

        # Validate just the first object's structure
        for field_name in self.expected_result_keys:
            assert field_name in results[0]

        # Validate the ids match up
        expected_ids = expected_data.values_list('id', flat=True)
        actual_ids = [o['id'] for o in results]
        assert set(actual_ids) == set(expected_ids) 
开发者ID:appsembler,项目名称:figures,代码行数:24,代码来源:test_sites_view.py

示例2: populate_course_mau

# 需要导入模块: from django.contrib.sites import models [as 别名]
# 或者: from django.contrib.sites.models import Site [as 别名]
def populate_course_mau(site_id, course_id, month_for=None, force_update=False):
    """Populates the MAU for the given site, course, and month
    """
    if month_for:
        month_for = as_date(month_for)
    else:
        month_for = datetime.datetime.utcnow().date()
    site = Site.objects.get(id=site_id)
    start_time = time.time()
    obj, _created = collect_course_mau(site=site,
                                       courselike=course_id,
                                       month_for=month_for,
                                       overwrite=force_update)
    if not obj:
        msg = 'populate_course_mau failed for course {course_id}'.format(
            course_id=str(course_id))
        logger.error(msg)
    elapsed_time = time.time() - start_time
    logger.info('populate_course_mau Elapsed time (seconds)={}. cdm_obj={}'.format(
        elapsed_time, obj)) 
开发者ID:appsembler,项目名称:figures,代码行数:22,代码来源:tasks.py

示例3: setUp

# 需要导入模块: from django.contrib.sites import models [as 别名]
# 或者: from django.contrib.sites.models import Site [as 别名]
def setUp(self):
        Site.objects.get_or_create(id=settings.SITE_ID, domain='example.com', name='example.com')
        self.obj = get_usersettings_model().objects.create(**self.usersettings_data)
        self.user = get_user_model().objects.create_superuser(
            self.username, self.email, self.password)

        self.assertTrue(self.client.login(
            username=self.username, password=self.password),
            'Failed to login user %s' % self.email)

        factory = RequestFactory()
        request = factory.get('/admin')
        request.user = self.user
        request.session = {}

        self.request = request
        self.settings_admin = SettingsAdmin(get_usersettings_model(), AdminSite())

        # Hack to test this function as it calls 'messages.add'
        # See https://code.djangoproject.com/ticket/17971
        setattr(self.request, 'session', 'session')
        messages = FallbackStorage(self.request)
        setattr(self.request, '_messages', messages) 
开发者ID:mishbahr,项目名称:django-usersettings2,代码行数:25,代码来源:test_admin.py

示例4: _pre_setup

# 需要导入模块: from django.contrib.sites import models [as 别名]
# 或者: from django.contrib.sites.models import Site [as 别名]
def _pre_setup(self):
        """Disable transaction methods, and clear some globals."""
        # Repeat stuff from TransactionTestCase, because I'm not calling its
        # _pre_setup, because that would load fixtures again.
        cache.cache.clear()
        settings.TEMPLATE_DEBUG = settings.DEBUG = False


        self.client = self.client_class()
        #self._fixture_setup()
        self._urlconf_setup()
        mail.outbox = []

        # Clear site cache in case somebody's mutated Site objects and then
        # cached the mutated stuff:
        from django.contrib.sites.models import Site
        Site.objects.clear_cache() 
开发者ID:sfu-fas,项目名称:coursys,代码行数:19,代码来源:testcase.py

示例5: test_sites

# 需要导入模块: from django.contrib.sites import models [as 别名]
# 或者: from django.contrib.sites.models import Site [as 别名]
def test_sites(self):
        """ Tests the django.contrib.sites support.
            A separate metadata definition is used, WithSites, which has turned on sites support.
        """
        path = "/abc/"
        site = Site.objects.get_current()
        path_metadata = WithSites._meta.get_model('path').objects.create(_site=site, title="Site Path title",
                                                                         _path=path)
        self.assertEqual(seo_get_metadata(path, name="WithSites").title.value, 'Site Path title')
        # Metadata with site=null should work
        path_metadata._site_id = None
        path_metadata.save()
        self.assertEqual(seo_get_metadata(path, name="WithSites").title.value, 'Site Path title')
        # Metadata with an explicitly wrong site should not work
        path_metadata._site_id = site.id + 1
        path_metadata.save()
        self.assertEqual(seo_get_metadata(path, name="WithSites").title.value, None) 
开发者ID:whyflyru,项目名称:django-seo,代码行数:19,代码来源:tests.py

示例6: handle

# 需要导入模块: from django.contrib.sites import models [as 别名]
# 或者: from django.contrib.sites.models import Site [as 别名]
def handle(self, *args, **options):

        if Account.objects.count() == 0:
            # If there are no Accounts, we can assume this is a new Env
            # create a super user
            self._create_super_users()

        if SocialApp.objects.count() == 0:
            # Also fixup  the Site info
            site = Site.objects.get_current()
            site.domain_name = getattr(settings, 'DOMAIN_NAME')
            site.display_name = getattr(settings, 'COMPANY_NAME')
            site.save()
            if not getattr(settings, 'PRODUCTION'):
                self._create_social_accounts(site)

        else:
            print('Admin accounts can only be initialized if no Accounts exist') 
开发者ID:dkarchmer,项目名称:django-aws-template,代码行数:20,代码来源:init-basic-data.py

示例7: about_view

# 需要导入模块: from django.contrib.sites import models [as 别名]
# 或者: from django.contrib.sites.models import Site [as 别名]
def about_view(request):
    g = hszinc.Grid()
    g.column['vendorUri'] = {}
    g.column['productUri'] = {}
    g.column['tz'] = {}
    g.column['serverName'] = {}
    g.column['productName'] = {}
    g.column['haystackVersion'] = {}
    g.column['productVersion'] = {}
    g.column['serverTime'] = {}
    g.column['serverBootTime'] = {}
    g.column['vendorName'] = {}
    g.extend([{
        'vendorUri': 'https://www.opensourcestrategies.com',
        'productUri': 'https://www.opensourcestrategies.com',
        'tz': timezone.get_default_timezone_name(),
        'serverName': Site.objects.get_current().domain,
        'productName': 'Opentaps-SEAS Haystack',
        'haystackVersion': '2.0',
        'productVersion': '1.0',
        'serverTime': timezone.now(),
        'vendorName': 'Opentaps-SEAS Haystack'
    }])
    return _hzinc_response(g) 
开发者ID:opentaps,项目名称:opentaps_seas,代码行数:26,代码来源:views.py

示例8: _check_site_configuration

# 需要导入模块: from django.contrib.sites import models [as 别名]
# 或者: from django.contrib.sites.models import Site [as 别名]
def _check_site_configuration(self, site_configuration):
        """
        Helper method for verifying that the Site is properly configured.

        Args:
            site_configuration (SiteConfiguration): SiteConfiguration that's being verified.
        """
        self.assertEqual(site_configuration.lms_url_root, self.site_configuration.lms_url_root)
        self.assertEqual(site_configuration.platform_name, self.site_configuration.platform_name)
        self.assertEqual(site_configuration.catalog_api_url, self.site_configuration.catalog_api_url)
        self.assertEqual(site_configuration.tos_url, self.site_configuration.tos_url)
        self.assertEqual(site_configuration.privacy_policy_url, self.site_configuration.privacy_policy_url)
        self.assertEqual(site_configuration.homepage_url, self.site_configuration.homepage_url)
        self.assertEqual(site_configuration.company_name, self.site_configuration.company_name)
        self.assertEqual(site_configuration.certificate_help_url, self.site_configuration.certificate_help_url)
        self.assertEqual(site_configuration.records_help_url, self.site_configuration.records_help_url)
        self.assertEqual(site_configuration.twitter_username, self.site_configuration.twitter_username)
        self.assertEqual(site_configuration.facebook_app_id, self.site_configuration.facebook_app_id)
        self.assertEqual(site_configuration.segment_key, self.site_configuration.segment_key)
        self.assertEqual(site_configuration.theme_name, self.site_configuration.theme_name)

        # Social sharing is disabled by default, if the flag is not passed
        self.assertFalse(site_configuration.enable_linkedin_sharing)
        self.assertFalse(site_configuration.enable_twitter_sharing)
        self.assertFalse(site_configuration.enable_facebook_sharing) 
开发者ID:edx,项目名称:credentials,代码行数:27,代码来源:test_commands.py

示例9: test_update_site

# 需要导入模块: from django.contrib.sites import models [as 别名]
# 或者: from django.contrib.sites.models import Site [as 别名]
def test_update_site(self):
        """ Verify the command updates Site and SiteConfiguration. """
        expected_site_domain = self.faker.domain_name()
        expected_site_name = 'Fake Credentials Server'
        site = SiteFactory()

        self._call_command(
            site_id=site.id,
            site_domain=expected_site_domain,
            site_name=expected_site_name
        )

        site.refresh_from_db()

        self.assertEqual(site.domain, expected_site_domain)
        self.assertEqual(site.name, expected_site_name)
        self._check_site_configuration(site.siteconfiguration) 
开发者ID:edx,项目名称:credentials,代码行数:19,代码来源:test_commands.py

示例10: get_payment_processors

# 需要导入模块: from django.contrib.sites import models [as 别名]
# 或者: from django.contrib.sites.models import Site [as 别名]
def get_payment_processors(self):
        """
        Returns payment processor classes enabled for the corresponding Site

        Returns:
            list[BasePaymentProcessor]: Returns payment processor classes enabled for the corresponding Site
        """
        all_processors = self._all_payment_processors()
        all_processor_names = {processor.NAME for processor in all_processors}

        missing_processor_configurations = self.payment_processors_set - all_processor_names
        if missing_processor_configurations:
            processor_config_repr = ", ".join(missing_processor_configurations)
            log.warning(
                'Unknown payment processors [%s] are configured for site %s', processor_config_repr, self.site.id
            )

        return [
            processor for processor in all_processors
            if processor.NAME in self.payment_processors_set and processor.is_enabled()
        ] 
开发者ID:edx,项目名称:ecommerce,代码行数:23,代码来源:models.py

示例11: handle

# 需要导入模块: from django.contrib.sites import models [as 别名]
# 或者: from django.contrib.sites.models import Site [as 别名]
def handle(self, *args, **options):
        site_id = options.get('site_id')
        sso_client_id = options.get('sso_client_id')
        sso_client_secret = options.get('sso_client_secret')
        backend_service_client_id = options.get('backend_service_client_id')
        backend_service_client_secret = options.get('backend_service_client_secret')

        site = Site.objects.get(id=site_id)
        site_configuration = SiteConfiguration.objects.get(site=site)
        oauth_settings = site_configuration.oauth_settings
        lms_url_root = site_configuration.lms_url_root

        oauth_settings.update({
            'SOCIAL_AUTH_EDX_OAUTH2_URL_ROOT': lms_url_root,
            'SOCIAL_AUTH_EDX_OAUTH2_LOGOUT_URL': '{lms_url_root}/logout'.format(lms_url_root=lms_url_root),
            'SOCIAL_AUTH_EDX_OAUTH2_ISSUERS': [lms_url_root],
            'SOCIAL_AUTH_EDX_OAUTH2_KEY': sso_client_id,
            'SOCIAL_AUTH_EDX_OAUTH2_SECRET': sso_client_secret,
            'BACKEND_SERVICE_EDX_OAUTH2_KEY': backend_service_client_id,
            'BACKEND_SERVICE_EDX_OAUTH2_SECRET': backend_service_client_secret,
        })

        site_configuration.save() 
开发者ID:edx,项目名称:ecommerce,代码行数:25,代码来源:update_site_oauth_settings.py

示例12: get_theme

# 需要导入模块: from django.contrib.sites import models [as 别名]
# 或者: from django.contrib.sites.models import Site [as 别名]
def get_theme(site):
        """
        Get SiteTheme object for given site, returns default site theme if it can not
        find a theme for the given site and `DEFAULT_SITE_THEME` setting has a proper value.

        Args:
            site (django.contrib.sites.models.Site): site object related to the current site.

        Returns:
            SiteTheme object for given site or a default site set by `DEFAULT_SITE_THEME`
        """
        if not site:
            return None

        theme = site.themes.first()

        if (not theme) and settings.DEFAULT_SITE_THEME:
            theme = SiteTheme(site=site, theme_dir_name=settings.DEFAULT_SITE_THEME)

        return theme 
开发者ID:edx,项目名称:ecommerce,代码行数:22,代码来源:models.py

示例13: test_update_site

# 需要导入模块: from django.contrib.sites import models [as 别名]
# 或者: from django.contrib.sites.models import Site [as 别名]
def test_update_site(self):
        """
        Test that site is updated properly if site-id belongs to an existing site.
        """
        # Create a site to update
        site = Site.objects.create(domain="test.localhost", name="Test Site")
        call_command(
            "create_or_update_site_theme",
            "--site-id={}".format(site.id),
            "--site-name=updated name",
            "--site-domain=test.localhost",
            '--site-theme=test',
        )

        # Verify updated site name
        site = Site.objects.get(id=site.id)
        self.assertEqual(site.name, "updated name") 
开发者ID:edx,项目名称:ecommerce,代码行数:19,代码来源:test_create_or_update_site_theme.py

示例14: test_update_site_theme

# 需要导入模块: from django.contrib.sites import models [as 别名]
# 或者: from django.contrib.sites.models import Site [as 别名]
def test_update_site_theme(self):
        """
        Test that site theme is updated properly when site and site theme already exist.
        """
        # Create a site and site theme to update
        site = Site.objects.create(domain="test.localhost", name="Test Site")
        site_theme = SiteTheme.objects.create(site=site, theme_dir_name="site_theme_1")

        call_command(
            "create_or_update_site_theme",
            "--site-domain=test.localhost",
            '--site-theme=site_theme_2',
        )

        # Verify updated site name
        site_theme = SiteTheme.objects.get(id=site_theme.id)
        self.assertEqual(site_theme.theme_dir_name, "site_theme_2") 
开发者ID:edx,项目名称:ecommerce,代码行数:19,代码来源:test_create_or_update_site_theme.py

示例15: handle

# 需要导入模块: from django.contrib.sites import models [as 别名]
# 或者: from django.contrib.sites.models import Site [as 别名]
def handle(self, *args, **options):
        if options['devstack']:
            configuration_prefix = 'devstack'
        else:
            configuration_prefix = 'sandbox'

        self.configuration_filename = '{}_configuration.json'.format(configuration_prefix)
        self.dns_name = options['dns_name']
        self.theme_path = options['theme_path']

        logger.info("Using %s configuration...", configuration_prefix)
        logger.info('DNS name: %s', self.dns_name)
        logger.info('Theme path: %s', self.theme_path)

        all_sites = self._get_site_partner_data()
        for site_name, site_data in all_sites.items():
            logger.info('Creating %s Site', site_name)
            self._create_sites(
                site_data['site_domain'],
                site_data['theme_dir_name'],
                site_data['configuration'],
                site_data['partner_code'],
                options['demo_course']
            ) 
开发者ID:edx,项目名称:ecommerce,代码行数:26,代码来源:create_sites_and_partners.py


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