Skip to content

Commit

Permalink
Merge pull request #913 from kobotoolbox/remove-sites
Browse files Browse the repository at this point in the history
Remove sites framework
  • Loading branch information
noliveleger committed Jan 24, 2024
2 parents c44af5a + 6872605 commit 523fcce
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 24 deletions.
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
11 changes: 3 additions & 8 deletions onadata/apps/main/tests/test_custom_context_processors.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
# coding: utf-8
from django.conf import settings
from django.test import TestCase
from django.test import override_settings, TestCase
from onadata.apps.main.context_processors import site_name


class CustomContextProcessorsTest(TestCase):
@override_settings(KOBOCAT_PUBLIC_HOSTNAME="kc.kobotoolbox.org")
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'})
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

0 comments on commit 523fcce

Please sign in to comment.