adds resume and streaming block
This commit is contained in:
parent
b6554fbf83
commit
b2001195fc
18 changed files with 223 additions and 0 deletions
47
base/blocks.py
Normal file
47
base/blocks.py
Normal file
|
@ -0,0 +1,47 @@
|
|||
from wagtail.blocks import (
|
||||
CharBlock,
|
||||
ChoiceBlock,
|
||||
RichTextBlock,
|
||||
StreamBlock,
|
||||
StructBlock,
|
||||
)
|
||||
from wagtail.embeds.blocks import EmbedBlock
|
||||
from wagtail.images.blocks import ImageChooserBlock
|
||||
|
||||
|
||||
class ImageBlock(StructBlock):
|
||||
image = ImageChooserBlock(required=True)
|
||||
caption = CharBlock(required=False)
|
||||
attribution = CharBlock(required=False)
|
||||
|
||||
class Meta:
|
||||
icon = "image"
|
||||
template = "base/blocks/image_block.html"
|
||||
|
||||
|
||||
class HeadingBlock(StructBlock):
|
||||
heading_text = CharBlock(classname="title", required=True)
|
||||
size = ChoiceBlock(
|
||||
choices=[
|
||||
("", "Select a heading size"),
|
||||
("h2", "H2"),
|
||||
("h3", "H3"),
|
||||
("h4", "H4"),
|
||||
],
|
||||
blank=True,
|
||||
required=False,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
icon = "title"
|
||||
template = "base/blocks/heading_block.html"
|
||||
|
||||
|
||||
class BaseStreamBlock(StreamBlock):
|
||||
heading_block = HeadingBlock()
|
||||
paragraph_block = RichTextBlock(icon="pilcrow")
|
||||
image_block = ImageBlock()
|
||||
embed_block = EmbedBlock(
|
||||
help_text="Insert a URL to embed. For example, https://www.youtube.com/watch?v=SGJFWirQ3ks",
|
||||
icon="media",
|
||||
)
|
7
base/templates/base/blocks/heading_block.html
Normal file
7
base/templates/base/blocks/heading_block.html
Normal file
|
@ -0,0 +1,7 @@
|
|||
{% if self.size == 'h2' %}
|
||||
<h2>{{ self.heading_text }}</h2>
|
||||
{% elif self.size == 'h3' %}
|
||||
<h3>{{ self.heading_text }}</h3>
|
||||
{% elif self.size == 'h4' %}
|
||||
<h4>{{ self.heading_text }}</h4>
|
||||
{% endif %}
|
6
base/templates/base/blocks/image_block.html
Normal file
6
base/templates/base/blocks/image_block.html
Normal file
|
@ -0,0 +1,6 @@
|
|||
{% load wagtailimages_tags %}
|
||||
|
||||
<figure>
|
||||
{% image self.image fill-600x338 loading="lazy" %}
|
||||
<figcaption>{{ self.caption }} - {{ self.attribution }}</figcaption>
|
||||
</figure>
|
|
@ -24,6 +24,7 @@ BASE_DIR = os.path.dirname(PROJECT_DIR)
|
|||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
"portfolio",
|
||||
"base",
|
||||
"blog",
|
||||
"home",
|
||||
|
|
BIN
media/images/moon_and_planets_design.2e16d0ba.fill-600x338.jpg
Normal file
BIN
media/images/moon_and_planets_design.2e16d0ba.fill-600x338.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
0
portfolio/__init__.py
Normal file
0
portfolio/__init__.py
Normal file
3
portfolio/admin.py
Normal file
3
portfolio/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
6
portfolio/apps.py
Normal file
6
portfolio/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class PortfolioConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'portfolio'
|
39
portfolio/blocks.py
Normal file
39
portfolio/blocks.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
# import CharBlock, ListBlock, PageChooserBlock, PageChooserBlock, RichTextBlock, and StructBlock:
|
||||
from wagtail.blocks import (
|
||||
CharBlock,
|
||||
ListBlock,
|
||||
PageChooserBlock,
|
||||
RichTextBlock,
|
||||
StructBlock,
|
||||
)
|
||||
|
||||
# import ImageChooserBlock:
|
||||
from wagtail.images.blocks import ImageChooserBlock
|
||||
|
||||
from base.blocks import BaseStreamBlock
|
||||
|
||||
# add CardBlock:
|
||||
class CardBlock(StructBlock):
|
||||
heading = CharBlock()
|
||||
text = RichTextBlock(features=["bold", "italic", "link"])
|
||||
image = ImageChooserBlock(required=False)
|
||||
|
||||
class Meta:
|
||||
icon = "form"
|
||||
template = "portfolio/blocks/card_block.html"
|
||||
|
||||
# add FeaturedPostsBlock:
|
||||
class FeaturedPostsBlock(StructBlock):
|
||||
heading = CharBlock()
|
||||
text = RichTextBlock(features=["bold", "italic", "link"], required=False)
|
||||
posts = ListBlock(PageChooserBlock(page_type="blog.BlogPage"))
|
||||
|
||||
class Meta:
|
||||
icon = "folder-open-inverse"
|
||||
template = "portfolio/blocks/featured_posts_block.html"
|
||||
|
||||
class PortfolioStreamBlock(BaseStreamBlock):
|
||||
# delete the pass statement
|
||||
|
||||
card = CardBlock(group="Sections")
|
||||
featured_posts = FeaturedPostsBlock(group="Sections")
|
31
portfolio/migrations/0001_initial.py
Normal file
31
portfolio/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
# Generated by Django 5.0.2 on 2024-03-01 18:40
|
||||
|
||||
import django.db.models.deletion
|
||||
import wagtail.blocks
|
||||
import wagtail.embeds.blocks
|
||||
import wagtail.fields
|
||||
import wagtail.images.blocks
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('wagtailcore', '0091_remove_revision_submitted_for_moderation'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='PortfolioPage',
|
||||
fields=[
|
||||
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.page')),
|
||||
('body', wagtail.fields.StreamField([('heading_block', wagtail.blocks.StructBlock([('heading_text', wagtail.blocks.CharBlock(form_classname='title', required=True)), ('size', wagtail.blocks.ChoiceBlock(blank=True, choices=[('', 'Select a heading size'), ('h2', 'H2'), ('h3', 'H3'), ('h4', 'H4')], required=False))])), ('paragraph_block', wagtail.blocks.RichTextBlock(icon='pilcrow')), ('image_block', wagtail.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock(required=True)), ('caption', wagtail.blocks.CharBlock(required=False)), ('attribution', wagtail.blocks.CharBlock(required=False))])), ('embed_block', wagtail.embeds.blocks.EmbedBlock(help_text='Insert a URL to embed. For example, https://www.youtube.com/watch?v=SGJFWirQ3ks', icon='media'))], blank=True, help_text='Use this section to list your projects and skills.')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
bases=('wagtailcore.page',),
|
||||
),
|
||||
]
|
22
portfolio/migrations/0002_alter_portfoliopage_body.py
Normal file
22
portfolio/migrations/0002_alter_portfoliopage_body.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
# Generated by Django 5.0.2 on 2024-03-01 18:41
|
||||
|
||||
import wagtail.blocks
|
||||
import wagtail.embeds.blocks
|
||||
import wagtail.fields
|
||||
import wagtail.images.blocks
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('portfolio', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='portfoliopage',
|
||||
name='body',
|
||||
field=wagtail.fields.StreamField([('heading_block', wagtail.blocks.StructBlock([('heading_text', wagtail.blocks.CharBlock(form_classname='title', required=True)), ('size', wagtail.blocks.ChoiceBlock(blank=True, choices=[('', 'Select a heading size'), ('h2', 'H2'), ('h3', 'H3'), ('h4', 'H4')], required=False))])), ('paragraph_block', wagtail.blocks.RichTextBlock(icon='pilcrow')), ('image_block', wagtail.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock(required=True)), ('caption', wagtail.blocks.CharBlock(required=False)), ('attribution', wagtail.blocks.CharBlock(required=False))])), ('embed_block', wagtail.embeds.blocks.EmbedBlock(help_text='Insert a URL to embed. For example, https://www.youtube.com/watch?v=SGJFWirQ3ks', icon='media')), ('card', wagtail.blocks.StructBlock([('heading', wagtail.blocks.CharBlock()), ('text', wagtail.blocks.RichTextBlock(features=['bold', 'italic', 'link'])), ('image', wagtail.images.blocks.ImageChooserBlock(required=False))], group='Sections')), ('featured_posts', wagtail.blocks.StructBlock([('heading', wagtail.blocks.CharBlock()), ('text', wagtail.blocks.RichTextBlock(features=['bold', 'italic', 'link'], required=False)), ('posts', wagtail.blocks.ListBlock(wagtail.blocks.PageChooserBlock(page_type=['blog.BlogPage'])))], group='Sections'))], blank=True, help_text='Use this section to list your projects and skills.'),
|
||||
),
|
||||
]
|
0
portfolio/migrations/__init__.py
Normal file
0
portfolio/migrations/__init__.py
Normal file
20
portfolio/models.py
Normal file
20
portfolio/models.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
from wagtail.models import Page
|
||||
from wagtail.fields import StreamField
|
||||
from wagtail.admin.panels import FieldPanel
|
||||
|
||||
from portfolio.blocks import PortfolioStreamBlock
|
||||
|
||||
|
||||
class PortfolioPage(Page):
|
||||
parent_page_types = ["home.HomePage"]
|
||||
|
||||
body = StreamField(
|
||||
PortfolioStreamBlock(),
|
||||
blank=True,
|
||||
use_json_field=True,
|
||||
help_text="Use this section to list your projects and skills.",
|
||||
)
|
||||
|
||||
content_panels = Page.content_panels + [
|
||||
FieldPanel("body"),
|
||||
]
|
8
portfolio/templates/portfolio/blocks/card_block.html
Normal file
8
portfolio/templates/portfolio/blocks/card_block.html
Normal file
|
@ -0,0 +1,8 @@
|
|||
{% load wagtailcore_tags wagtailimages_tags %}
|
||||
<div class="card">
|
||||
<h3>{{ self.heading }}</h3>
|
||||
<div>{{ self.text|richtext }}</div>
|
||||
{% if self.image %}
|
||||
{% image self.image width-480 %}
|
||||
{% endif %}
|
||||
</div>
|
|
@ -0,0 +1,16 @@
|
|||
{% load wagtailcore_tags %}
|
||||
<div>
|
||||
<h2>{{ self.heading }}</h2>
|
||||
{% if self.text %}
|
||||
<p>{{ self.text|richtext }}</p>
|
||||
{% endif %}
|
||||
|
||||
<div class="grid">
|
||||
{% for page in self.posts %}
|
||||
<div class="card">
|
||||
<p><a href="{% pageurl page %}">{{ page.title }}</a></p>
|
||||
<p>{{ page.specific.date }}</p>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
11
portfolio/templates/portfolio/portfolio_page.html
Normal file
11
portfolio/templates/portfolio/portfolio_page.html
Normal file
|
@ -0,0 +1,11 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% load wagtailcore_tags wagtailimages_tags %}
|
||||
|
||||
{% block body_class %}template-portfolio{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>{{ page.title }}</h1>
|
||||
|
||||
{{ page.body }}
|
||||
{% endblock %}
|
3
portfolio/tests.py
Normal file
3
portfolio/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
3
portfolio/views.py
Normal file
3
portfolio/views.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
Loading…
Add table
Add a link
Reference in a new issue