-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nossas): add plugin to list publications by category/page
- Loading branch information
1 parent
0fac1b0
commit d46a3fd
Showing
6 changed files
with
112 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
app/nossas/publications/migrations/0006_publicationlist.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Generated by Django 4.2 on 2024-03-28 16:40 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('cms', '0022_auto_20180620_1551'), | ||
('publications', '0005_alter_publication_managers_publication_external_link'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='PublicationList', | ||
fields=[ | ||
('cmsplugin_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='%(app_label)s_%(class)s', serialize=False, to='cms.cmsplugin')), | ||
('category', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='cms.page', verbose_name='Página Relacionada')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
bases=('cms.cmsplugin',), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
app/nossas/publications/templates/nossas/publications/publication_list_plugin.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<div class="grid"> | ||
{% for p in publication_list %} | ||
<div class="g-col-12 g-col-md-6"> | ||
<a href="{{ p.get_absolute_url }}" class="text-reset text-decoration-none"> | ||
<div class="card"> | ||
{% if p.image_default %} | ||
<img src="{{ p.image_default.url }}" class="card-img-top" alt="{{ p.name }}"> | ||
{% endif %} | ||
<div class="card-body"> | ||
<div class="card-body-content"> | ||
<h3>{{ p.title }}</h3> | ||
<p>{{ p.description }}</p> | ||
</div> | ||
</div> | ||
</div> | ||
</a> | ||
</div> | ||
{% endfor %} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters