Adds Template Overrides 14/69614/4
authorParker Berberian <pberberian@iol.unh.edu>
Thu, 30 Jan 2020 18:33:35 +0000 (13:33 -0500)
committerParker Berberian <pberberian@iol.unh.edu>
Thu, 30 Jan 2020 21:12:18 +0000 (16:12 -0500)
Changes the structure of the template directories to allow
a new project to define their own set of override templates
that inherit from a common base.

I have slightly modified landing.html here as an example.
In comming changes we will try to move all the "laas" specific
content into the laas directory

Change-Id: I46151be182de901f870debb247b305ea34ae77ba
Signed-off-by: Parker Berberian <pberberian@iol.unh.edu>
66 files changed:
config.env.sample
src/laas_dashboard/settings.py
src/templates/README [new file with mode: 0644]
src/templates/base/account/booking_list.html [moved from src/templates/account/booking_list.html with 100% similarity]
src/templates/base/account/configuration_list.html [moved from src/templates/account/configuration_list.html with 100% similarity]
src/templates/base/account/details.html [moved from src/templates/account/details.html with 100% similarity]
src/templates/base/account/image_list.html [moved from src/templates/account/image_list.html with 100% similarity]
src/templates/base/account/resource_list.html [moved from src/templates/account/resource_list.html with 100% similarity]
src/templates/base/account/user_list.html [moved from src/templates/account/user_list.html with 100% similarity]
src/templates/base/account/userprofile_update_form.html [moved from src/templates/account/userprofile_update_form.html with 100% similarity]
src/templates/base/base.html [moved from src/templates/base.html with 100% similarity]
src/templates/base/booking/booking_calendar.html [moved from src/templates/booking/booking_calendar.html with 100% similarity]
src/templates/base/booking/booking_delete.html [moved from src/templates/booking/booking_delete.html with 100% similarity]
src/templates/base/booking/booking_detail.html [moved from src/templates/booking/booking_detail.html with 100% similarity]
src/templates/base/booking/booking_grid_item.html [moved from src/templates/booking/booking_grid_item.html with 100% similarity]
src/templates/base/booking/booking_list.html [moved from src/templates/booking/booking_list.html with 100% similarity]
src/templates/base/booking/booking_table.html [moved from src/templates/booking/booking_table.html with 100% similarity]
src/templates/base/booking/quick_deploy.html [moved from src/templates/booking/quick_deploy.html with 100% similarity]
src/templates/base/booking/stats.html [moved from src/templates/booking/stats.html with 100% similarity]
src/templates/base/booking/steps/booking_meta.html [moved from src/templates/booking/steps/booking_meta.html with 100% similarity]
src/templates/base/config_bundle/steps/assign_host_roles.html [moved from src/templates/config_bundle/steps/assign_host_roles.html with 100% similarity]
src/templates/base/config_bundle/steps/assign_network_roles.html [moved from src/templates/config_bundle/steps/assign_network_roles.html with 100% similarity]
src/templates/base/config_bundle/steps/config_software.html [moved from src/templates/config_bundle/steps/config_software.html with 100% similarity]
src/templates/base/config_bundle/steps/define_software.html [moved from src/templates/config_bundle/steps/define_software.html with 100% similarity]
src/templates/base/config_bundle/steps/pick_installer.html [moved from src/templates/config_bundle/steps/pick_installer.html with 100% similarity]
src/templates/base/config_bundle/steps/table_formset.html [moved from src/templates/config_bundle/steps/table_formset.html with 100% similarity]
src/templates/base/dashboard/genericselect.html [moved from src/templates/dashboard/genericselect.html with 100% similarity]
src/templates/base/dashboard/host_profile_detail.html [moved from src/templates/dashboard/host_profile_detail.html with 100% similarity]
src/templates/base/dashboard/idf.yaml [moved from src/templates/dashboard/idf.yaml with 100% similarity]
src/templates/base/dashboard/lab_detail.html [moved from src/templates/dashboard/lab_detail.html with 100% similarity]
src/templates/base/dashboard/lab_list.html [moved from src/templates/dashboard/lab_list.html with 100% similarity]
src/templates/base/dashboard/landing.html [moved from src/templates/dashboard/landing.html with 80% similarity]
src/templates/base/dashboard/login.html [moved from src/templates/dashboard/login.html with 100% similarity]
src/templates/base/dashboard/multiple_select_filter_widget.html [moved from src/templates/dashboard/multiple_select_filter_widget.html with 100% similarity]
src/templates/base/dashboard/pdf.yaml [moved from src/templates/dashboard/pdf.yaml with 100% similarity]
src/templates/base/dashboard/resource.html [moved from src/templates/dashboard/resource.html with 100% similarity]
src/templates/base/dashboard/resource_all.html [moved from src/templates/dashboard/resource_all.html with 100% similarity]
src/templates/base/dashboard/resource_detail.html [moved from src/templates/dashboard/resource_detail.html with 100% similarity]
src/templates/base/dashboard/searchable_select_multiple.html [moved from src/templates/dashboard/searchable_select_multiple.html with 100% similarity]
src/templates/base/dashboard/server_table.html [moved from src/templates/dashboard/server_table.html with 100% similarity]
src/templates/base/dashboard/table.html [moved from src/templates/dashboard/table.html with 100% similarity]
src/templates/base/layout.html [moved from src/templates/layout.html with 100% similarity]
src/templates/base/notifier/email_ended.txt [moved from src/templates/notifier/email_ended.txt with 100% similarity]
src/templates/base/notifier/email_expiring.txt [moved from src/templates/notifier/email_expiring.txt with 100% similarity]
src/templates/base/notifier/email_fulfilled.txt [moved from src/templates/notifier/email_fulfilled.txt with 100% similarity]
src/templates/base/notifier/end_booking.html [moved from src/templates/notifier/end_booking.html with 100% similarity]
src/templates/base/notifier/expiring_booking.html [moved from src/templates/notifier/expiring_booking.html with 100% similarity]
src/templates/base/notifier/inbox.html [moved from src/templates/notifier/inbox.html with 100% similarity]
src/templates/base/notifier/new_booking.html [moved from src/templates/notifier/new_booking.html with 100% similarity]
src/templates/base/notifier/notification.html [moved from src/templates/notifier/notification.html with 100% similarity]
src/templates/base/resource/hostprofile_detail.html [moved from src/templates/resource/hostprofile_detail.html with 100% similarity]
src/templates/base/resource/hosts.html [moved from src/templates/resource/hosts.html with 100% similarity]
src/templates/base/resource/mxClient.min.js [moved from src/templates/resource/mxClient.min.js with 100% similarity]
src/templates/base/resource/steps/define_hardware.html [moved from src/templates/resource/steps/define_hardware.html with 100% similarity]
src/templates/base/resource/steps/host_info.html [moved from src/templates/resource/steps/host_info.html with 100% similarity]
src/templates/base/resource/steps/meta_info.html [moved from src/templates/resource/steps/meta_info.html with 100% similarity]
src/templates/base/resource/steps/pod_definition.html [moved from src/templates/resource/steps/pod_definition.html with 100% similarity]
src/templates/base/resource/uncommon.css [moved from src/templates/resource/uncommon.css with 100% similarity]
src/templates/base/rest_framework/api.html [moved from src/templates/rest_framework/api.html with 100% similarity]
src/templates/base/snapshot_workflow/steps/meta.html [moved from src/templates/snapshot_workflow/steps/meta.html with 100% similarity]
src/templates/base/snapshot_workflow/steps/select_host.html [moved from src/templates/snapshot_workflow/steps/select_host.html with 100% similarity]
src/templates/base/workflow/confirm.html [moved from src/templates/workflow/confirm.html with 100% similarity]
src/templates/base/workflow/no_workflow.html [moved from src/templates/workflow/no_workflow.html with 100% similarity]
src/templates/base/workflow/viewport-base.html [moved from src/templates/workflow/viewport-base.html with 100% similarity]
src/templates/base/workflow/viewport-element.html [moved from src/templates/workflow/viewport-element.html with 100% similarity]
src/templates/laas/dashboard/landing.html [new file with mode: 0644]

index 7677c2f..01194b9 100644 (file)
@@ -36,3 +36,6 @@ EMAIL_PORT=
 EMAIL_HOST_USER=
 EMAIL_HOST_PASSWORD=
 DEFAULT_FROM_EMAIL=webmaster@localhost
+
+
+TEMPLATE_OVERRIDE_DIR=laas
index 951ce1a..d41ad0c 100644 (file)
@@ -53,10 +53,23 @@ MIDDLEWARE = [
 
 ROOT_URLCONF = 'laas_dashboard.urls'
 
+TEMPLATE_OVERRIDE = os.environ.get("TEMPLATE_OVERRIDE_DIR", "")  # the user's custom template dir
+TEMPLATE_DIRS = ["base"]  # where all the base templates are
+
+# If the user has a custom template directory,
+# We should search that first. Then we search the
+# root template directory so that we can extend the base
+# templates within the custom template dir.
+if TEMPLATE_OVERRIDE:
+    TEMPLATE_DIRS = [TEMPLATE_OVERRIDE, ""] + TEMPLATE_DIRS
+
+# all template dirs are relative to /project_root/templates/
+dirs = [os.path.join(BASE_DIR, "templates", d) for d in TEMPLATE_DIRS]
+
 TEMPLATES = [
     {
         'BACKEND': 'django.template.backends.django.DjangoTemplates',
-        'DIRS': [os.path.join(BASE_DIR, 'templates')],
+        'DIRS': dirs,
         'APP_DIRS': True,
         'OPTIONS': {
             'context_processors': [
diff --git a/src/templates/README b/src/templates/README
new file mode 100644 (file)
index 0000000..d058036
--- /dev/null
@@ -0,0 +1,25 @@
+We use a special directory structure here that allows you to define
+your own set of templates than inherit from a common base.
+
+To create your own templates:
+
+Create your new directory as a sibling of base/
+    `mkdir my_templates`
+
+Now you can override any template file in base/ by creating a file of the same name in my_templates.
+
+For example, to replace base/booking/booking_table.html,
+you would create my_templates/booking/booking_table.html. Your template will be loaded instead of the original.
+
+
+You can also inherit from the base templates. For example, if you
+wanted to add to base/dashboard/landing.html, you can create
+a template at my_templates/dashboard/landing.html and add this line to
+the top of the file:
+    {% extends base/dashboard/landing.html %}
+
+This way you can add in new {% block %} tags to the parents and define only
+the new content you need without affecting the default behavior.
+
+
+When your template directory is ready, you must add it to your config.env
similarity index 80%
rename from src/templates/dashboard/landing.html
rename to src/templates/base/dashboard/landing.html
index f0fa954..9e45b09 100644 (file)
     <!-- About us -->
     <div class="col-12 col-lg-6 mb-4">
         <h2 class="border-bottom">About Us</h2>
-        <p>The Lab as a Service (LaaS) project aims to help in the development and testing of LFN projects such as
-            OPNFV
-            by hosting hardware and providing access to the community. Currently, the only participating lab is the
-            University of New Hampshire Interoperability Lab (UNH-IOL).</p>
-        <p>To get started, you can request access to a server at the right. PTL's have the ability to design and
-            book a
-            whole block of servers with customized layer2 networks (e.g. a Pharos Pod). Read more here: <a
-                href="https://wiki.opnfv.org/display/INF/Lab+as+a+Service+2.0">LaaS Wiki</a></p>
+        {% block about_us %}
+        <p>Here is some information about us!</p>
+        {% endblock about_us %}
     </div>
 
     <!-- Get started -->
diff --git a/src/templates/laas/dashboard/landing.html b/src/templates/laas/dashboard/landing.html
new file mode 100644 (file)
index 0000000..b1ac7c5
--- /dev/null
@@ -0,0 +1,12 @@
+{% extends "base/dashboard/landing.html" %}
+
+{% block about_us %}
+<p>The Lab as a Service (LaaS) project aims to help in the development and testing of LFN projects such as
+    OPNFV
+    by hosting hardware and providing access to the community. Currently, the only participating lab is the
+    University of New Hampshire Interoperability Lab (UNH-IOL).</p>
+<p>To get started, you can request access to a server at the right. PTL's have the ability to design and
+    book a
+    whole block of servers with customized layer2 networks (e.g. a Pharos Pod). Read more here: <a
+        href="https://wiki.opnfv.org/display/INF/Lab+as+a+Service+2.0">LaaS Wiki</a></p>
+{% endblock about_us %}