Implement some basic API access for paperwork and membershipworks

This commit is contained in:
Adam Goldsmith 2022-12-25 01:21:30 -05:00
parent d1d7161fd7
commit 48cad701e8
5 changed files with 104 additions and 0 deletions

View File

@ -21,8 +21,13 @@ from django.conf import settings
from rest_framework import routers
from paperwork.api import router as paperwork_router
from membershipworks.api import router as membershipworks_router
router = routers.DefaultRouter()
router.registry.extend(paperwork_router.registry)
router.registry.extend(membershipworks_router.registry)
urlpatterns = [
path("", lambda request: redirect("/tasks/"), name="root"),
path("tasks/", include("tasks.urls")),

30
membershipworks/api.py Normal file
View File

@ -0,0 +1,30 @@
from rest_framework import routers, serializers, viewsets
from .models import Member, MemberFlag, Flag
class MemberSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Member
fields = "__all__"
class MemberViewSet(viewsets.ModelViewSet):
queryset = Member.objects.all()
serializer_class = MemberSerializer
class FlagSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Flag
fields = "__all__"
class FlagViewSet(viewsets.ModelViewSet):
queryset = Flag.objects.all()
serializer_class = FlagSerializer
router = routers.DefaultRouter()
router.register(r"membershipworks/member", MemberViewSet)
router.register(r"membershipworks/flag", FlagViewSet)

50
paperwork/api.py Normal file
View File

@ -0,0 +1,50 @@
from rest_framework import routers, serializers, viewsets
from .models import Certification, CertificationDefinition, CertificationVersion
class CertificationDefinitionSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = CertificationDefinition
fields = ["certification_name", "department", "mailing_list"]
class CertificationDefinitionViewSet(viewsets.ModelViewSet):
queryset = CertificationDefinition.objects.all()
serializer_class = CertificationDefinitionSerializer
class CertificationVersionSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = CertificationVersion
fields = ["definition", "version"]
class CertificationVersionViewSet(viewsets.ModelViewSet):
queryset = CertificationVersion.objects.all()
serializer_class = CertificationVersionSerializer
class CertificationSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Certification
fields = [
"name",
"member",
"certification_version",
"certified_by",
"date",
"shop_lead_notified",
"notes",
]
class CertificationViewSet(viewsets.ModelViewSet):
queryset = Certification.objects.all()
serializer_class = CertificationSerializer
router = routers.DefaultRouter()
router.register(r"paperwork/certification_definition", CertificationDefinitionViewSet)
router.register(r"paperwork/certification_version", CertificationVersionViewSet)
router.register(r"paperwork/certification", CertificationViewSet)

View File

@ -0,0 +1,18 @@
# Generated by Django 4.1.3 on 2022-12-24 17:04
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("paperwork", "0004_alter_certification_options"),
]
operations = [
migrations.AddField(
model_name="certificationdefinition",
name="mailing_list",
field=models.CharField(blank=True, max_length=128),
),
]

View File

@ -58,6 +58,7 @@ class CertificationDefinition(models.Model):
department = models.CharField(
db_column="Department", max_length=255, blank=True, null=True
)
mailing_list = models.CharField(max_length=128, blank=True)
def __str__(self):
return f"{self.certification_name} <{self.department}>"