You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2019/10/17 23:25:50 UTC

[airavata-django-portal] branch master updated: Wagtail export/import documentation

This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git


The following commit(s) were added to refs/heads/master by this push:
     new 744da51  Wagtail export/import documentation
744da51 is described below

commit 744da51d8280530376adc991b3572764b412cf6d
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Thu Oct 17 19:25:35 2019 -0400

    Wagtail export/import documentation
---
 .../base/management/commands/load_cms_data.py      | 38 +++++++++
 docs/dev/wagtail_export.md                         | 95 ++++++++++++++++++++++
 mkdocs.yml                                         |  1 +
 3 files changed, 134 insertions(+)

diff --git a/django_airavata/wagtailapps/base/management/commands/load_cms_data.py b/django_airavata/wagtailapps/base/management/commands/load_cms_data.py
new file mode 100644
index 0000000..e83a7a6
--- /dev/null
+++ b/django_airavata/wagtailapps/base/management/commands/load_cms_data.py
@@ -0,0 +1,38 @@
+import os
+
+from django.conf import settings
+from django.core.management import call_command
+from django.core.management.base import BaseCommand
+from wagtail.core.models import Page, Site
+
+
+class Command(BaseCommand):
+
+    def add_arguments(self, parser):
+        parser.add_argument('filename')
+
+    def handle(self, **options):
+        fixtures_dir = os.path.join(
+            settings.BASE_DIR,
+            'django_airavata',
+            'wagtailapps',
+            'base',
+            'fixtures')
+        # options['filename'] may or may not contain the .json extension
+        fixture_file = os.path.join(fixtures_dir, options['filename'])
+        if not os.path.exists(fixture_file):
+            fixture_file = os.path.join(
+                fixtures_dir, f"{options['filename']}.json")
+
+        # Wagtail creates default Site and Page instances during install, but we already have
+        # them in the data load. Remove the auto-generated ones.
+        if Site.objects.filter(hostname='localhost').exists():
+            Site.objects.get(hostname='localhost').delete()
+        if Page.objects.filter(
+                title='Welcome to your new Wagtail site!').exists():
+            Page.objects.get(
+                title='Welcome to your new Wagtail site!').delete()
+
+        call_command('loaddata', fixture_file, verbosity=0)
+
+        print(f"{options['filename']} is loaded successfully....!")
diff --git a/docs/dev/wagtail_export.md b/docs/dev/wagtail_export.md
new file mode 100644
index 0000000..bc609f3
--- /dev/null
+++ b/docs/dev/wagtail_export.md
@@ -0,0 +1,95 @@
+# Creating a Wagtail Export
+
+You can create an initial set of Wagtail pages with theming and images and then
+export them for loading into another Django portal instance. These can be used
+to create starter themes or to fully develop a themed set of pages for an
+Airavata Django Portal.
+
+These steps document how to create one of these exports locally.
+
+## Getting Started
+
+1. Clone and setup the
+   [Airavata Django Portal](https://github.com/apache/airavata-django-portal)
+   locally. Follow the instructions in the README.md.
+2. Edit your `django_airavata/settings_local.py` file and add the following at
+   the bottom:
+
+```python
+AUTHENTICATION_BACKENDS = ['django.contrib.auth.backends.ModelBackend']
+MIDDLEWARE = [
+    'django.middleware.security.SecurityMiddleware',
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.middleware.common.CommonMiddleware',
+    'django.middleware.csrf.CsrfViewMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+    'django.contrib.messages.middleware.MessageMiddleware',
+    'django.middleware.clickjacking.XFrameOptionsMiddleware',
+    # Wagtail related middleware
+    'wagtail.core.middleware.SiteMiddleware',
+    'wagtail.contrib.redirects.middleware.RedirectMiddleware',
+]
+```
+
+This allows you to log in locally, without needing to setup Keycloak or have an
+Airavata backend running.
+
+3. Create a superuser account. You'll use this to log into wagtail and edit
+   pages:
+
+```
+python manage.py createsuperuser
+```
+
+4. You can either start from scratch, or start from an existing Wagtail export.
+   If you don't want to start from an export you can start the server, log into
+   <http://localhost:8000/cms> and start creating pages.
+
+5. To start from an existing Wagtail export, first remove the database.
+
+```
+rm db.sqlite3
+```
+
+6. Run `python manage.py migrate`.
+
+7. Run `python manage.py load_cms_data FILENAME`, where FILENAME is the name of
+   one of the Wagtail exports in
+   [fixtures](https://github.com/apache/airavata-django-portal/tree/master/django_airavata/wagtailapps/base/fixtures)
+   directory. For example, you can run
+
+```
+python manage.py load_cms_data default.json
+```
+
+## Creating the Wagtail export
+
+Once you have the pages just the way you want them, you can now export them.
+
+1. Run the following to export the Wagtail settings into a JSON file in the
+   fixtures directory:
+
+```bash
+python manage.py dumpdata --natural-foreign --exclude auth.permission \
+  --exclude contenttypes --indent 4 > django_airavata/wagtailapps/base/fixtures/myexport.json
+```
+
+Where you can change `myexport` to whatever you want to meaningfully name the
+export file.
+
+2. Commit any media files that were added as part of creating the Wagtail pages.
+
+## Importing a Wagtail export
+
+You can import a Wagtail export by running the following command on a newly
+created Django instance.
+
+1. Make sure you have the virtual environment activated.
+2. Run
+
+```bash
+python manage.py load_cms_data myexport.json
+```
+
+where `myexport.json` should match the name that you gave the file when
+exporting it.
diff --git a/mkdocs.yml b/mkdocs.yml
index af6dfd8..7740248 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -11,6 +11,7 @@ nav:
     - Adding a Custom Django App: dev/custom_django_app.md
     - Developing the Frontend: dev/developing_frontend.md
     - Developing the Backend: dev/developing_backend.md
+    - Developing a Wagtail Export (theme): dev/wagtail_export.md
   - Administrator Guide:
     - Tusd Installation: admin/tusd.md
   - Tutorials: