Skip to content

Commit

Permalink
Merge pull request #176 from scieloorg/tk164
Browse files Browse the repository at this point in the history
Atualiza a versão do wagtail para 4.2
  • Loading branch information
gitnnolabs authored Mar 16, 2023
2 parents 82ca16b + 21a8fd1 commit 111faf1
Show file tree
Hide file tree
Showing 223 changed files with 10,237 additions and 5,091 deletions.
4 changes: 2 additions & 2 deletions blog/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class BlogConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'blog'
default_auto_field = "django.db.models.BigAutoField"
name = "blog"
138 changes: 105 additions & 33 deletions blog/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,72 +4,144 @@
import django.db.models.deletion
import modelcluster.contrib.taggit
import modelcluster.fields
import wagtail.core.fields
import wagtail.fields


class Migration(migrations.Migration):

initial = True

dependencies = [
('wagtailimages', '0023_add_choose_permissions'),
('wagtailcore', '0066_collection_management_permissions'),
('taggit', '0004_alter_taggeditem_content_type_alter_taggeditem_tag'),
("wagtailimages", "0023_add_choose_permissions"),
("wagtailcore", "0066_collection_management_permissions"),
("taggit", "0004_alter_taggeditem_content_type_alter_taggeditem_tag"),
]

operations = [
migrations.CreateModel(
name='BlogIndexPage',
name="BlogIndexPage",
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')),
('intro', wagtail.core.fields.RichTextField(blank=True)),
(
"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",
),
),
("intro", wagtail.fields.RichTextField(blank=True)),
],
options={
'abstract': False,
"abstract": False,
},
bases=('wagtailcore.page',),
bases=("wagtailcore.page",),
),
migrations.CreateModel(
name='BlogPage',
name="BlogPage",
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')),
('date', models.DateField(verbose_name='Post date')),
('intro', models.CharField(max_length=250)),
('body', wagtail.core.fields.RichTextField(blank=True)),
(
"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",
),
),
("date", models.DateField(verbose_name="Post date")),
("intro", models.CharField(max_length=250)),
("body", wagtail.fields.RichTextField(blank=True)),
],
options={
'abstract': False,
"abstract": False,
},
bases=('wagtailcore.page',),
bases=("wagtailcore.page",),
),
migrations.CreateModel(
name='BlogPageTag',
name="BlogPageTag",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('content_object', modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='tagged_items', to='blog.blogpage')),
('tag', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='blog_blogpagetag_items', to='taggit.tag')),
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"content_object",
modelcluster.fields.ParentalKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="tagged_items",
to="blog.blogpage",
),
),
(
"tag",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="blog_blogpagetag_items",
to="taggit.tag",
),
),
],
options={
'abstract': False,
"abstract": False,
},
),
migrations.CreateModel(
name='BlogPageGalleryImage',
name="BlogPageGalleryImage",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('sort_order', models.IntegerField(blank=True, editable=False, null=True)),
('caption', models.CharField(blank=True, max_length=250)),
('image', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='wagtailimages.image')),
('page', modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='gallery_images', to='blog.blogpage')),
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"sort_order",
models.IntegerField(blank=True, editable=False, null=True),
),
("caption", models.CharField(blank=True, max_length=250)),
(
"image",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="+",
to="wagtailimages.image",
),
),
(
"page",
modelcluster.fields.ParentalKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="gallery_images",
to="blog.blogpage",
),
),
],
options={
'ordering': ['sort_order'],
'abstract': False,
"ordering": ["sort_order"],
"abstract": False,
},
),
migrations.AddField(
model_name='blogpage',
name='tags',
field=modelcluster.contrib.taggit.ClusterTaggableManager(blank=True, help_text='A comma-separated list of tags.', through='blog.BlogPageTag', to='taggit.Tag', verbose_name='Tags'),
model_name="blogpage",
name="tags",
field=modelcluster.contrib.taggit.ClusterTaggableManager(
blank=True,
help_text="A comma-separated list of tags.",
through="blog.BlogPageTag",
to="taggit.Tag",
verbose_name="Tags",
),
),
]
56 changes: 28 additions & 28 deletions blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.conf import settings

from wagtail.core.models import Page, Orderable
from wagtail.models import Page, Orderable

from wagtail.core.fields import RichTextField
from wagtail.admin.edit_handlers import FieldPanel, InlinePanel, MultiFieldPanel
from wagtail.fields import RichTextField
from wagtail.admin.panels import FieldPanel, InlinePanel, MultiFieldPanel

from modelcluster.fields import ParentalKey
from modelcluster.contrib.taggit import ClusterTaggableManager
from taggit.models import TaggedItemBase

from wagtail.images.edit_handlers import ImageChooserPanel
from wagtail.search import index


Expand All @@ -20,11 +19,11 @@ class BlogIndexPage(Page):

def get_context(self, request):
context = super().get_context(request)
all_posts = self.get_children().live().order_by('-blogpage__date')
all_posts = self.get_children().live().order_by("-blogpage__date")
all_tags = set()

if request.GET.get('tag'):
all_posts = all_posts.filter(blogpage__tags__slug=request.GET.get('tag'))
if request.GET.get("tag"):
all_posts = all_posts.filter(blogpage__tags__slug=request.GET.get("tag"))

for post in all_posts.exclude(blogpage__tags=None)[0:100]:
for tag in post.specific.tags.all():
Expand All @@ -46,21 +45,17 @@ def get_context(self, request):
# Then return the last page
posts = paginator.page(paginator.num_pages)

context['posts'] = posts
context['tags'] = all_tags
context["posts"] = posts
context["tags"] = all_tags

return context

content_panels = Page.content_panels + [
FieldPanel('intro', classname="full")
]
content_panels = Page.content_panels + [FieldPanel("intro", classname="full")]


class BlogPageTag(TaggedItemBase):
content_object = ParentalKey(
'BlogPage',
related_name='tagged_items',
on_delete=models.CASCADE
"BlogPage", related_name="tagged_items", on_delete=models.CASCADE
)


Expand All @@ -78,29 +73,34 @@ def main_image(self):
return None

search_fields = Page.search_fields + [
index.SearchField('intro'),
index.SearchField('body'),
index.SearchField("intro"),
index.SearchField("body"),
]

content_panels = Page.content_panels + [
MultiFieldPanel([
FieldPanel('date'),
FieldPanel('tags'),
], heading="Blog information"),
FieldPanel('intro'),
FieldPanel('body'),
InlinePanel('gallery_images', label="Gallery images"),
MultiFieldPanel(
[
FieldPanel("date"),
FieldPanel("tags"),
],
heading="Blog information",
),
FieldPanel("intro"),
FieldPanel("body"),
InlinePanel("gallery_images", label="Gallery images"),
]


class BlogPageGalleryImage(Orderable):
page = ParentalKey(BlogPage, on_delete=models.CASCADE, related_name='gallery_images')
page = ParentalKey(
BlogPage, on_delete=models.CASCADE, related_name="gallery_images"
)
image = models.ForeignKey(
'wagtailimages.Image', on_delete=models.CASCADE, related_name='+'
"wagtailimages.Image", on_delete=models.CASCADE, related_name="+"
)
caption = models.CharField(blank=True, max_length=250)

panels = [
ImageChooserPanel('image'),
FieldPanel('caption'),
FieldPanel("image"),
FieldPanel("caption"),
]
2 changes: 1 addition & 1 deletion compose/local/django/start
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ set -o nounset


python manage.py migrate
python manage.py runserver_plus 0.0.0.0:8000
python manage.py runserver_plus 0.0.0.0:8000
Loading

0 comments on commit 111faf1

Please sign in to comment.