Skip to content
This repository has been archived by the owner on Feb 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #109 from DHRI-Curriculum:pages
Browse files Browse the repository at this point in the history
Resolves #107
  • Loading branch information
kallewesterling authored Jul 9, 2020
2 parents b7e3c3f + 4543705 commit 9640b13
Show file tree
Hide file tree
Showing 13 changed files with 133 additions and 3,002 deletions.
2,991 changes: 1 addition & 2,990 deletions app/fixtures.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/library/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
app_name = 'library'

urlpatterns = [
path('', views.index, name='index'),
# path('', views.index, name='index'),
path('project/<str:pk>/', views.project_details, name='project_details'),
path('load-projects/', views.lazyload_projects, name='project_lazyloader'),
path('load-readings/', views.lazyload_readings, name='reading_lazyloader'),
Expand Down
22 changes: 22 additions & 0 deletions app/website/migrations/0002_auto_20200709_1837.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.0.7 on 2020-07-09 18:37

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('website', '0001_initial'),
]

operations = [
migrations.RemoveField(
model_name='page',
name='is_homepage',
),
migrations.AddField(
model_name='page',
name='template',
field=models.CharField(default='website/page.html', max_length=100),
),
]
18 changes: 18 additions & 0 deletions app/website/migrations/0003_auto_20200709_1841.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.0.7 on 2020-07-09 18:41

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('website', '0002_auto_20200709_1837'),
]

operations = [
migrations.AlterField(
model_name='page',
name='template',
field=models.CharField(choices=[('website/page.html', 'Standard'), ('workshop/workshop-list.html', 'Workshop list'), ('library/all-library-items.html', 'Library items')], default='website/page.html', max_length=100),
),
]
10 changes: 9 additions & 1 deletion app/website/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
from django.db import models
from django.utils.translation import gettext_lazy as _



class Page(models.Model):
class Template(models.TextChoices):
STANDARD = 'website/page.html', _('Standard')
WORKSHOP_LIST = 'workshop/workshop-list.html', _('Workshop list')
LIBRARY_LIST = 'library/all-library-items.html', _('Library items')

name = models.CharField(max_length=200)
slug = models.CharField(max_length=200, blank=True)
text = models.TextField()
is_homepage = models.BooleanField(default=False)
template = models.CharField(max_length=100, choices=Template.choices, default=Template.STANDARD)

def __str__(self):
return str(self.name)
20 changes: 19 additions & 1 deletion app/website/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
from django.shortcuts import render, get_object_or_404
from .models import Page
from workshop.models import Workshop
from library.models import Project, Reading, Resource, Tutorial
from django.views.decorators.csrf import ensure_csrf_cookie

@ensure_csrf_cookie
def index(request):
page = Page.objects.filter(is_homepage=True).last()
return render(request, 'website/index.html', {'page': page})

@ensure_csrf_cookie
def page(request, page_slug):
payload = dict()

page = get_object_or_404(Page, slug=page_slug)
return render(request, 'website/page.html', {'page': page})
payload['page'] = page

if page.template == Page.Template.WORKSHOP_LIST:
payload['workshops'] = Workshop.objects.all()

if page.template == Page.Template.LIBRARY_LIST:
payload['projects'] = Project.objects.all().order_by('title')[:3]
payload['readings'] = Reading.objects.all().order_by('title')[:3]
payload['resources'] = Resource.objects.all().order_by('title')[:3]
payload['tutorials'] = Tutorial.objects.all().order_by('label')[:3]

return render(request, page.template, payload)
14 changes: 13 additions & 1 deletion app/workshop/templates/library/all-library-items.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,23 @@
{% block hero %}
<div class="px-3 py-3 pt-md-5 pb-md-4 mx-auto text-center">
<h1 class="display-4">Library</h1>
<p class="lead">Introduction text here.</p>
{{ page.text | safe }}
</div>
{% endblock %}


{% block admin_edit %}
<a href="{% url 'admin:website_page_change' page.id %}" class="text-decoration-none">
<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-pen" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" d="M5.707 13.707a1 1 0 0 1-.39.242l-3 1a1 1 0 0 1-1.266-1.265l1-3a1 1 0 0 1 .242-.391L10.086 2.5a2 2 0 0 1 2.828 0l.586.586a2 2 0 0 1 0 2.828l-7.793 7.793zM3 11l7.793-7.793a1 1 0 0 1 1.414 0l.586.586a1 1 0 0 1 0 1.414L5 13l-3 1 1-3z"/>
<path fill-rule="evenodd" d="M9.854 2.56a.5.5 0 0 0-.708 0L5.854 5.855a.5.5 0 0 1-.708-.708L8.44 1.854a1.5 1.5 0 0 1 2.122 0l.293.292a.5.5 0 0 1-.707.708l-.293-.293z"/>
<path d="M13.293 1.207a1 1 0 0 1 1.414 0l.03.03a1 1 0 0 1 .03 1.383L13.5 4 12 2.5l1.293-1.293z"/>
</svg><span class="ml-1 mr-4">Edit page</span>
</a>
{% endblock %}



{% block main %}
<div class="container">
<div class="row">
Expand Down
2 changes: 1 addition & 1 deletion app/workshop/templates/website/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
</div>

<div id="footer" class="container mx-auto">
<footer class="pt-4 my-md-5 pt-md-5 border-top zen-hideaway">
<footer class="pt-4 my-5 border-top zen-hideaway">
{% include 'website/footer.html' %}
</footer>
</div>
Expand Down
10 changes: 10 additions & 0 deletions app/workshop/templates/website/page.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
{% extends 'website/base.html' %}
{% load markdownify %}

{% block admin_edit %}
<a href="{% url 'admin:website_page_change' page.id %}" class="text-decoration-none">
<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-pen" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" d="M5.707 13.707a1 1 0 0 1-.39.242l-3 1a1 1 0 0 1-1.266-1.265l1-3a1 1 0 0 1 .242-.391L10.086 2.5a2 2 0 0 1 2.828 0l.586.586a2 2 0 0 1 0 2.828l-7.793 7.793zM3 11l7.793-7.793a1 1 0 0 1 1.414 0l.586.586a1 1 0 0 1 0 1.414L5 13l-3 1 1-3z"/>
<path fill-rule="evenodd" d="M9.854 2.56a.5.5 0 0 0-.708 0L5.854 5.855a.5.5 0 0 1-.708-.708L8.44 1.854a1.5 1.5 0 0 1 2.122 0l.293.292a.5.5 0 0 1-.707.708l-.293-.293z"/>
<path d="M13.293 1.207a1 1 0 0 1 1.414 0l.03.03a1 1 0 0 1 .03 1.383L13.5 4 12 2.5l1.293-1.293z"/>
</svg><span class="ml-1 mr-4">Edit page</span>
</a>
{% endblock %}


{% block hero %}
<div class="px-3 py-3 pt-md-5 pb-md-4 mx-auto text-left">
Expand Down
8 changes: 3 additions & 5 deletions app/workshop/templates/workshop/workshop-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@
{% block hero %}
<div class="px-3 py-3 pt-md-5 pb-md-4 mx-auto text-center">
<h1 class="display-4">Workshops</h1>
<p class="lead">Introduction text here.</p>
<p class="lead">{{ page.text | safe }}</p>
</div>
{% endblock %}

{% block admin_edit %}

<!--
<a href=" url 'admin:praxis_praxis_change' praxis.id " class="text-decoration-none">
<a href="{% url 'admin:website_page_change' page.id %}" class="text-decoration-none">
<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-pen" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" d="M5.707 13.707a1 1 0 0 1-.39.242l-3 1a1 1 0 0 1-1.266-1.265l1-3a1 1 0 0 1 .242-.391L10.086 2.5a2 2 0 0 1 2.828 0l.586.586a2 2 0 0 1 0 2.828l-7.793 7.793zM3 11l7.793-7.793a1 1 0 0 1 1.414 0l.586.586a1 1 0 0 1 0 1.414L5 13l-3 1 1-3z"/>
<path fill-rule="evenodd" d="M9.854 2.56a.5.5 0 0 0-.708 0L5.854 5.855a.5.5 0 0 1-.708-.708L8.44 1.854a1.5 1.5 0 0 1 2.122 0l.293.292a.5.5 0 0 1-.707.708l-.293-.293z"/>
<path d="M13.293 1.207a1 1 0 0 1 1.414 0l.03.03a1 1 0 0 1 .03 1.383L13.5 4 12 2.5l1.293-1.293z"/>
</svg><span class="ml-1 mr-4">Edit Theory to Practice Page</span>
</svg><span class="ml-1 mr-4">Edit page</span>
</a>
-->

<a target="_blank" href="https://www.github.com/DHRI-Curriculum" class="text-decoration-none">
<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-file-earmark-code" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
Expand Down
2 changes: 1 addition & 1 deletion app/workshop/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
app_name = 'workshop'

urlpatterns = [
path('', views.index, name='index'),
# path('', views.index, name='index'),
path('<str:slug>/', views.frontmatter, name='frontmatter'),
path('<str:slug>/theory-to-practice/', views.praxis, name='praxis'),
path('<str:slug>/lessons/', views.lesson, name='lesson'),
Expand Down
1 change: 1 addition & 0 deletions dhri/django/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
from praxis.models import Praxis
from library.models import Project, Resource, Reading, Tutorial
from lesson.models import Lesson, Challenge, Solution
from website.models import Page
35 changes: 34 additions & 1 deletion populate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dhri import debug
from dhri.django import django, Fixture
from dhri.django.models import Workshop, Praxis, Tutorial, Reading, Frontmatter, LearningObjective, Project, Contributor, Lesson, Challenge, Solution
from dhri.django.models import Workshop, Praxis, Tutorial, Reading, Frontmatter, LearningObjective, Project, Contributor, Lesson, Challenge, Solution, Page
from dhri.interaction import Logger, get_or_default
from dhri.settings import AUTO_PROCESS, FIXTURE_PATH, REPLACEMENTS
from dhri.utils.loader import WebCache
Expand Down Expand Up @@ -298,6 +298,39 @@

iteration += 1

# Add standard setup of pages
collector = dict()
collector['pages'] = []

p = Page(
name = 'Workshops',
slug = 'workshops',
text = '<p class="lead">This is the workshop page.</p>',
template = 'workshop/workshop-list.html'
)
p.save()
collector['pages'].append(p)

p = Page(
name = 'About',
slug = 'about',
text = '<p class="lead">This is the about page.</p>',
template = 'website/page.html'
)
p.save()
collector['pages'].append(p)

p = Page(
name = 'Library',
slug = 'library',
text = '<p class="lead">This is the library page.</p>',
template = 'library/all-library-items.html'
)
p.save()
collector['pages'].append(p)

fixtures.add(collector=collector)

fixtures.save()

from dhri.setup import setup
Expand Down

0 comments on commit 9640b13

Please sign in to comment.