diff --git a/member_paperwork/settings/base.py b/member_paperwork/settings/base.py index 8fffde2..19dd5d1 100644 --- a/member_paperwork/settings/base.py +++ b/member_paperwork/settings/base.py @@ -28,6 +28,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'membershipworks.apps.MembershipworksConfig', 'paperwork.apps.PaperworkConfig', ] @@ -62,7 +63,8 @@ TEMPLATES = [ WSGI_APPLICATION = 'member_paperwork.wsgi.application' -DATABASE_ROUTERS = ['paperwork.routers.MembershipWorksRouter', 'paperwork.routers.PaperworkRouter'] +DATABASE_ROUTERS = ['membershipworks.routers.MembershipWorksRouter', + 'paperwork.routers.PaperworkRouter'] # Internationalization diff --git a/membershipworks/__init__.py b/membershipworks/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/membershipworks/admin.py b/membershipworks/admin.py new file mode 100644 index 0000000..7dbdf5a --- /dev/null +++ b/membershipworks/admin.py @@ -0,0 +1,14 @@ +from django.contrib import admin + +from .models import Member + + +@admin.register(Member) +class MemberAdmin(admin.ModelAdmin): + readonly_fields = [field.name for field in Member._meta.get_fields() if field.concrete] + + def has_add_permission(self, request, obj=None): + return False + + def has_delete_permission(self, request, obj=None): + return False diff --git a/membershipworks/apps.py b/membershipworks/apps.py new file mode 100644 index 0000000..10a3771 --- /dev/null +++ b/membershipworks/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class MembershipworksConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'membershipworks' diff --git a/membershipworks/models.py b/membershipworks/models.py new file mode 100644 index 0000000..1d3a4c4 --- /dev/null +++ b/membershipworks/models.py @@ -0,0 +1,18 @@ +from django.db import models + + +class Member(models.Model): + # TODO: this is only a partial set of fields, may want to expand + uid = models.CharField(primary_key=True, max_length=24) + year_of_birth = models.TextField(db_column='Year of Birth', blank=True, null=True) + account_name = models.TextField(db_column='Account Name', blank=True, null=True) + first_name = models.TextField(db_column='First Name', blank=True, null=True) + last_name = models.TextField(db_column='Last Name', blank=True, null=True) + + def __str__(self): + return f"{self.account_name}" + + class Meta: + managed = False + db_table = 'members' + ordering = ('first_name', 'last_name') diff --git a/membershipworks/routers.py b/membershipworks/routers.py new file mode 100644 index 0000000..d1a80b2 --- /dev/null +++ b/membershipworks/routers.py @@ -0,0 +1,21 @@ +class MembershipWorksRouter: + app_label = 'membershipworks' + db = 'membershipworks' + + def db_for_read(self, model, **hints): + if model._meta.app_label == self.app_label: + return self.db + return None + + def db_for_write(self, model, **hints): + if model._meta.app_label == self.app_label: + return self.db + return None + + def allow_relation(self, obj1, obj2, **hints): + return None + + def allow_migrate(self, db, app_label, model_name=None, **hints): + if db == self.db: + return False + return None diff --git a/membershipworks/tests.py b/membershipworks/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/membershipworks/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/membershipworks/views.py b/membershipworks/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/membershipworks/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/paperwork/admin.py b/paperwork/admin.py index d43ec70..54fb78f 100644 --- a/paperwork/admin.py +++ b/paperwork/admin.py @@ -2,44 +2,33 @@ from django.contrib import admin from .models import (CmsRedRiverVeteransScholarship, CertificationDefinition, Certification, - InstructorOrVendor, SpecialProgram, Waiver, - Member) + InstructorOrVendor, SpecialProgram, Waiver) +@admin.register(CertificationDefinition) class CertificationDefinitionAdmin(admin.ModelAdmin): search_fields = ['certification_name', 'department'] +@admin.register(Certification) class CertificationAdmin(admin.ModelAdmin): search_fields = ['name', 'certification__certification_name', 'certification__department'] +@admin.register(InstructorOrVendor) class InstructorOrVendorAdmin(admin.ModelAdmin): search_fields = ['name'] +@admin.register(SpecialProgram) class SpecialProgramAdmin(admin.ModelAdmin): search_fields = ['program_name'] +@admin.register(Waiver) class WaiverAdmin(admin.ModelAdmin): search_fields = ['name'] -class MemberAdmin(admin.ModelAdmin): - readonly_fields = [field.name for field in Member._meta.get_fields() if field.concrete] - - def has_add_permission(self, request, obj=None): - return False - - def has_delete_permission(self, request, obj=None): - return False - - admin.site.register(CmsRedRiverVeteransScholarship) -admin.site.register(CertificationDefinition, CertificationDefinitionAdmin) -admin.site.register(Certification, CertificationAdmin) -admin.site.register(InstructorOrVendor, InstructorOrVendorAdmin) -admin.site.register(SpecialProgram, SpecialProgramAdmin) -admin.site.register(Waiver, WaiverAdmin) -admin.site.register(Member, MemberAdmin) + diff --git a/paperwork/models.py b/paperwork/models.py index 03ac08c..171038c 100644 --- a/paperwork/models.py +++ b/paperwork/models.py @@ -1,21 +1,6 @@ from django.db import models - -class Member(models.Model): - # TODO: this is only a partial set of fields, may want to expand - uid = models.CharField(primary_key=True, max_length=24) - year_of_birth = models.TextField(db_column='Year of Birth', blank=True, null=True) - account_name = models.TextField(db_column='Account Name', blank=True, null=True) - first_name = models.TextField(db_column='First Name', blank=True, null=True) - last_name = models.TextField(db_column='Last Name', blank=True, null=True) - - def __str__(self): - return f"{self.account_name}" - - class Meta: - managed = False - db_table = 'members' - ordering = ('first_name', 'last_name') +from membershipworks.models import Member class CmsRedRiverVeteransScholarship(models.Model): diff --git a/paperwork/routers.py b/paperwork/routers.py index 4e2249c..c17d73d 100644 --- a/paperwork/routers.py +++ b/paperwork/routers.py @@ -1,8 +1,6 @@ -from .models import Member - - class PaperworkRouter: app_label = 'paperwork' + related_app_labels = {'paperwork', 'membershipworks'} db = 'cms' def db_for_read(self, model, **hints): @@ -16,8 +14,8 @@ class PaperworkRouter: return None def allow_relation(self, obj1, obj2, **hints): - if (isinstance(obj1, Member) and obj2._meta.app_label == self.app_label) or \ - (isinstance(obj2, Member) and obj1._meta.app_label == self.app_label): + if obj1._meta.app_label in self.related_app_labels or \ + obj2._meta.app_label in self.related_app_labels: return True return None @@ -25,26 +23,3 @@ class PaperworkRouter: if db == self.db: return False return None - - -# TODO: this is pretty hacky/special cased -class MembershipWorksRouter: - db = 'membershipworks' - - def db_for_read(self, model, **hints): - if model == Member: - return self.db - return None - - def db_for_write(self, model, **hints): - if model == Member: - return self.db - return None - - def allow_relation(self, obj1, obj2, **hints): - return None - - def allow_migrate(self, db, app_label, model_name=None, **hints): - if db == self.db: - return False - return None