Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove sites framework #913

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions onadata/apps/api/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from django import forms
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.core.files.storage import default_storage
from django.http import (
HttpResponse,
Expand Down Expand Up @@ -245,7 +244,7 @@ def get_view_description(view_obj, html=False):
Replace example.com in Django REST framework's default API description
with the domain name of the current site
"""
domain = Site.objects.get_current().domain
domain = settings.KOBOCAT_PUBLIC_HOSTNAME
description = rest_framework_views.get_view_description(view_obj, html)
# description might not be a plain string: e.g. it could be a SafeText
# to prevent further HTML escaping
Expand Down
10 changes: 1 addition & 9 deletions onadata/apps/main/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# coding: utf-8
from django.conf import settings
from django.contrib.sites.models import Site


def google_analytics(request):
Expand All @@ -15,14 +14,7 @@ def google_analytics(request):


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}
return {'SITE_NAME': settings.KOBOCAT_PUBLIC_HOSTNAME}


def base_url(request):
Expand Down
8 changes: 1 addition & 7 deletions onadata/apps/main/tests/test_custom_context_processors.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
# coding: utf-8
from django.conf import settings
from django.test import TestCase
from onadata.apps.main.context_processors import site_name


class CustomContextProcessorsTest(TestCase):
def test_site_name(self):
context = site_name(None)
self.assertEqual(context, {'SITE_NAME': 'example.com'})
restore_site_id = settings.SITE_ID
settings.SITE_ID = 100
context = site_name(None)
self.assertEqual(context, {'SITE_NAME': 'example.org'})
settings.SITE_ID = restore_site_id
self.assertEqual(context, {'SITE_NAME': 'kc.kobotoolbox.org'})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not pass locally (because my domain name is not kc.kobotoolbox.org)
I guess we could use something like:

from django.test import override_settings

class CustomContextProcessorsTest(TestCase):
    @override_settings(KOBOCAT_PUBLIC_SUBDOMAIN='kc.domain.tld')
    def test_site_name(self):
         context = site_name(None)
         self.assertEqual(context, {'SITE_NAME': 'kc.domain.tld'})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested by setting KOBOCAT_PUBLIC_SUBDOMAIN to another value. Test failed. With recent commit, it now passes. The specific override needs to be "KOBOCAT_PUBLIC_HOSTNAME"

4 changes: 2 additions & 2 deletions onadata/libs/utils/user_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import re
from functools import wraps

from django.conf import settings
from django.contrib.auth import authenticate
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.http import HttpResponseRedirect, HttpResponse
from django.shortcuts import get_object_or_404
from guardian.shortcuts import get_perms_for_model, assign_perm
Expand All @@ -25,7 +25,7 @@ class HttpResponseNotAuthorized(HttpResponse):
def __init__(self):
HttpResponse.__init__(self)
self['WWW-Authenticate'] =\
'Basic realm="%s"' % Site.objects.get_current().name
'Basic realm="%s"' % settings.KOBOCAT_PUBLIC_HOSTNAME


def check_and_set_user(request, username):
Expand Down
3 changes: 0 additions & 3 deletions onadata/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ def skip_suspicious_operations(record):
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = env.int('DJANGO_SITE_ID', 1)

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
Expand Down Expand Up @@ -192,7 +190,6 @@ def skip_suspicious_operations(record):
# https://code.djangoproject.com/ticket/10827
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
Expand Down
Loading