Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Outline for the Topics page #153

Merged
merged 10 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions website/theses/migrations/0039_auto_20200831_0648.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.1 on 2020-08-31 06:48

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('theses', '0038_coach'),
]

operations = [
migrations.RenameField(
model_name='thesisdiscipline',
old_name='description',
new_name='description_legacy',
),
]
28 changes: 28 additions & 0 deletions website/theses/migrations/0040_auto_20200831_0854.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 2.2.1 on 2020-08-31 08:54

from django.db import migrations
import theses.models
import wagtail.core.blocks
import wagtail.core.fields
import wagtail.embeds.blocks
import wagtail.images.blocks


class Migration(migrations.Migration):

dependencies = [
('theses', '0039_auto_20200831_0648'),
]

operations = [
migrations.AddField(
model_name='thesisdiscipline',
name='introduction',
field=wagtail.core.fields.RichTextField(blank=True),
),
migrations.AddField(
model_name='thesisdiscipline',
name='topics',
field=wagtail.core.fields.StreamField([('heading', wagtail.core.blocks.CharBlock(classname='full title')), ('heading_linkable', theses.models.HeadingBlock(features=['bold', 'italic', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'], help_text='heading text')), ('paragraph', theses.models.AllHeadingsRichTextBlock()), ('image', wagtail.images.blocks.ImageChooserBlock()), ('embed', wagtail.embeds.blocks.EmbedBlock()), ('rawHtml', wagtail.core.blocks.RawHTMLBlock())], blank=True, null=True),
),
]
48 changes: 36 additions & 12 deletions website/theses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from wagtail.core import blocks
from wagtail.core.fields import RichTextField, StreamField
from wagtail.core.models import Page
from wagtail.core.rich_text import RichText
from wagtail.embeds.blocks import EmbedBlock
from wagtail.documents.edit_handlers import DocumentChooserPanel
from wagtail.images.blocks import ImageChooserBlock
Expand Down Expand Up @@ -99,9 +98,33 @@ def __str__(self):
@register_snippet
class ThesisDiscipline(models.Model):
name = models.CharField(max_length=100, blank=False, unique=True)
description = RichTextField(blank=True)
introduction = RichTextField(blank=True)
description_legacy = RichTextField(blank=True)
topics = StreamField(
[
("heading", blocks.CharBlock(classname="full title")),
(
"heading_linkable",
HeadingBlock(
help_text="heading text",
features=["bold", "italic", "h1", "h2", "h3", "h4", "h5", "h6"],
),
),
("paragraph", AllHeadingsRichTextBlock()),
("image", ImageChooserBlock()),
("embed", EmbedBlock()),
("rawHtml", blocks.RawHTMLBlock()),
],
null=True,
blank=True,
)

panels = [FieldPanel("name"), FieldPanel("description")]
panels = [
FieldPanel("name"),
FieldPanel("introduction"),
StreamFieldPanel("topics"),
FieldPanel("description_legacy"),
]

def __str__(self):
return self.name
Expand Down Expand Up @@ -155,7 +178,7 @@ def get_standard_streamfield():
)


class ThesisSearch(Page):
class ThesisSearch(Page, FlatLinksOutline):
parent_page_types = ["theses.ThesisIndexPage"]

body = get_standard_streamfield()
Expand All @@ -167,19 +190,20 @@ class ThesisSearch(Page):
StreamFieldPanel("footer"),
]

def _get_discipline_by_name(self, name) -> ThesisDiscipline:
return ThesisDiscipline.objects.get(name=name)

def get_context(self, request, *args, form=None, **kwargs):
context = super().get_context(request, *args, **kwargs)
if "discipline" in request.GET:
discipline_name = request.GET["discipline"]
discipline = ThesisDiscipline.objects.get(name=discipline_name)
selected_discipline = discipline_name
selected_discipline_description = discipline.description
else:
selected_discipline = None
selected_discipline_description = None
discipline = self._get_discipline_by_name(name=discipline_name)
context["selectedDiscipline"] = discipline_name
context["descriptionLegacy"] = discipline.description_legacy
context["introduction"] = discipline.introduction
context["disciplineTopics"] = discipline.topics
context["topicsOutline"] = self.get_outline(discipline.topics.stream_data)

context["selectedDiscipline"] = selected_discipline
context["selectedDisciplineDescription"] = selected_discipline_description
context["disciplines"] = ThesisDiscipline.objects.all().order_by("name")
context["form"] = form or TopicInterestForm()

Expand Down
1 change: 0 additions & 1 deletion website/theses/outline_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ def _get_raw_heading(_data):
keys = ("type", "value", "id")
_data = dict(zip(keys, _data))

print("data:", _data)
if not isinstance(_data, dict):
return None

Expand Down
68 changes: 65 additions & 3 deletions website/theses/templates/theses/thesis_search.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@
{% load menu_tags %}

{% block content %}

<style>
.table-outline {
outline-style: solid;
outline-color: rgb(204, 204, 204);
outline-width: 2px;
}

.block-embed {
max-width: 550px;
margin-left: 0px;
}

.block-image img {
max-height: 360px;
width: auto;
}
</style>

<main class="hero" style="background-image: url({% static "img/hero-topics-theses.jpg" %});">
<div class="jumbotron">
<div class="container">
Expand Down Expand Up @@ -76,11 +95,53 @@ <h3 id="disciplines" class="text-uppercase mb-4">
</div>
</div>

{% if selectedDisciplineDescription %}
{% if introduction %}
<div class="row mb-2">
<div class="col-md-12 all-tags">
<div class="mb-3">
<p>{{ introduction | safe }}</p>
</div>
</div>
</div>
{% endif %}

{% if topicsOutline %}
<div class="row mb-3">
<div class="col-md-12 all-tags">
<table class="table table-responsive table-outline mt-3 mb-2" role="grid">

<tbody class=".table-hover .table-striped">

<tr class="row-2" role="row">
<td>
<div class="panel clearfix">
{% include_block topicsOutline %}

</div>
</td>
</tr>
</table>

</div>
</div>
{% endif %}


{% if disciplineTopics %}
<div class="row mb-5">
<div class="col-md-12 all-tags">
<div class="mb-3">
<p>{{ disciplineTopics | safe }}</p>
</div>
</div>
</div>
{% endif %}

{% if descriptionLegacy %}
<div class="row mb-5">
<div class="col-md-12 all-tags">
<div class="mb-3">
<p>{{ selectedDisciplineDescription | safe }}</p>
<p>{{ descriptionLegacy | safe }}</p>
</div>
</div>
</div>
Expand All @@ -89,6 +150,7 @@ <h3 id="disciplines" class="text-uppercase mb-4">
<!-- After disciplines -->
<div class="row my-5">
<div class="col">
<a id="if-interested-in-topics" style="position: relative;top: -5em;"></a>
{% include_block page.footer %}

<div id="topic-interest-form">
Expand Down Expand Up @@ -138,7 +200,7 @@ <h3 id="disciplines" class="text-uppercase mb-4">
$(document).ready(function () {
if (
window.location.search.includes("discipline")
&& window.location.hash !== "disciplines"
&& window.location.hash == ""
) {
window.location.hash = "disciplines";
}
Expand Down