Browse Source

initial bloop

main
Julia Luna 2 years ago
commit
9c1a199ec8
Signed by: xenua
GPG Key ID: 6A0C04FA9A7D7582
  1. 4
      .gitignore
  2. 22
      manage.py
  3. 2
      requirements.txt
  4. 0
      scopedsites/__init__.py
  5. 3
      scopedsites/admin.py
  6. 6
      scopedsites/apps.py
  7. 16
      scopedsites/middleware.py
  8. 0
      scopedsites/migrations/__init__.py
  9. 20
      scopedsites/models.py
  10. 3
      scopedsites/tests.py
  11. 3
      scopedsites/views.py

4
.gitignore vendored

@ -0,0 +1,4 @@
env/
.idea/
db.sqlite3
django_scopedsites

22
manage.py

@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_scopedsites.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()

2
requirements.txt

@ -0,0 +1,2 @@
django_scopes
django

0
scopedsites/__init__.py

3
scopedsites/admin.py

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
scopedsites/apps.py

@ -0,0 +1,6 @@
from django.apps import AppConfig
class ScopedsitesConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'scopedsites'

16
scopedsites/middleware.py

@ -0,0 +1,16 @@
from django_scopes import scope
from scopedsites.models import Domain
class DomainScopeMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
d = Domain.get_from_request(request)
with scope(domain=d):
response = self.get_response(request)
return response

0
scopedsites/migrations/__init__.py

20
scopedsites/models.py

@ -0,0 +1,20 @@
from django.db import models
from django.shortcuts import get_object_or_404
from django.utils.translation import gettext_lazy as _
class Domain(models.Model):
fqdn = models.CharField(
_('FQDN'),
max_length=255,
unique=True,
)
name = models.CharField(
_('display name'),
max_length=255,
)
@classmethod
def get_from_request(cls, request):
return get_object_or_404(cls, fqdn__iexact=request.META.get('HTTP_HOST', ''))

3
scopedsites/tests.py

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
scopedsites/views.py

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.
Loading…
Cancel
Save