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


Python Site.DoesNotExist方法代码示例

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


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

示例1: handle

# 需要导入模块: from django.contrib.sites.models import Site [as 别名]
# 或者: from django.contrib.sites.models.Site import DoesNotExist [as 别名]
def handle(self, *args, **options):
        """Handle the command invocation."""
        site_id = getattr(settings, 'SITE_ID', None)
        site_name = getattr(settings, 'SITE_NAME', None)
        site_domain = getattr(settings, 'SITE_DOMAIN', None)

        if not site_id:
            raise CommandError('No SITE_ID specified in project settings')
        if not site_name:
            raise CommandError('No SITE_NAME specified in project settings')
        if not site_domain:
            raise CommandError('No SITE_DOMAIN specified in project settings')

        try:
            site = Site.objects.get(pk=site_id)
        except Site.DoesNotExist:  # pylint: disable=no-member
            raise CommandError('Site "%s" does not exist' % site_id)

        site.name = site_name
        site.domain = site_domain
        site.save()

        msg = 'Successfully configured site #%s; name: "%s"; domain: %s' % (site_id, site_name, site_domain)
        self.stdout.write(self.style.SUCCESS(msg))  # pylint: disable=no-member 
开发者ID:twschiller,项目名称:open-synthesis,代码行数:26,代码来源:setname.py

示例2: add_view

# 需要导入模块: from django.contrib.sites.models import Site [as 别名]
# 或者: from django.contrib.sites.models.Site import DoesNotExist [as 别名]
def add_view(self, request, form_url='', extra_context=None):
        site_id = request.GET.get('site_id', None)

        if not site_id:
            return self.select_site_view(request)
        else:
            try:
                site_id = self.model._meta.pk.to_python(site_id)
                site = Site.objects.get(pk=site_id)
            except (Site.DoesNotExist, ValidationError, ValueError):
                return self.select_site_view(request)
            else:
                try:
                    obj = self.model.objects.get(site=site)
                    change_url = reverse(
                        'admin:%s_%s_change' % self.get_model_info(), args=(obj.pk,),
                        current_app=self.admin_site.name)
                    msg = _('{0} for "{1}" already exists. You may edit it below.')\
                        .format(self.opts.verbose_name, site.domain)
                    self.message_user(request, msg)
                    return HttpResponseRedirect(change_url)
                except self.model.DoesNotExist:
                    pass
        return super(SettingsAdmin, self).add_view(request, form_url, extra_context) 
开发者ID:mishbahr,项目名称:django-usersettings2,代码行数:26,代码来源:admin.py

示例3: changelist_view

# 需要导入模块: from django.contrib.sites.models import Site [as 别名]
# 或者: from django.contrib.sites.models.Site import DoesNotExist [as 别名]
def changelist_view(self, request, extra_context=None):
        sites_count = Site.objects.count()
        if sites_count == 1:
            site = Site.objects.get()
            try:
                obj = self.model.objects.get(site=site)
                change_url = reverse(
                    'admin:%s_%s_change' % self.get_model_info(), args=(obj.pk,),
                    current_app=self.admin_site.name)
                return HttpResponseRedirect(change_url)
            except self.model.DoesNotExist:
                add_url = '%s?site_id=%s' % (
                    reverse('admin:%s_%s_add' % self.get_model_info(),
                            current_app=self.admin_site.name), site.pk)
                return HttpResponseRedirect(add_url)

        else:
            return super(SettingsAdmin, self).changelist_view(request, extra_context) 
开发者ID:mishbahr,项目名称:django-usersettings2,代码行数:20,代码来源:admin.py

示例4: _get_context

# 需要导入模块: from django.contrib.sites.models import Site [as 别名]
# 或者: from django.contrib.sites.models.Site import DoesNotExist [as 别名]
def _get_context(self, context_list):
        try:
            data = self._model_to_dict(Site.objects.get_current())
        except Site.DoesNotExist:
            data = {}

        for context in context_list:
            if isinstance(context, dict):
                data.update(context)
            elif hasattr(context, '_meta'):
                data.update(self._model_to_dict(context))
                data.update({self._get_context_module_name(context): context})

        if settings.DEBUG and SHOW_CONTEXT:
            pprint.pprint(data)
        return data 
开发者ID:LPgenerator,项目名称:django-db-mailer,代码行数:18,代码来源:mail.py

示例5: handle

# 需要导入模块: from django.contrib.sites.models import Site [as 别名]
# 或者: from django.contrib.sites.models.Site import DoesNotExist [as 别名]
def handle(self, *args, **options):
        queryset = Referral.objects.filter(site__isnull=True)
        count = queryset.count()

        try:
            site = Site.objects.get(id=options['site_id'])
        except Site.DoesNotExist:
            msg = 'A valid Site ID must be specified!'
            self.stderr.write(msg)
            raise CommandError(msg)

        if options['commit']:
            self.stdout.write('Associating [{}] referrals with site [{}]...'.format(count, site))

            queryset.update(site=site)
            self.stdout.write('Done.')
        else:
            msg = 'This has been an example operation. If the --commit flag had been included, the command ' \
                  'would have associated [{}] referrals with site [{}].'.format(count, site)
            self.stdout.write(msg) 
开发者ID:edx,项目名称:ecommerce,代码行数:22,代码来源:add_site_to_referrals.py

示例6: handle

# 需要导入模块: from django.contrib.sites.models import Site [as 别名]
# 或者: from django.contrib.sites.models.Site import DoesNotExist [as 别名]
def handle(self, *args, **options):
        queryset = Basket.objects.filter(site__isnull=True)
        count = queryset.count()

        try:
            site = Site.objects.get(id=options['site_id'])
        except Site.DoesNotExist:
            raise CommandError('A valid Site ID must be specified!')

        if options['commit']:
            self.stderr.write('Associating [{}] baskets with site [{}]...'.format(count, site))

            queryset.update(site=site)
            self.stderr.write('Done.')
        else:
            msg = 'This has been an example operation. If the --commit flag had been included, the command ' \
                  'would have associated [{}] baskets with site [{}].'.format(count, site)
            self.stderr.write(msg) 
开发者ID:edx,项目名称:ecommerce,代码行数:20,代码来源:add_site_to_baskets.py

示例7: handle

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

        try:
            site = Site.objects.get(id=site_id)
        except Site.DoesNotExist:
            site, site_created = Site.objects.get_or_create(domain=site_domain)
            if site_created:
                logger.info('Site created with domain %s', site_domain)

        site.domain = site_domain
        if site_name:
            site.name = site_name
        site.save()

        _, created = SiteTheme.objects.update_or_create(
            site=site,
            defaults={
                'theme_dir_name': site_theme,
            }
        )
        logger.info('Site Theme %s with theme "%s"', "created" if created else "updated", site_theme) 
开发者ID:edx,项目名称:ecommerce,代码行数:27,代码来源:create_or_update_site_theme.py

示例8: site_name

# 需要导入模块: from django.contrib.sites.models import Site [as 别名]
# 或者: from django.contrib.sites.models.Site import DoesNotExist [as 别名]
def site_name(request):
    site_id = getattr(settings, 'SITE_ID', None)
    try:
        site = Site.objects.get(pk=site_id)
    except Site.DoesNotExist:
        site_name = 'example.org'
    else:
        site_name = site.name
    return {'SITE_NAME': site_name} 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:11,代码来源:context_processors.py

示例9: handle

# 需要导入模块: from django.contrib.sites.models import Site [as 别名]
# 或者: from django.contrib.sites.models.Site import DoesNotExist [as 别名]
def handle(self, *args, **options):
        """gets data from WordPress site"""
        # TODO: refactor these with .get
        if 'username' in options:
            self.username = options['username']
        else:
            self.username = None
        if 'password' in options:
            self.password = options['password']
        else:
            self.password = None

        self.xml_path = options.get('xml')
        self.url = options.get('url')
        try:
            blog_index = BlogIndexPage.objects.get(
                title__icontains=options['blog_index'])
        except BlogIndexPage.DoesNotExist:
            raise CommandError("Incorrect blog index title - have you created it?")
        if self.url == "just_testing":
            with open('test-data.json') as test_json:
                posts = json.load(test_json)
        elif self.xml_path:
            try:
                import lxml
                from blog.wp_xml_parser import XML_parser
            except ImportError as e:
                print("You must have lxml installed to run xml imports."
                      " Run `pip install lxml`.")
                raise e
            self.xml_parser = XML_parser(self.xml_path)
            posts = self.xml_parser.get_posts_data()
        else:
            posts = self.get_posts_data(self.url)
        self.should_import_comments = options.get('import_comments')
        self.create_blog_pages(posts, blog_index) 
开发者ID:thelabnyc,项目名称:wagtail_blog,代码行数:38,代码来源:wordpress_to_wagtail.py

示例10: create_user

# 需要导入模块: from django.contrib.sites.models import Site [as 别名]
# 或者: from django.contrib.sites.models.Site import DoesNotExist [as 别名]
def create_user(self, author):
        username = author['username']
        first_name = author['first_name']
        last_name = author['last_name']
        try:
            user = User.objects.get(username=username)
        except User.DoesNotExist:
            user = User.objects.create_user(
                username=username, first_name=first_name, last_name=last_name)
        return user 
开发者ID:thelabnyc,项目名称:wagtail_blog,代码行数:12,代码来源:wordpress_to_wagtail.py

示例11: __init__

# 需要导入模块: from django.contrib.sites.models import Site [as 别名]
# 或者: from django.contrib.sites.models.Site import DoesNotExist [as 别名]
def __init__(self, state=None, request=None, *args, **kwargs):
        from .conf import config

        self.config = config

        extra_scopes = self.config.MICROSOFT_AUTH_EXTRA_SCOPES

        try:
            current_site = Site.objects.get_current(request)
        except Site.DoesNotExist:
            current_site = Site.objects.first()

        domain = current_site.domain
        path = reverse("microsoft_auth:auth-callback")
        scope = " ".join(self.SCOPE_MICROSOFT)

        if self.config.MICROSOFT_AUTH_LOGIN_TYPE == LOGIN_TYPE_XBL:
            scope = " ".join(self.SCOPE_XBL)

        scope = "{} {}".format(scope, extra_scopes).strip()

        scheme = get_scheme(request, self.config)

        super().__init__(
            self.config.MICROSOFT_AUTH_CLIENT_ID,
            scope=scope,
            state=state,
            redirect_uri="{0}://{1}{2}".format(scheme, domain, path),
            *args,
            **kwargs
        ) 
开发者ID:AngellusMortis,项目名称:django_microsoft_auth,代码行数:33,代码来源:client.py

示例12: microsoft

# 需要导入模块: from django.contrib.sites.models import Site [as 别名]
# 或者: from django.contrib.sites.models.Site import DoesNotExist [as 别名]
def microsoft(request):
    """ Adds global template variables for microsoft_auth """
    login_type = None
    if config.MICROSOFT_AUTH_LOGIN_TYPE == LOGIN_TYPE_XBL:
        login_type = _("Xbox Live")
    else:
        login_type = _("Microsoft")

    if config.DEBUG:  # pragma: no branch
        try:
            current_domain = Site.objects.get_current(request).domain
        except Site.DoesNotExist:
            logger.warning(
                "\nWARNING:\nThe domain configured for the sites framework "
                "does not match the domain you are accessing Django with. "
                "Microsoft authentication may not work.\n"
            )
        else:
            do_warning = get_scheme(
                request
            ) == "http" and not current_domain.startswith("localhost")
            if do_warning:  # pragma: no branch
                logger.warning(
                    "\nWARNING:\nYou are not using HTTPS. Microsoft "
                    "authentication only works over HTTPS unless the hostname "
                    "for your `redirect_uri` is `localhost`\n"
                )

    # initialize Microsoft client using CSRF token as state variable
    signer = TimestampSigner()
    state = signer.sign(get_token(request))
    microsoft = MicrosoftClient(state=state, request=request)
    auth_url = microsoft.authorization_url()[0]
    return {
        "microsoft_login_enabled": config.MICROSOFT_AUTH_LOGIN_ENABLED,
        "microsoft_authorization_url": mark_safe(auth_url),  # nosec
        "microsoft_login_type_text": login_type,
    } 
开发者ID:AngellusMortis,项目名称:django_microsoft_auth,代码行数:40,代码来源:context_processors.py

示例13: _get_msg_with_track

# 需要导入模块: from django.contrib.sites.models import Site [as 别名]
# 或者: from django.contrib.sites.models.Site import DoesNotExist [as 别名]
def _get_msg_with_track(self):
        message = self._message
        if defaults.TRACK_ENABLE is False:
            return message
        if ENABLE_LOGGING and self._template.enable_log:
            try:
                domain = Site.objects.get_current().domain
                encrypted = signing.dumps(self._log_id, compress=True)
                path = reverse('db-mail-tracker', args=[encrypted])
                message += defaults.TRACK_HTML % {
                    'url': 'http://%s%s' % (domain, path)}
            except (Site.DoesNotExist, NoReverseMatch):
                pass
        return message 
开发者ID:LPgenerator,项目名称:django-db-mailer,代码行数:16,代码来源:mail.py

示例14: call_first_site_post_save

# 需要导入模块: from django.contrib.sites.models import Site [as 别名]
# 或者: from django.contrib.sites.models.Site import DoesNotExist [as 别名]
def call_first_site_post_save(apps, **kwargs):
    try:
        site = Site.objects.get(id=getattr(settings, 'SITE_ID', 1))
    except Site.DoesNotExist:
        pass
    else:
        site.save() 
开发者ID:PonyConf,项目名称:PonyConf,代码行数:9,代码来源:signals.py

示例15: handle

# 需要导入模块: from django.contrib.sites.models import Site [as 别名]
# 或者: from django.contrib.sites.models.Site import DoesNotExist [as 别名]
def handle(self, *args, **options):
        try:
            site = Site.objects.get(id=options['id'])
            site.name = options['name']
            site.domain = options['domain']
        except Site.DoesNotExist:
            site = Site.objects.create(id=options['id'], name=options['name'], domain=options['domain'])

        site.save()
        self.stdout.write('Created or updated site {}.'.format(options['id'])) 
开发者ID:gwu-libraries,项目名称:sfm-ui,代码行数:12,代码来源:addsite.py


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