Created
August 23, 2019 14:52
-
-
Save fredkingham/49941a5b4e34fb78282427e031252c5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render | |
# urls.py | |
pathway_urls = [] | |
for pathway in Pathway.list(): | |
pathway_urls += [ | |
url(pathway.get_template_url(), PathwayTemplateView], | |
] | |
# pathway | |
class Pathway(object): | |
def __init__(self, request): | |
self.request = request | |
@classmethod | |
def get_url(k): | |
return k.url | |
@classmethod | |
def get_template_url(k): | |
return k.url + "/template.html" | |
def get_template_name(self, *args, **kwargs): | |
pass | |
def get_template_context_data(*a **k): | |
pass | |
# pathway.views | |
class PathwayTemplateView(): | |
def dispatch(self, *args, **kwargs): | |
self.pathway = Pathway.get(kwargs['slug'])(request) | |
super() | |
def get_template_name(self, *a, **k): | |
return self.pathway.get_template_name() | |
def get_context_data(self, *args, **kwargs): | |
return self.pathway.get_template_context_data() | |
# app.pathways | |
class SomeDiagnsisChange(Pathway): | |
slug = "diagnosis-change" | |
url = "/pathway/<slug>/<episode_id>/diagnosis/" | |
template_name = "/some_template/blahblah.html" | |
def get_initial_data(self, *a, **k): | |
return Diagnosis.objects.filter(episode_id=self.pk) | |
def save_data(self, *a, **k): | |
""" | |
Nothing is deleted... | |
""" | |
for diagnosis in some_data: | |
diagnosis["episode_id"] = self.pk | |
Diagnosis.bulk_update_from_dicts(some_data) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment