add hostadmin app
This commit is contained in:
parent
12191369b7
commit
3cd89b7162
13 changed files with 143 additions and 38 deletions
0
backend/hostadmin/__init__.py
Normal file
0
backend/hostadmin/__init__.py
Normal file
11
backend/hostadmin/admin.py
Normal file
11
backend/hostadmin/admin.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
from django.contrib import admin
|
||||
|
||||
from .models import Domain
|
||||
|
||||
|
||||
class DomainAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'owner', 'open_registration')
|
||||
list_filter = ('name', 'owner', 'open_registration')
|
||||
|
||||
|
||||
admin.site.register(Domain, DomainAdmin)
|
27
backend/hostadmin/api.py
Normal file
27
backend/hostadmin/api.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
from rest_framework import routers, serializers, viewsets
|
||||
from rest_framework.authentication import TokenAuthentication
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
|
||||
from hostadmin.models import Domain
|
||||
|
||||
router = routers.SimpleRouter()
|
||||
|
||||
|
||||
class DomainSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Domain
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class DomainViewSet(viewsets.ModelViewSet):
|
||||
queryset = Domain.objects.all()
|
||||
serializer_class = DomainSerializer
|
||||
authentication_classes = [TokenAuthentication]
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
|
||||
router.register(r'domains', DomainViewSet, basename='domains')
|
||||
|
||||
urlpatterns = [
|
||||
*router.urls,
|
||||
]
|
26
backend/hostadmin/migrations/0001_initial.py
Normal file
26
backend/hostadmin/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
# Generated by Django 4.1.7 on 2023-06-07 20:59
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Domain',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=255, unique=True)),
|
||||
('open_registration', models.BooleanField(default=False)),
|
||||
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='domains', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
]
|
0
backend/hostadmin/migrations/__init__.py
Normal file
0
backend/hostadmin/migrations/__init__.py
Normal file
10
backend/hostadmin/models.py
Normal file
10
backend/hostadmin/models.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
from django.db import models
|
||||
|
||||
|
||||
class Domain(models.Model):
|
||||
name = models.CharField(max_length=255, unique=True)
|
||||
owner = models.ForeignKey('authentication.ToolshedUser', on_delete=models.CASCADE, related_name='domains')
|
||||
open_registration = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
20
backend/hostadmin/tests.py
Normal file
20
backend/hostadmin/tests.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
from django.test import TestCase
|
||||
|
||||
from authentication.models import ToolshedUser
|
||||
from hostadmin.models import Domain
|
||||
|
||||
|
||||
class DomainTestCase(TestCase):
|
||||
def setUp(self):
|
||||
admin = ToolshedUser.objects.create_superuser('admin', 'admin@localhost', '')
|
||||
admin.set_password('testpassword')
|
||||
admin.save()
|
||||
example_com = Domain.objects.create(name='example.com', owner=admin, open_registration=True)
|
||||
example_com.save()
|
||||
|
||||
def test_domain(self):
|
||||
example_com = Domain.objects.get(name='example.com')
|
||||
self.assertEqual(example_com.name, 'example.com')
|
||||
self.assertEqual(example_com.owner.username, 'admin')
|
||||
self.assertEqual(example_com.open_registration, True)
|
||||
self.assertEqual(str(example_com), 'example.com')
|
Loading…
Add table
Add a link
Reference in a new issue