-
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.
Merge pull request #191 from nossas/feature/publications-app
Aplicativo de Publicações
- Loading branch information
Showing
34 changed files
with
615 additions
and
48 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
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
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
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,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()) |
4 changes: 4 additions & 0 deletions
4
app/nossas/apps/templates/search/indexes/apps/campaign_text.txt
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,4 @@ | ||
{{ object.name }} | ||
{{ object.campaign_group.name }} | ||
{{ object.description }} | ||
{{ object.tags.all|join:" " }} |
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
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
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
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
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
Empty file.
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,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) |
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,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") |
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,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"] |
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
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() |
Oops, something went wrong.