Python django.conf.settings.SITE_ID Examples
The following are 30
code examples of django.conf.settings.SITE_ID().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.conf.settings
, or try the search function
.
Example #1
Source File: managers.py From DCRM with GNU Affero General Public License v3.0 | 6 votes |
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
Example #2
Source File: tools.py From kobo-predict with BSD 2-Clause "Simplified" License | 6 votes |
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
Example #3
Source File: flatpages.py From python2017 with MIT License | 6 votes |
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 ''
Example #4
Source File: flatpages.py From bioforum with MIT License | 6 votes |
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 ''
Example #5
Source File: settings.py From yournextrepresentative with GNU Affero General Public License v3.0 | 6 votes |
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
Example #6
Source File: models.py From GTDWeb with GNU General Public License v2.0 | 6 votes |
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." )
Example #7
Source File: test_all.py From DCRM with GNU Affero General Public License v3.0 | 6 votes |
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.")
Example #8
Source File: flatpages.py From GTDWeb with GNU General Public License v2.0 | 6 votes |
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 ''
Example #9
Source File: flatpages.py From openhgsenti with Apache License 2.0 | 6 votes |
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 ''
Example #10
Source File: models.py From openhgsenti with Apache License 2.0 | 6 votes |
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." )
Example #11
Source File: checks.py From promgen with MIT License | 6 votes |
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)
Example #12
Source File: flatpages.py From Hands-On-Application-Development-with-PyCharm with MIT License | 6 votes |
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 ''
Example #13
Source File: models.py From django-usersettings2 with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #14
Source File: sites.py From callisto-core with GNU Affero General Public License v3.0 | 5 votes |
def __exit__(self, *args): settings.SITE_ID = self.site_id_stable
Example #15
Source File: test_validation.py From callisto-core with GNU Affero General Public License v3.0 | 5 votes |
def setUp(self): del settings.SITE_ID self.populate_sites() self.populate_emails() super(EmailValidationTest, self).setUp()
Example #16
Source File: 0002_set_site_domain_and_name.py From betterself with MIT License | 5 votes |
def update_site_forward(apps, schema_editor): """Set site domain and name.""" Site = apps.get_model('sites', 'Site') Site.objects.update_or_create( id=settings.SITE_ID, defaults={ 'domain': 'betterself.io', 'name': 'betterself' } )
Example #17
Source File: mixins.py From ecommerce with GNU Affero General Public License v3.0 | 5 votes |
def setUp(self): super(SiteMixin, self).setUp() # Set the domain used for all test requests domain = 'testserver.fake' self.client = self.client_class(SERVER_NAME=domain) Course.objects.all().delete() Partner.objects.all().delete() Site.objects.all().delete() lms_url_root = "http://lms.testserver.fake" self.site_configuration = SiteConfigurationFactory( lms_url_root=lms_url_root, from_email='from@example.com', oauth_settings={ 'SOCIAL_AUTH_EDX_OAUTH2_KEY': 'key', 'SOCIAL_AUTH_EDX_OAUTH2_SECRET': 'secret', 'BACKEND_SERVICE_EDX_OAUTH2_KEY': 'key', 'BACKEND_SERVICE_EDX_OAUTH2_SECRET': 'secret', 'SOCIAL_AUTH_EDX_OAUTH2_LOGOUT_URL': lms_url_root + '/logout', }, partner__name='edX', partner__short_code='edx', segment_key='fake_segment_key', site__domain=domain, site__id=settings.SITE_ID, base_cookie_domain=domain, ) self.partner = self.site_configuration.partner self.partner.default_site = self.site = self.site_configuration.site self.partner.save() self.request = RequestFactory(SERVER_NAME=domain).get('') self.request.session = None self.request.site = self.site set_thread_variable('request', self.request) set_current_request(self.request) self.addCleanup(set_current_request)
Example #18
Source File: 0003_set_site_domain_and_name.py From open with MIT License | 5 votes |
def update_site_backward(apps, schema_editor): """Revert site domain and name to default.""" Site = apps.get_model("sites", "Site") Site.objects.update_or_create( id=settings.SITE_ID, defaults={"domain": "example.com", "name": "example.com"} )
Example #19
Source File: 0002_set_site_domain_and_name.py From betterself with MIT License | 5 votes |
def update_site_backward(apps, schema_editor): """Revert site domain and name to default.""" Site = apps.get_model('sites', 'Site') Site.objects.update_or_create( id=settings.SITE_ID, defaults={ 'domain': 'example.com', 'name': 'example.com' } )
Example #20
Source File: 0003_set_site_domain_and_name.py From opentaps_seas with GNU Lesser General Public License v3.0 | 5 votes |
def update_site_backward(apps, schema_editor): """Revert site domain and name to default.""" Site = apps.get_model("sites", "Site") Site.objects.update_or_create( id=settings.SITE_ID, defaults={"domain": "example.com", "name": "example.com"} )
Example #21
Source File: 0003_set_site_domain_and_name.py From open with MIT License | 5 votes |
def update_site_forward(apps, schema_editor): """Set site domain and name.""" Site = apps.get_model("sites", "Site") Site.objects.update_or_create( id=settings.SITE_ID, defaults={ "domain": "open.senrigan.io", "name": "open", }, )
Example #22
Source File: 0002_set_site_domain_and_name.py From semillas_platform with MIT License | 5 votes |
def update_site_backward(apps, schema_editor): """Revert site domain and name to default.""" Site = apps.get_model('sites', 'Site') Site.objects.update_or_create( id=settings.SITE_ID, defaults={ 'domain': 'example.com', 'name': 'example.com' } )
Example #23
Source File: 0002_set_site_domain_and_name.py From semillas_platform with MIT License | 5 votes |
def update_site_forward(apps, schema_editor): """Set site domain and name.""" Site = apps.get_model('sites', 'Site') Site.objects.update_or_create( id=settings.SITE_ID, defaults={ 'domain': 'semillasocial.org', 'name': 'semillas_backend' } )
Example #24
Source File: feeds.py From django-torina-blog with MIT License | 5 votes |
def site(self): """サイト詳細情報の遅延ロード""" if not hasattr(self, '_site'): site = Site.objects.get(pk=settings.SITE_ID) mysite, _ = SiteDetail.objects.get_or_create(site=site) self._site = mysite return self._site
Example #25
Source File: test_algolia_models.py From course-discovery with GNU Affero General Public License v3.0 | 5 votes |
def setUpClass(cls): super(TestAlgoliaProxyWithEdxPartner, cls).setUpClass() Partner.objects.all().delete() Site.objects.all().delete() cls.site = SiteFactory(id=settings.SITE_ID, domain=TEST_DOMAIN) cls.edxPartner = PartnerFactory(site=cls.site) cls.edxPartner.name = 'edX'
Example #26
Source File: mixins.py From course-discovery with GNU Affero General Public License v3.0 | 5 votes |
def setUpClass(cls): super().setUpClass() Site.objects.all().delete() cls.site = SiteFactory(id=settings.SITE_ID, domain=TEST_DOMAIN) cls.partner = PartnerFactory(site=cls.site) cls.request = RequestFactory(SERVER_NAME=cls.site.domain).get('') cls.request.site = cls.site
Example #27
Source File: conftest.py From course-discovery with GNU Affero General Public License v3.0 | 5 votes |
def site(db): # pylint: disable=unused-argument skip_if_no_django() from django.conf import settings Site.objects.all().delete() return SiteFactory(id=settings.SITE_ID, domain=TEST_DOMAIN)
Example #28
Source File: set_site.py From lexpredict-contraxsuite with GNU Affero General Public License v3.0 | 5 votes |
def handle(self, *args, **options): Site.objects.update_or_create( id=settings.SITE_ID, defaults={ 'domain': settings.HOST_NAME, 'name': settings.SITE_NAME } )
Example #29
Source File: managers.py From rdmo with Apache License 2.0 | 5 votes |
def filter_current_site(self): return self.filter(sites=settings.SITE_ID)
Example #30
Source File: managers.py From rdmo with Apache License 2.0 | 5 votes |
def filter_current_site(self): return self.filter(project__site=settings.SITE_ID)