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


Python settings.SITE_ID属性代码示例

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


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

示例1: get_current

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SITE_ID [as 别名]
def get_current(self):
        """
        Returns the current ``UserSettings`` based on the SITE_ID in the
        project's settings. The ``UserSettings`` object is cached the first
        time it's retrieved from the database.
        """
        from django.conf import settings
        try:
            site_id = settings.SITE_ID
        except AttributeError:
            raise ImproperlyConfigured(
                'You\'re using the Django "sites framework" without having '
                'set the SITE_ID setting. Create a site in your database and '
                'set the SITE_ID setting to fix this error.')

        try:
            current_usersettings = USERSETTINGS_CACHE[site_id]
        except KeyError:
            current_usersettings = self.get(site_id=site_id)
            USERSETTINGS_CACHE[site_id] = current_usersettings
        return current_usersettings 
开发者ID:mishbahr,项目名称:django-usersettings2,代码行数:23,代码来源:models.py

示例2: render

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SITE_ID [as 别名]
def render(self, context):
        if 'request' in context:
            site_pk = get_current_site(context['request']).pk
        else:
            site_pk = settings.SITE_ID
        flatpages = FlatPage.objects.filter(sites__id=site_pk)
        # If a prefix was specified, add a filter
        if self.starts_with:
            flatpages = flatpages.filter(
                url__startswith=self.starts_with.resolve(context))

        # If the provided user is not authenticated, or no user
        # was provided, filter the list to only public flatpages.
        if self.user:
            user = self.user.resolve(context)
            if not user.is_authenticated():
                flatpages = flatpages.filter(registration_required=False)
        else:
            flatpages = flatpages.filter(registration_required=False)

        context[self.context_name] = flatpages
        return '' 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:24,代码来源:flatpages.py

示例3: get_current

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SITE_ID [as 别名]
def get_current(self, request=None):
        """
        Returns the current Site based on the SITE_ID in the project's settings.
        If SITE_ID isn't defined, it returns the site with domain matching
        request.get_host(). The ``Site`` object is cached the first time it's
        retrieved from the database.
        """
        from django.conf import settings
        if getattr(settings, 'SITE_ID', ''):
            site_id = settings.SITE_ID
            return self._get_site_by_id(site_id)
        elif request:
            return self._get_site_by_request(request)

        raise ImproperlyConfigured(
            "You're using the Django \"sites framework\" without having "
            "set the SITE_ID setting. Create a site in your database and "
            "set the SITE_ID setting or pass a request to "
            "Site.objects.get_current() to fix this error."
        ) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:22,代码来源:models.py

示例4: create_organization_object

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SITE_ID [as 别名]
def create_organization_object(org_name, creator, attrs={}):
    '''Creates an OrganizationProfile object without saving to the database'''
    name = attrs.get('name', org_name)
    first_name, last_name = _get_first_last_names(name)
    email = attrs.get('email', u'')
    new_user = User(username=org_name, first_name=first_name,
                    last_name=last_name, email=email, is_active=True)
    new_user.save()
    registration_profile = RegistrationProfile.objects.create_profile(new_user)
    if email:
        site = Site.objects.get(pk=settings.SITE_ID)
        registration_profile.send_activation_email(site)
    profile = OrganizationProfile(
        user=new_user, name=name, creator=creator,
        created_by=creator,
        city=attrs.get('city', u''),
        country=attrs.get('country', u''),
        organization=attrs.get('organization', u''),
        home_page=attrs.get('home_page', u''),
        twitter=attrs.get('twitter', u''))
    return profile 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:23,代码来源:tools.py

示例5: get_queryset

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SITE_ID [as 别名]
def get_queryset(self):
        """
        Return the first preferences object for the current site.
        If preferences do not exist create it.
        """
        queryset = super(SingletonManager, self).get_queryset()

        # Get current site
        current_site = None
        if getattr(settings, 'SITE_ID', None) is not None:
            current_site = Site.objects.get_current()

        # If site found limit queryset to site.
        if current_site is not None:
            queryset = queryset.filter(sites=settings.SITE_ID)

        try:
            queryset.get()
        except self.model.DoesNotExist:
            # Create object (for current site) if it doesn't exist.
            obj = self.model.objects.create()
            if current_site is not None:
                obj.sites.add(current_site)

        return queryset 
开发者ID:82Flex,项目名称:DCRM,代码行数:27,代码来源:managers.py

示例6: test_get_queryset

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SITE_ID [as 别名]
def test_get_queryset(self):
        # Should return preferences without sites.
        # Shouldn't fail on duplicates.
        self.failIf(MyPreferences.singleton.get().sites.all(), "Without \
                SITE_ID should not have any preferences with sites.")

        # Should return preferences for current site.
        # Shouldn't fail on duplicates.
        settings.SITE_ID = 1
        current_site = Site.objects.get_current()
        obj = MyPreferences.singleton.get()
        self.failUnlessEqual(current_site, obj.sites.get(), "With SITE_ID \
                should have preferences for current site.")

        # Should return preferences for current site.
        # Shouldn't fail on duplicates.
        settings.SITE_ID = 2
        second_site, created = Site.objects.get_or_create(id=2)
        obj = MyPreferences.singleton.get()
        self.failUnlessEqual(second_site, obj.sites.get(), "With SITE_ID \
                should have preferences for current site.") 
开发者ID:82Flex,项目名称:DCRM,代码行数:23,代码来源:test_all.py

示例7: render

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SITE_ID [as 别名]
def render(self, context):
        if 'request' in context:
            site_pk = get_current_site(context['request']).pk
        else:
            site_pk = settings.SITE_ID
        flatpages = FlatPage.objects.filter(sites__id=site_pk)
        # If a prefix was specified, add a filter
        if self.starts_with:
            flatpages = flatpages.filter(
                url__startswith=self.starts_with.resolve(context))

        # If the provided user is not authenticated, or no user
        # was provided, filter the list to only public flatpages.
        if self.user:
            user = self.user.resolve(context)
            if not user.is_authenticated:
                flatpages = flatpages.filter(registration_required=False)
        else:
            flatpages = flatpages.filter(registration_required=False)

        context[self.context_name] = flatpages
        return '' 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:24,代码来源:flatpages.py

示例8: get_form_kwargs

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SITE_ID [as 别名]
def get_form_kwargs(self):
        kwargs = super(SettingsView, self).get_form_kwargs()
        # We're getting the current site settings in such a way as to
        # avoid using any of the convenience methods that return the
        # cached current UserSettings object, since is_valid may
        # subsequently update the object we set here.  (is_valid
        # doesn't save it to the database, but because the cached
        # object is updated, it still means that the object returned
        # by those conveninence method, including the
        # self.request.usersettings attribute set by the middleware,
        # may not be in sync with the database any more.
        kwargs['instance'], _ = SiteSettings.objects.get_or_create(
            site_id=settings.SITE_ID,
            defaults={'user': self.request.user}
        )
        return kwargs 
开发者ID:mysociety,项目名称:yournextrepresentative,代码行数:18,代码来源:settings.py

示例9: sites

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SITE_ID [as 别名]
def sites(app_configs, **kwargs):
    if models.Site.objects.count() == 0:
        yield checks.Warning(
            "Site not configured",
            hint="Missing django site configuration",
            id="promgen.W006",
        )

    for site in models.Site.objects.filter(
        pk=settings.SITE_ID, domain__in=["example.com"]
    ):
        yield checks.Warning(
            "Promgen is configured to example domain",
            obj=site,
            hint="Please update from admin page /admin/",
            id="promgen.W007",
        )


# See notes in bootstrap.py
# @custom.register(checks.Tags.models) 
开发者ID:line,项目名称:promgen,代码行数:23,代码来源:checks.py

示例10: default_site

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SITE_ID [as 别名]
def default_site():
    """
    Wrapper aroung `django.conf.settings.SITE_ID` so we do not have to create a
    new migration if we change how we get the default site ID
    """
    return settings.SITE_ID 
开发者ID:appsembler,项目名称:figures,代码行数:8,代码来源:models.py

示例11: default_site

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SITE_ID [as 别名]
def default_site():
    """Returns the default site instance if Django settings defines SITE_ID, else None

    Tech debt note: Open edX monkeypatches django.contrib.sites to override
    behavior for getting the current site.
    """
    if getattr(settings, 'SITE_ID', ''):
        return Site.objects.get(pk=settings.SITE_ID)

    return None 
开发者ID:appsembler,项目名称:figures,代码行数:12,代码来源:sites.py

示例12: get_site_for_course

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SITE_ID [as 别名]
def get_site_for_course(course_id):
    """
    Given a course, return the related site or None

    For standalone mode, will always return the site
    For multisite mode, will return the site if there is a mapping between the
    course and the site. Otherwise `None` is returned

    # Implementation notes

    There should be only one organization per course.
    TODO: Figure out how we want to handle ``DoesNotExist``
    whether to let it raise back up raw or handle with a custom exception
    """
    if figures.helpers.is_multisite():
        org_courses = organizations.models.OrganizationCourse.objects.filter(
            course_id=str(course_id))
        if org_courses:
            # Keep until this assumption analyzed
            msg = 'Multiple orgs found for course: {}'
            assert org_courses.count() == 1, msg.format(course_id)
            first_org = org_courses.first().organization
            if hasattr(first_org, 'sites'):
                msg = 'Must have one and only one site. Org is "{}"'
                assert first_org.sites.count() == 1, msg.format(first_org.name)
                site = first_org.sites.first()
            else:
                site = None
        else:
            # We don't want to make assumptions of who our consumers are
            # TODO: handle no organizations found for the course
            site = None
    else:
        # Operating in single site / standalone mode, return the default site
        site = Site.objects.get(id=settings.SITE_ID)
    return site 
开发者ID:appsembler,项目名称:figures,代码行数:38,代码来源:sites.py

示例13: setUp

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SITE_ID [as 别名]
def setUp(self):
        Site.objects.get_or_create(id=settings.SITE_ID, domain='example.com', name='example.com')
        self.usersettings_model.objects.create(**self.usersettings_data) 
开发者ID:mishbahr,项目名称:django-usersettings2,代码行数:5,代码来源:test_middleware.py

示例14: test_request

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SITE_ID [as 别名]
def test_request(self):
        """ Makes sure that the request has correct `usersettings` attribute. """
        middleware = CurrentUserSettingsMiddleware()
        request = HttpRequest()
        middleware.process_request(request)
        self.assertEqual(request.usersettings.site.id, settings.SITE_ID) 
开发者ID:mishbahr,项目名称:django-usersettings2,代码行数:8,代码来源:test_middleware.py

示例15: setUp

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import SITE_ID [as 别名]
def setUp(self):
        Site.objects.get_or_create(id=settings.SITE_ID, domain='example.com', name='example.com') 
开发者ID:mishbahr,项目名称:django-usersettings2,代码行数:4,代码来源:test_models.py


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