Skip to content

Commit

Permalink
Merge pull request #191 from nossas/feature/publications-app
Browse files Browse the repository at this point in the history
Aplicativo de Publicações
  • Loading branch information
miguelzinh3 authored Apr 1, 2024
2 parents fda2860 + d46a3fd commit a7e6d6c
Show file tree
Hide file tree
Showing 34 changed files with 615 additions and 48 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Publish Bonde CMS docker image](https://github.com/nossas/cms/actions/workflows/publish.yml/badge.svg?branch=main)](https://github.com/nossas/cms/actions/workflows/publish.yml)

Bonde CMS
----------

Expand Down
2 changes: 2 additions & 0 deletions app/nossas/apps/basemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class OnSiteBaseModel(models.Model):
site = models.ForeignKey(Site, on_delete=models.CASCADE)

on_site = CurrentSiteManager()
# Force objects queryset
objects = CurrentSiteManager()

class Meta:
abstract = True
4 changes: 4 additions & 0 deletions app/nossas/apps/models/campaigns.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def __str__(self):
def get_absolute_url(self):
return reverse("campaigns:campaign-detail", kwargs={"pk": self.pk})

@property
def get_pub_date(self):
return self.release_date

def create_default_page(self):
language = "pt-br"

Expand Down
15 changes: 15 additions & 0 deletions app/nossas/apps/search_indexes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from datetime import datetime
from haystack import indexes
from .models import Campaign


class CampaignIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
pub_date = indexes.DateTimeField(model_attr="release_date")

def get_model(self):
return Campaign

def index_queryset(self, using=None):
"""Used when the entire index for model is updated."""
return self.get_model().on_site.filter(release_date__lte=datetime.now())
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{ object.name }}
{{ object.campaign_group.name }}
{{ object.description }}
{{ object.tags.all|join:" " }}
46 changes: 45 additions & 1 deletion app/nossas/design/fields.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from django import forms
from django.db import models

from cms.models import Page
from django_select2.forms import ModelSelect2Widget


class GraphicElementRadioSelect(forms.RadioSelect):
template_name = "design/fields/graphic_element_select.html"
Expand Down Expand Up @@ -37,4 +40,45 @@ class GraphicIconChoices(models.TextChoices):
hub = "hub", "Hub, Eixo"
impulsionador = "impulsionador", "Impulsionador"
impacto = "impacto", "Impacto"
empatico = "empatico", "Empático"
empatico = "empatico", "Empático"


class Select2PageSearchFieldMixin:
search_fields = [
'title_set__title__icontains',
'title_set__menu_title__icontains',
'title_set__slug__icontains'
]

def label_from_instance(self, obj):
return obj.get_title()


class Select2PageSelectWidget(Select2PageSearchFieldMixin, ModelSelect2Widget):
site = None

# show entries when clicking on it
def build_attrs(self, base_attrs, extra_attrs=None):
default_attrs = {"data-minimum-input-length": 0}
default_attrs.update(base_attrs)
attrs = super().build_attrs(default_attrs, extra_attrs=extra_attrs)
return attrs

def get_queryset(self):
if self.site:
return Page.objects.drafts().on_site(self.site)
return Page.objects.drafts()

# we need to implement jQuery ourselves, see #180
class Media:
js = (
"https://code.jquery.com/jquery-3.5.1.slim.min.js",
)


class Select2PageSearchField(forms.ModelChoiceField):
widget = Select2PageSelectWidget(attrs={"classes": "customizacao"})

def __init__(self, *args, **kwargs):
kwargs['queryset'] = self.widget.get_queryset()
super().__init__(*args, **kwargs)
11 changes: 11 additions & 0 deletions app/nossas/design/static/design/scss/nossas.scss
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,17 @@ $carousel-control-next-icon-bg: url("data:image/svg+xml,<svg width='41' height='
}
}

.search-results {
a {
color: inherit;
text-decoration: none;

&:hover {
color: var(--bs-azul-nossas);
}
}
}

// Forms
// input.form-control {
// border-color: var(--bs-border-color);
Expand Down
14 changes: 14 additions & 0 deletions app/nossas/design/templatetags/design_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@ def add_class(field, class_name):
"class": " ".join((field.css_classes(), class_name))
})

@register.filter
def add_attr(field, css):
attrs = {}
definition = css.split(',')

for d in definition:
if ':' not in d:
attrs['class'] = d
else:
key, val = d.split(':')
attrs[key] = val

return field.as_widget(attrs=attrs)

@register.simple_tag
def multiple_svg_icon(icon):
return f'nossas/svg/{icon}.svg'
44 changes: 1 addition & 43 deletions app/nossas/plugins/forms/cardform.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,11 @@
from django.utils.translation import gettext_lazy as _

# from cms.forms.fields import PageSelectFormField as PageSearchField
from cms.models import Page
from django_select2.forms import ModelSelect2Widget
from nossas.design.fields import Select2PageSearchField

from ..models.cardmodel import Card


class Select2PageSearchFieldMixin:
search_fields = [
'title_set__title__icontains',
'title_set__menu_title__icontains',
'title_set__slug__icontains'
]

def label_from_instance(self, obj):
return obj.get_title()


class Select2PageSelectWidget(Select2PageSearchFieldMixin, ModelSelect2Widget):
site = None

# show entries when clicking on it
def build_attrs(self, base_attrs, extra_attrs=None):
default_attrs = {"data-minimum-input-length": 0}
default_attrs.update(base_attrs)
attrs = super().build_attrs(default_attrs, extra_attrs=extra_attrs)
return attrs

def get_queryset(self):
if self.site:
return Page.objects.drafts().on_site(self.site)
return Page.objects.drafts()

# we need to implement jQuery ourselves, see #180
class Media:
js = (
"https://code.jquery.com/jquery-3.5.1.slim.min.js",
)


class Select2PageSearchField(forms.ModelChoiceField):
widget = Select2PageSelectWidget(attrs={"classes": "customizacao"})

def __init__(self, *args, **kwargs):
kwargs['queryset'] = self.widget.get_queryset()
super().__init__(*args, **kwargs)


class CardPluginForm(forms.ModelForm):
internal_link = Select2PageSearchField(
label=_('Link interno'),
Expand Down
2 changes: 1 addition & 1 deletion app/nossas/plugins/templates/nossas/plugins/navbar.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% load menu_tags %}

<nav class="navbar px-0 px-sm-4{% if instance and instance.classes %} {{ instance.classes }}{% endif %}" data-bs-theme="dark">
<nav class="navbar px-0 px-sm-4{% if instance and instance.classes %} {{ instance.classes }}{% else %} bg-azul-nossas{% endif %}" data-bs-theme="dark">
{% comment %} Visible only mobile {% endcomment %}
<div class="container-fluid d-sm-none">
<a class="navbar-brand" href="{{ request.scheme|add:'://'|add:request.current_site.domain }}">
Expand Down
Empty file.
16 changes: 16 additions & 0 deletions app/nossas/publications/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django.contrib import admin

# TODO: Mover esses imports para base de aplicativos e plugins
from nossas.apps.baseadmin import OnSiteAdmin

from .models import Publication
from .forms import PublicationForm


class PublicationAdmin(OnSiteAdmin):
list_display = ("slug", "title", "parent", "created_at", "updated_at")
form = PublicationForm
prepopulated_fields = {'slug': ('title_pt_br',), }


admin.site.register(Publication, PublicationAdmin)
7 changes: 7 additions & 0 deletions app/nossas/publications/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.apps import AppConfig
from django.utils.translation import gettext_lazy as _


class PublicationsConfig(AppConfig):
name = "nossas.publications"
verbose_name = _("Aplicativos | Publicações")
23 changes: 23 additions & 0 deletions app/nossas/publications/cms_apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django.utils.translation import gettext_lazy as _

from cms.app_base import CMSApp
from cms.apphook_pool import apphook_pool


@apphook_pool.register
class PublicationsApphook(CMSApp):
app_name = "publications"
name = _("Publicações")

def get_urls(self, page=None, language=None, **kwargs):
return ["nossas.publications.urls"]



@apphook_pool.register
class SearchApphook(CMSApp):
app_name = "haystack"
name = _("Buscador")

def get_urls(self, page=None, language=None, **kwargs):
return ["nossas.urls_search"]
36 changes: 36 additions & 0 deletions app/nossas/publications/cms_plugins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from django.utils.translation import gettext_lazy as _

from cms.cms_plugins import CMSPluginBase, plugin_pool

from .forms import PublicationListForm
from .models import Publication, PublicationList


@plugin_pool.register_plugin
class PublicationListPlugin(CMSPluginBase):
name = _("Listagem de Publicações")
module = "NOSSAS"
model = PublicationList
form = PublicationListForm
render_template = "nossas/publications/publication_list_plugin.html"

# def get_form(self, request, obj=None, change=False, **kwargs):
# form = super().get_form(request, obj, change, **kwargs)

# import ipdb;ipdb.set_trace()
# if not change and request.current_page.application_namespace:
# form.fields["category"].initial = request.current_page

# return form


def render(self, context, instance, placeholder):
context = super().render(context, instance, placeholder)
qs = Publication.on_site.all()

if instance.category:
qs = qs.filter(parent=instance.category)

context["publication_list"] = qs

return context
40 changes: 40 additions & 0 deletions app/nossas/publications/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from django import forms
from django.utils.translation import gettext_lazy as _

from cms.models import Page
from nossas.design.fields import Select2PageSearchField

from .models import Publication, PublicationList


class PublicationForm(forms.ModelForm):
parent = Select2PageSearchField(
label=_("Página Relacionada"),
required=False,
)

class Meta:
model = Publication
fields = "__all__"

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.fields["parent"].queryset = Page.objects.drafts().on_site()



class PublicationListForm(forms.ModelForm):
category = Select2PageSearchField(
label=_("Página Relacionada"),
required=False,
)

class Meta:
model = PublicationList
fields = "__all__"

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.fields["category"].queryset = Page.objects.drafts().on_site()
Loading

0 comments on commit a7e6d6c

Please sign in to comment.