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

Feat: Adiciona extensão para configurar dados Meta das páginas #139

Merged
merged 2 commits into from
Oct 31, 2023
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
21 changes: 19 additions & 2 deletions app/contrib/campaign/admin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
from django.contrib import admin
from cms.extensions import PageExtensionAdmin
from cms.models import Page
from cms.admin.pageadmin import PageAdmin

from .models import IconExtension
from cms.admin.forms import ChangePageForm

from .models import IconExtension, MetaDataExtension


class IconExtensionAdmin(PageExtensionAdmin):
pass

admin.site.register(IconExtension, IconExtensionAdmin)

class SimpleChangePageForm(ChangePageForm):
meta_description = None


class SimplePageAdmin(PageAdmin):
change_form = SimpleChangePageForm


admin.site.register(IconExtension, IconExtensionAdmin)
admin.site.register(MetaDataExtension, PageExtensionAdmin)

admin.site.unregister(Page)
admin.site.register(Page, SimplePageAdmin)
18 changes: 16 additions & 2 deletions app/contrib/campaign/cms_toolbars.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from cms.toolbar_pool import toolbar_pool
from cms.extensions.toolbar import ExtensionToolbar
from django.utils.translation import ugettext_lazy as _
from .models import IconExtension
from .models import IconExtension, MetaDataExtension


@toolbar_pool.register
Expand All @@ -20,4 +20,18 @@ def populate(self):
if url:
# adds a toolbar item in position 0 (at the top of the menu)
current_page_menu.add_modal_item(_('Page Icon'), url=url,
disabled=not self.toolbar.edit_mode_active, position=0)
disabled=not self.toolbar.edit_mode_active, position=0)


@toolbar_pool.register
class MetaDataExtensionToolbar(ExtensionToolbar):
model = MetaDataExtension

def populate(self):
current_page_menu = self._setup_extension_toolbar()

if current_page_menu:
page_extension, url = self.get_page_extension_admin()
if url:
current_page_menu.add_modal_item(_('Sharing'), url=url,
disabled=not self.toolbar.edit_mode_active, position=0)
32 changes: 32 additions & 0 deletions app/contrib/campaign/migrations/0022_metadataextension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 3.2 on 2023-10-26 20:30

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import filer.fields.image


class Migration(migrations.Migration):

dependencies = [
('cms', '0022_auto_20180620_1551'),
migrations.swappable_dependency(settings.FILER_IMAGE_MODEL),
('campaign', '0021_delete_pressure'),
]

operations = [
migrations.CreateModel(
name='MetaDataExtension',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(blank=True, max_length=70, null=True, verbose_name='Título da postagem')),
('subtitle', models.CharField(blank=True, max_length=90, null=True, verbose_name='Texto da postagem')),
('extended_object', models.OneToOneField(editable=False, on_delete=django.db.models.deletion.CASCADE, to='cms.page')),
('image', filer.fields.image.FilerImageField(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.FILER_IMAGE_MODEL, verbose_name='Thumbnail')),
('public_extension', models.OneToOneField(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='draft_extension', to='campaign.metadataextension')),
],
options={
'abstract': False,
},
),
]
26 changes: 25 additions & 1 deletion app/contrib/campaign/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,32 @@ class IconExtension(PageExtension):
blank=True,
null=True,
on_delete=models.SET_NULL,
related_name="+",
related_name="+"
)


extension_pool.register(IconExtension)


class MetaDataExtension(PageExtension):
image = FilerImageField(
verbose_name="Thumbnail",
blank=True,
null=True,
on_delete=models.SET_NULL,
related_name="+"
)
title = models.CharField(
verbose_name="Título da postagem",
blank=True,
null=True,
max_length=70
)
subtitle = models.CharField(
verbose_name="Texto da postagem",
blank=True,
null=True,
max_length=90
)

extension_pool.register(MetaDataExtension)
8 changes: 8 additions & 0 deletions app/contrib/campaign/templatetags/campaign_page_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django import template

register = template.Library()


@register.simple_tag
def get_absolute_url(request, path=""):
return request.scheme + "://" + request.get_host() + path
9 changes: 5 additions & 4 deletions app/tailwind/templates/tailwind.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load cms_tags sekizai_tags static %}
{% load cms_tags campaign_page_tags sekizai_tags static %}
<!doctype html>
<html lang="{{ LANGUAGE_CODE }}">

Expand All @@ -7,10 +7,11 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
{% block meta %}
<meta name="description" content="{% page_attribute meta_description %}" />
<meta name="description" content="{{ request.current_page.metadataextension.subtitle }}" />
<meta property="og:type" content="website" />
<meta property="og:title" content="{% page_attribute 'page_title' %}" />
<meta property="og:description" content="{% page_attribute meta_description %}" />
<meta property="og:title" content="{{ request.current_page.metadataextension.title }}" />
<meta property="og:description" content="{{ request.current_page.metadataextension.subtitle }}" />
<meta property="og:image" content="{% get_absolute_url request request.current_page.metadataextension.image.url %}" />
{% endblock meta %}
{% block canonical_url %}
<link rel="canonical" href="{{ request.build_absolute_uri }}" />
Expand Down
Loading