[Django] #30021: Feature request to allow "mixed mode" Sites operation.

6 views
Skip to first unread message

Django

unread,
Dec 7, 2018, 8:03:40 PM12/7/18
to django-...@googlegroups.com
#30021: Feature request to allow "mixed mode" Sites operation.
-----------------------------------------+------------------------
Reporter: iraabbott | Owner: nobody
Type: New feature | Status: new
Component: contrib.sites | Version: 2.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-----------------------------------------+------------------------
We all learn very early in playing with django to set a site and a
SITE_ID. Once we operate as multiple sites, we either use the multiple
processes, each configured with a separate SITE_ID or we can now pass a
request in. However, I assume for backward compatibility, SITE_ID must
be removed. This allows all sites which specify SITE_ID to operate as if
the addition of passing request was not added. However, removing SITE_ID
to allow get_site_by_request breaks all applications which do NOT pass
request, because there is no SITE_ID.

I propose a setting, which, when set to True in addition to setting
SITE_ID, causes request to take precedence over SITE_ID. This will allow
applications using both paradigms to coexist without modification - sites
which pass request use get_site_by_request as if SITE_ID had not been
defined and calls passing no request get SITE_ID. When the new setting is
not present, all behavior is backward compatible.

Essentially, I am proposing something like the 'change set' I typed in
below - I considered that a complex and/or in the fist if could cover all
of the conditions, but I think qualifying the first line with the new
setting and adding the elif to cover the cleanup case of not set to True
is easier to understand - especially in light of understanding the the
backward compatibility aspect of the change. The version of this change I
am currently running simply defines a new SITE_DEFAULT_ID to catch the
third case, but it occurred to me that some modules may expect SITE_ID
directly for some reason, and MIXED_MODE has them covered too.

I expect the documentation change to accompany the new setting would go
with the Sites documentation next to SITE_ID an explanation of removing
SITE_ID to use request.

This would be my first contribution, so I am unsure that it would welcome.
If this ticket is accepted, I will quite gladly prepare a pull request
with an agreed upon setting name (in case mine doesn't grab ya) or other
any other suggested style improvements etc.

Thank you for taking the time to review my request.

All the best, and thank you for your work with django.

Manually edited 'change set' describing the proposed change (three lines)
follow:

django/contrib/sites/models.py

def get_current(self, request=None):
"""
Return the current Site based on the SITE_ID in the project's
settings.
If SITE_ID isn't defined, return 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', ''):
++ if getattr(settings, 'SITE_ID', '') and not getattr(settings,
'SITE_MIXED_MODE'):
site_id = settings.SITE_ID
return self._get_site_by_id(site_id)
elif request:
return self._get_site_by_request(request)
++ elif getattr(settings, 'SITE_MIXED_MODE') and
settings.SITE_MIXED_MODE = True:
++ return self._get_site_by_id(site_id)

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."
)

--
Ticket URL: <https://code.djangoproject.com/ticket/30021>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 7, 2018, 8:44:53 PM12/7/18
to django-...@googlegroups.com
#30021: Feature request to allow "mixed mode" Sites operation.
-------------------------------+--------------------------------------
Reporter: Ira Abbott | Owner: nobody

Type: New feature | Status: new
Component: contrib.sites | Version: 2.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 1

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Ira Abbott):

* needs_docs: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/30021#comment:1>

Django

unread,
Dec 7, 2018, 8:45:48 PM12/7/18
to django-...@googlegroups.com
#30021: Feature request to allow "mixed mode" Sites operation.
-------------------------------+--------------------------------------
Reporter: Ira Abbott | Owner: nobody

Type: New feature | Status: new
Component: contrib.sites | Version: 2.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 1

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Ira Abbott):

* cc: Ira Abbott (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/30021#comment:2>

Django

unread,
Dec 7, 2018, 8:47:39 PM12/7/18
to django-...@googlegroups.com
#30021: Feature request to allow "mixed mode" Sites operation.
-------------------------------+--------------------------------------
Reporter: Ira Abbott | Owner: nobody

Type: New feature | Status: new
Component: contrib.sites | Version: 2.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 1

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by Ira Abbott:

Old description:

New description:

django/contrib/sites/models.py

settings.SITE_MIXED_MODE == True:
++ return self._get_site_by_id(site_id)

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."
)

--

--
Ticket URL: <https://code.djangoproject.com/ticket/30021#comment:3>

Django

unread,
Dec 7, 2018, 8:50:25 PM12/7/18
to django-...@googlegroups.com
#30021: Feature request to allow "mixed mode" Sites operation.
-------------------------------+--------------------------------------
Reporter: Ira Abbott | Owner: nobody

Type: New feature | Status: new
Component: contrib.sites | Version: 2.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 1

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by Ira Abbott:

Old description:

> We all learn very early in playing with django to set a site and a

> settings.SITE_MIXED_MODE == True:


> ++ return self._get_site_by_id(site_id)
>
> 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."
> )

New description:

django/contrib/sites/models.py

mixed = getattr(settings, 'SITE_MIXED_MODE')


-- if getattr(settings, 'SITE_ID', ''):

++ if getattr(settings, 'SITE_ID', '') and not mixed:


site_id = settings.SITE_ID
return self._get_site_by_id(site_id)
elif request:
return self._get_site_by_request(request)

++ elif mixed == True:
++ return self._get_site_by_id(site_id)

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."
)

--

--
Ticket URL: <https://code.djangoproject.com/ticket/30021#comment:4>

Django

unread,
Dec 7, 2018, 8:50:57 PM12/7/18
to django-...@googlegroups.com
#30021: Feature request to allow "mixed mode" Sites operation.
-------------------------------+--------------------------------------
Reporter: Ira Abbott | Owner: nobody

Type: New feature | Status: new
Component: contrib.sites | Version: 2.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 1

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by Ira Abbott:

Old description:

> We all learn very early in playing with django to set a site and a

> mixed = getattr(settings, 'SITE_MIXED_MODE')

> -- if getattr(settings, 'SITE_ID', ''):

> ++ if getattr(settings, 'SITE_ID', '') and not mixed:


> site_id = settings.SITE_ID
> return self._get_site_by_id(site_id)
> elif request:
> return self._get_site_by_request(request)

> ++ elif mixed == True:


> ++ return self._get_site_by_id(site_id)
>
> 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."
> )

New description:

django/contrib/sites/models.py

+ mixed = getattr(settings, 'SITE_MIXED_MODE')


-- if getattr(settings, 'SITE_ID', ''):

++ if getattr(settings, 'SITE_ID', '') and not mixed:


site_id = settings.SITE_ID
return self._get_site_by_id(site_id)
elif request:
return self._get_site_by_request(request)

++ elif mixed == True:
++ return self._get_site_by_id(site_id)

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."
)

--

--
Ticket URL: <https://code.djangoproject.com/ticket/30021#comment:5>

Django

unread,
Dec 7, 2018, 8:51:21 PM12/7/18
to django-...@googlegroups.com
#30021: Feature request to allow "mixed mode" Sites operation.
-------------------------------+--------------------------------------
Reporter: Ira Abbott | Owner: nobody

Type: New feature | Status: new
Component: contrib.sites | Version: 2.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 1

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by Ira Abbott:

Old description:

> We all learn very early in playing with django to set a site and a

> + mixed = getattr(settings, 'SITE_MIXED_MODE')

> -- if getattr(settings, 'SITE_ID', ''):

> ++ if getattr(settings, 'SITE_ID', '') and not mixed:


> site_id = settings.SITE_ID
> return self._get_site_by_id(site_id)
> elif request:
> return self._get_site_by_request(request)

> ++ elif mixed == True:


> ++ return self._get_site_by_id(site_id)
>
> 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."
> )

New description:

django/contrib/sites/models.py

++ mixed = getattr(settings, 'SITE_MIXED_MODE')


-- if getattr(settings, 'SITE_ID', ''):

++ if getattr(settings, 'SITE_ID', '') and not mixed:


site_id = settings.SITE_ID
return self._get_site_by_id(site_id)
elif request:
return self._get_site_by_request(request)

++ elif mixed == True:
++ return self._get_site_by_id(site_id)

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."
)

--

--
Ticket URL: <https://code.djangoproject.com/ticket/30021#comment:6>

Django

unread,
Dec 7, 2018, 8:55:31 PM12/7/18
to django-...@googlegroups.com
#30021: Feature request to allow "mixed mode" Sites operation.
-------------------------------+--------------------------------------
Reporter: Ira Abbott | Owner: nobody

Type: New feature | Status: new
Component: contrib.sites | Version: 2.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 1

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by Ira Abbott:

Old description:

> We all learn very early in playing with django to set a site and a

> ++ mixed = getattr(settings, 'SITE_MIXED_MODE')

> -- if getattr(settings, 'SITE_ID', ''):

> ++ if getattr(settings, 'SITE_ID', '') and not mixed:


> site_id = settings.SITE_ID
> return self._get_site_by_id(site_id)
> elif request:
> return self._get_site_by_request(request)

> ++ elif mixed == True:


> ++ return self._get_site_by_id(site_id)
>
> 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."
> )

New description:

django/contrib/sites/models.py

++ mixed = getattr(settings, 'SITE_MIXED_MODE')

-- if getattr(settings, 'SITE_ID', ''):

++ if getattr(settings, 'SITE_ID', '') and not mixed:


site_id = settings.SITE_ID
return self._get_site_by_id(site_id)
elif request:
return self._get_site_by_request(request)

++ elif getattr(settings, 'SITE_ID', '') and mixed == True:
++ site_id = settings.SITE_ID
++ return self._get_site_by_id(site_id)

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."
)

--

--
Ticket URL: <https://code.djangoproject.com/ticket/30021#comment:7>

Django

unread,
Dec 7, 2018, 8:57:48 PM12/7/18
to django-...@googlegroups.com
#30021: Feature request to allow "mixed mode" Sites operation.
-------------------------------+--------------------------------------
Reporter: Ira Abbott | Owner: nobody

Type: New feature | Status: new
Component: contrib.sites | Version: 2.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 1

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Ira Abbott):

Sorry for the churn. I proposed something I am hoping is more elegant and
in line than my current version. After I typed it, I saw that it needed a
little splatter-proofing.

--
Ticket URL: <https://code.djangoproject.com/ticket/30021#comment:8>

Django

unread,
Dec 7, 2018, 9:17:34 PM12/7/18
to django-...@googlegroups.com
#30021: Feature request to allow "mixed mode" Sites operation.
-------------------------------+--------------------------------------
Reporter: Ira Abbott | Owner: nobody

Type: New feature | Status: new
Component: contrib.sites | Version: 2.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 1

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by Ira Abbott:

Old description:

> We all learn very early in playing with django to set a site and a

> ++ mixed = getattr(settings, 'SITE_MIXED_MODE')

> -- if getattr(settings, 'SITE_ID', ''):

> ++ if getattr(settings, 'SITE_ID', '') and not mixed:


> site_id = settings.SITE_ID
> return self._get_site_by_id(site_id)
> elif request:
> return self._get_site_by_request(request)

> ++ elif getattr(settings, 'SITE_ID', '') and mixed == True:
> ++ site_id = settings.SITE_ID

> ++ return self._get_site_by_id(site_id)
>
> 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."
> )

New description:

django/contrib/sites/models.py

++ has_mixed = getattr(settings, 'SITE_MIXED_MODE')
++ has_site = getattr(settings, 'SITE_ID', '')


-- if getattr(settings, 'SITE_ID', ''):

++ if has_site and not has_mixed:


site_id = settings.SITE_ID
return self._get_site_by_id(site_id)
elif request:
return self._get_site_by_request(request)

++ elif has_site and has_mixed and settings.SITE_MIXED_MODE == True:
++ site_id = settings.SITE_ID
++ return self._get_site_by_id(site_id)

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."
)

--

--
Ticket URL: <https://code.djangoproject.com/ticket/30021#comment:9>

Django

unread,
Dec 7, 2018, 9:27:18 PM12/7/18
to django-...@googlegroups.com
#30021: Feature request to allow "mixed mode" Sites operation.
-------------------------------+--------------------------------------
Reporter: Ira Abbott | Owner: nobody

Type: New feature | Status: new
Component: contrib.sites | Version: 2.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 1

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by Ira Abbott:

Old description:

> We all learn very early in playing with django to set a site and a

> ++ has_mixed = getattr(settings, 'SITE_MIXED_MODE')
> ++ has_site = getattr(settings, 'SITE_ID', '')

> -- if getattr(settings, 'SITE_ID', ''):

> ++ if has_site and not has_mixed:


> site_id = settings.SITE_ID
> return self._get_site_by_id(site_id)
> elif request:
> return self._get_site_by_request(request)

> ++ elif has_site and has_mixed and settings.SITE_MIXED_MODE ==
> True:
> ++ site_id = settings.SITE_ID

> ++ return self._get_site_by_id(site_id)
>
> 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."
> )

New description:

django/contrib/sites/models.py

++ site_id = getattr(settings, 'SITE_ID', '')
++ mixed = getattr(settings, 'SITE_MIXED_MODE', '')


-- if getattr(settings, 'SITE_ID', ''):

++ if site_id and not mixed:
-- site_id = settings.SITE_ID


return self._get_site_by_id(site_id)
elif request:
return self._get_site_by_request(request)

++ elif site_id and mixed == True:
++ return self._get_site_by_id(site_id)

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."
)

--

--
Ticket URL: <https://code.djangoproject.com/ticket/30021#comment:10>

Django

unread,
Dec 7, 2018, 9:59:24 PM12/7/18
to django-...@googlegroups.com
#30021: Feature request to allow "mixed mode" Sites operation.
-------------------------------+--------------------------------------
Reporter: Ira Abbott | Owner: nobody

Type: New feature | Status: new
Component: contrib.sites | Version: 2.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 1

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Ira Abbott):

After more tweaking and plugging it in for test:

def get_current(self, request=None):
"""
Return the current Site based on the SITE_ID in the project's
settings.
If SITE_ID isn't defined, return 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

site_id = getattr(settings, 'SITE_ID', '')

mixed_mode = getattr(settings, 'SITE_MIXED_MODE', '')
if site_id and not mixed_mode:


return self._get_site_by_id(site_id)
elif request:
return self._get_site_by_request(request)

elif site_id and mixed_mode == True:
return self._get_site_by_id(site_id)

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."
)

--
Ticket URL: <https://code.djangoproject.com/ticket/30021#comment:11>

Django

unread,
Dec 7, 2018, 10:16:20 PM12/7/18
to django-...@googlegroups.com
#30021: Feature request to allow "mixed mode" Sites operation.
-------------------------------+--------------------------------------
Reporter: Ira Abbott | Owner: nobody

Type: New feature | Status: new
Component: contrib.sites | Version: 2.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 1

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Ira Abbott):

I have tested the changed file with both with and without the new setting
and verified that site by request happened with the setting, but that I
got the base site without it. I also removed the app requiring site id,
but left the one with request and verified that with no SITE_ID (simple
switcheroo in the settings).

--
Ticket URL: <https://code.djangoproject.com/ticket/30021#comment:12>

Django

unread,
Dec 7, 2018, 10:27:09 PM12/7/18
to django-...@googlegroups.com
#30021: Feature request to allow "mixed mode" Sites operation.
-------------------------------+--------------------------------------
Reporter: Ira Abbott | Owner: nobody

Type: New feature | Status: new
Component: contrib.sites | Version: 2.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 1

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by Tim Graham:

Old description:

> ++ site_id = getattr(settings, 'SITE_ID', '')
> ++ mixed = getattr(settings, 'SITE_MIXED_MODE', '')


> -- if getattr(settings, 'SITE_ID', ''):

> ++ if site_id and not mixed:

> -- site_id = settings.SITE_ID


> return self._get_site_by_id(site_id)
> elif request:
> return self._get_site_by_request(request)

> ++ elif site_id and mixed == True:


> ++ return self._get_site_by_id(site_id)
>
> 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."
> )

New description:

django/contrib/sites/models.py
{{{ #!diff


def get_current(self, request=None):
"""
Return the current Site based on the SITE_ID in the project's
settings.
If SITE_ID isn't defined, return 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

++ site_id = getattr(settings, 'SITE_ID', '')
++ mixed = getattr(settings, 'SITE_MIXED_MODE', '')


-- if getattr(settings, 'SITE_ID', ''):

++ if site_id and not mixed:

-- site_id = settings.SITE_ID


return self._get_site_by_id(site_id)
elif request:
return self._get_site_by_request(request)

++ elif site_id and mixed == True:
++ return self._get_site_by_id(site_id)

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."
)
}}}

--

--
Ticket URL: <https://code.djangoproject.com/ticket/30021#comment:13>

Django

unread,
Dec 7, 2018, 11:27:37 PM12/7/18
to django-...@googlegroups.com
#30021: Feature request to allow "mixed mode" Sites operation.
-------------------------------+--------------------------------------
Reporter: Ira Abbott | Owner: nobody

Type: New feature | Status: new
Component: contrib.sites | Version: 2.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 1

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Ira Abbott):

* has_patch: 1 => 0


Old description:

> {{{ #!diff


> def get_current(self, request=None):
> """
> Return the current Site based on the SITE_ID in the project's
> settings.
> If SITE_ID isn't defined, return 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

> ++ site_id = getattr(settings, 'SITE_ID', '')
> ++ mixed = getattr(settings, 'SITE_MIXED_MODE', '')

> -- if getattr(settings, 'SITE_ID', ''):

> ++ if site_id and not mixed:

> -- site_id = settings.SITE_ID


> return self._get_site_by_id(site_id)
> elif request:
> return self._get_site_by_request(request)

> ++ elif site_id and mixed == True:


> ++ return self._get_site_by_id(site_id)
>
> 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."
> )
> }}}

New description:

django/contrib/sites/models.py

++ site_id = getattr(settings, 'SITE_ID', '')
++ mixed = getattr(settings, 'SITE_MIXED_MODE', '')

-- if getattr(settings, 'SITE_ID', ''):

++ if site_id and not mixed:

-- site_id = settings.SITE_ID


return self._get_site_by_id(site_id)
elif request:
return self._get_site_by_request(request)

++ elif site_id and mixed == True:
++ return self._get_site_by_id(site_id)

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."
)

--

--
Ticket URL: <https://code.djangoproject.com/ticket/30021#comment:14>

Django

unread,
Dec 8, 2018, 9:23:07 AM12/8/18
to django-...@googlegroups.com
#30021: Allow contrib.sites to use the request host and fallback to a SITE_ID
-------------------------------+-----------------------------------------
Reporter: Ira Abbott | Owner: nobody

Type: New feature | Status: new
Component: contrib.sites | Version: 2.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Someday/Maybe
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+-----------------------------------------
Changes (by Tim Graham):

* needs_docs: 1 => 0
* stage: Unreviewed => Someday/Maybe
* easy: 1 => 0


Old description:

> We all learn very early in playing with django to set a site and a

> ++ site_id = getattr(settings, 'SITE_ID', '')
> ++ mixed = getattr(settings, 'SITE_MIXED_MODE', '')

> -- if getattr(settings, 'SITE_ID', ''):

> ++ if site_id and not mixed:

> -- site_id = settings.SITE_ID


> return self._get_site_by_id(site_id)
> elif request:
> return self._get_site_by_request(request)

> ++ elif site_id and mixed == True:


> ++ return self._get_site_by_id(site_id)
>
> 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."
> )

New description:

django/contrib/sites/models.py
{{{ #!diff


def get_current(self, request=None):
"""
Return the current Site based on the SITE_ID in the project's
settings.
If SITE_ID isn't defined, return 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

++ site_id = getattr(settings, 'SITE_ID', '')
++ mixed = getattr(settings, 'SITE_MIXED_MODE', '')

-- if getattr(settings, 'SITE_ID', ''):

++ if site_id and not mixed:

-- site_id = settings.SITE_ID


return self._get_site_by_id(site_id)
elif request:
return self._get_site_by_request(request)

++ elif site_id and mixed == True:
++ return self._get_site_by_id(site_id)

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."
)
}}}

--

Comment:

Proposals for new settings must be made on the DevelopersMailingList.

--
Ticket URL: <https://code.djangoproject.com/ticket/30021#comment:15>

Django

unread,
Dec 9, 2018, 9:05:32 PM12/9/18
to django-...@googlegroups.com
#30021: Allow contrib.sites to use the request host and fallback to a SITE_ID
-------------------------------+-----------------------------------------
Reporter: Ira Abbott | Owner: nobody

Type: New feature | Status: new
Component: contrib.sites | Version: 2.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Someday/Maybe
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+-----------------------------------------

Comment (by Ira Abbott):

Thanks Tim. Given that I did not follow process, I will take
"Someday/Maybe" as positive feedback.
I have copied the result here to DevelopersMailingList, waiting for the
topic's approval.
Thank you for your consideration and patience.

--
Ticket URL: <https://code.djangoproject.com/ticket/30021#comment:16>

Reply all
Reply to author
Forward
0 new messages