Move Members model to new "membershipworks" app

This commit is contained in:
Adam Goldsmith 2022-02-03 13:45:58 -05:00
parent 192145e32a
commit 4fb8aa74f0
11 changed files with 79 additions and 63 deletions

View File

@ -28,6 +28,7 @@ INSTALLED_APPS = [
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'membershipworks.apps.MembershipworksConfig',
'paperwork.apps.PaperworkConfig', 'paperwork.apps.PaperworkConfig',
] ]
@ -62,7 +63,8 @@ TEMPLATES = [
WSGI_APPLICATION = 'member_paperwork.wsgi.application' WSGI_APPLICATION = 'member_paperwork.wsgi.application'
DATABASE_ROUTERS = ['paperwork.routers.MembershipWorksRouter', 'paperwork.routers.PaperworkRouter'] DATABASE_ROUTERS = ['membershipworks.routers.MembershipWorksRouter',
'paperwork.routers.PaperworkRouter']
# Internationalization # Internationalization

View File

14
membershipworks/admin.py Normal file
View File

@ -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

6
membershipworks/apps.py Normal file
View File

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

18
membershipworks/models.py Normal file
View File

@ -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')

View File

@ -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

3
membershipworks/tests.py Normal file
View File

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

3
membershipworks/views.py Normal file
View File

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

View File

@ -2,44 +2,33 @@ from django.contrib import admin
from .models import (CmsRedRiverVeteransScholarship, from .models import (CmsRedRiverVeteransScholarship,
CertificationDefinition, Certification, CertificationDefinition, Certification,
InstructorOrVendor, SpecialProgram, Waiver, InstructorOrVendor, SpecialProgram, Waiver)
Member)
@admin.register(CertificationDefinition)
class CertificationDefinitionAdmin(admin.ModelAdmin): class CertificationDefinitionAdmin(admin.ModelAdmin):
search_fields = ['certification_name', 'department'] search_fields = ['certification_name', 'department']
@admin.register(Certification)
class CertificationAdmin(admin.ModelAdmin): class CertificationAdmin(admin.ModelAdmin):
search_fields = ['name', 'certification__certification_name', 'certification__department'] search_fields = ['name', 'certification__certification_name', 'certification__department']
@admin.register(InstructorOrVendor)
class InstructorOrVendorAdmin(admin.ModelAdmin): class InstructorOrVendorAdmin(admin.ModelAdmin):
search_fields = ['name'] search_fields = ['name']
@admin.register(SpecialProgram)
class SpecialProgramAdmin(admin.ModelAdmin): class SpecialProgramAdmin(admin.ModelAdmin):
search_fields = ['program_name'] search_fields = ['program_name']
@admin.register(Waiver)
class WaiverAdmin(admin.ModelAdmin): class WaiverAdmin(admin.ModelAdmin):
search_fields = ['name'] 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(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)

View File

@ -1,21 +1,6 @@
from django.db import models from django.db import models
from membershipworks.models import Member
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')
class CmsRedRiverVeteransScholarship(models.Model): class CmsRedRiverVeteransScholarship(models.Model):

View File

@ -1,8 +1,6 @@
from .models import Member
class PaperworkRouter: class PaperworkRouter:
app_label = 'paperwork' app_label = 'paperwork'
related_app_labels = {'paperwork', 'membershipworks'}
db = 'cms' db = 'cms'
def db_for_read(self, model, **hints): def db_for_read(self, model, **hints):
@ -16,8 +14,8 @@ class PaperworkRouter:
return None return None
def allow_relation(self, obj1, obj2, **hints): def allow_relation(self, obj1, obj2, **hints):
if (isinstance(obj1, Member) and obj2._meta.app_label == self.app_label) or \ if obj1._meta.app_label in self.related_app_labels or \
(isinstance(obj2, Member) and obj1._meta.app_label == self.app_label): obj2._meta.app_label in self.related_app_labels:
return True return True
return None return None
@ -25,26 +23,3 @@ class PaperworkRouter:
if db == self.db: if db == self.db:
return False return False
return None 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