From 245afdf4d7cda67d3a50b8b52d32a0024565f6f3 Mon Sep 17 00:00:00 2001
From: Fredrik Jonsson <frjo@xdeb.org>
Date: Fri, 31 Jan 2020 14:47:54 +0100
Subject: [PATCH] Add guide link field to labs and fund, display it on fund/lab
 pages and forms.

---
 .../migrations/0072_add_guide_link_field.py   | 23 +++++++++++++++++++
 opentech/apply/funds/models/applications.py   |  6 +++++
 .../templates/funds/application_base.html     |  6 ++++-
 .../public_funds/includes/fund_apply_cta.html |  5 ++++
 .../src/sass/public/components/_link.scss     | 11 +++++++++
 5 files changed, 50 insertions(+), 1 deletion(-)
 create mode 100644 opentech/apply/funds/migrations/0072_add_guide_link_field.py

diff --git a/opentech/apply/funds/migrations/0072_add_guide_link_field.py b/opentech/apply/funds/migrations/0072_add_guide_link_field.py
new file mode 100644
index 000000000..d2d47cbb5
--- /dev/null
+++ b/opentech/apply/funds/migrations/0072_add_guide_link_field.py
@@ -0,0 +1,23 @@
+# Generated by Django 2.2.9 on 2020-01-31 12:51
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('funds', '0071_update_field_reviewer'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='applicationbase',
+            name='guide_link',
+            field=models.URLField(blank=True, help_text='Link to the apply guide.', max_length=255),
+        ),
+        migrations.AddField(
+            model_name='labbase',
+            name='guide_link',
+            field=models.URLField(blank=True, help_text='Link to the apply guide.', max_length=255),
+        ),
+    ]
diff --git a/opentech/apply/funds/models/applications.py b/opentech/apply/funds/models/applications.py
index d9a3d4d24..2191bd0f6 100644
--- a/opentech/apply/funds/models/applications.py
+++ b/opentech/apply/funds/models/applications.py
@@ -73,6 +73,8 @@ class ApplicationBase(EmailForm, WorkflowStreamForm):  # type: ignore
         related_name='funds',
     )
 
+    guide_link = models.URLField(blank=True, max_length=255, help_text=_('Link to the apply guide.'))
+
     slack_channel = models.CharField(blank=True, max_length=128, help_text=_('The slack #channel for notifications.'))
 
     objects = PageManager.from_queryset(ApplicationBaseManager)()
@@ -110,6 +112,7 @@ class ApplicationBase(EmailForm, WorkflowStreamForm):  # type: ignore
     content_panels = WorkflowStreamForm.content_panels + [
         FieldPanel('approval_form'),
         FieldPanel('reviewers', widget=forms.SelectMultiple(attrs={'size': '16'})),
+        FieldPanel('guide_link'),
         FieldPanel('slack_channel'),
     ]
 
@@ -400,6 +403,8 @@ class LabBase(EmailForm, WorkflowStreamForm, SubmittableStreamForm):  # type: ig
         related_name='labs',
     )
 
+    guide_link = models.URLField(blank=True, max_length=255, help_text=_('Link to the apply guide.'))
+
     slack_channel = models.CharField(blank=True, max_length=128, help_text=_('The slack #channel for notifications.'))
 
     parent_page_types = ['apply_home.ApplyHomePage']
@@ -409,6 +414,7 @@ class LabBase(EmailForm, WorkflowStreamForm, SubmittableStreamForm):  # type: ig
         FieldPanel('approval_form'),
         FieldPanel('lead'),
         FieldPanel('reviewers', widget=forms.SelectMultiple(attrs={'size': '16'})),
+        FieldPanel('guide_link'),
         FieldPanel('slack_channel'),
     ]
 
diff --git a/opentech/apply/funds/templates/funds/application_base.html b/opentech/apply/funds/templates/funds/application_base.html
index a82e3844f..d3ceb7f7a 100644
--- a/opentech/apply/funds/templates/funds/application_base.html
+++ b/opentech/apply/funds/templates/funds/application_base.html
@@ -6,7 +6,6 @@
 {% block header_modifier %}header--light-bg{% endblock %}
 
 {% block content %}
-
 {% if form.errors or form.non_field_errors %}
 <div class="wrapper wrapper--medium wrapper--error">
     <svg class="icon icon--error"><use xlink:href="#error"></use></svg>
@@ -26,6 +25,11 @@
         {# the page has no open rounds and we arent on a round page #}
         <h3>{% blocktrans %}Sorry this {{ page|verbose_name }} is not accepting applications at the moment{% endblocktrans %}</h3>
     {% else%}
+        {% if page.get_parent.specific.guide_link %}
+            <a href="{{ page.get_parent.specific.guide_link }}" class="link link--fixed-apply">
+                {% trans "Application guide" %}
+            </a>
+        {% endif %}
         <form class="form application-form" action="/test500/" method="POST" enctype="multipart/form-data">
             {{ form.media }}
             {% csrf_token %}
diff --git a/opentech/public/funds/templates/public_funds/includes/fund_apply_cta.html b/opentech/public/funds/templates/public_funds/includes/fund_apply_cta.html
index 9e8d0b196..73c9e2241 100644
--- a/opentech/public/funds/templates/public_funds/includes/fund_apply_cta.html
+++ b/opentech/public/funds/templates/public_funds/includes/fund_apply_cta.html
@@ -15,6 +15,11 @@
             <a href="{% pageurl apply_page %}" class="link link--button-secondary">
                 {% trans "Apply for this" %} {% verbose_name apply_page %}
             </a>
+            {% if apply_page.specific.guide_link %}
+                <a href="{{ apply_page.specific.guide_link }}" class="link link--button-tertiary">
+                    {% trans "Application guide" %}
+                </a>
+            {% endif %}
         {% else %}
             <h3 class="heading heading--no-margin">
                 {% trans "CLOSED" %}
diff --git a/opentech/static_src/src/sass/public/components/_link.scss b/opentech/static_src/src/sass/public/components/_link.scss
index 7d4790b20..95288fd06 100644
--- a/opentech/static_src/src/sass/public/components/_link.scss
+++ b/opentech/static_src/src/sass/public/components/_link.scss
@@ -32,6 +32,17 @@
         @include button($color--purple, darken($color--purple, 20%));
     }
 
+    &--button-tertiary {
+        @include button(transparent, darken($color--purple, 20%));
+        color: $color--purple;
+        border-color: $color--purple;
+
+        &:focus,
+        &:hover {
+            color: $color--white;
+        }
+    }
+
     &--button-transparent {
         @include button(transparent, $color--darkest-blue);
         color: $color--white;
-- 
GitLab