Skip to content
Open
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
123 changes: 121 additions & 2 deletions contrib/bonde/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table
# Feel free to rename the models, but don't rename db_table values or field names.
from django.db import models
from django.conf import settings
from django.contrib.sites.models import Site


class User(models.Model):
Expand Down Expand Up @@ -91,7 +93,9 @@ class Meta:


class DnsHostedZone(models.Model):
community = models.ForeignKey(Community, on_delete=models.CASCADE, blank=True, null=True)
community = models.ForeignKey(
Community, on_delete=models.CASCADE, blank=True, null=True
)
domain_name = models.CharField(unique=True, max_length=100, blank=True, null=True)
# comment = models.TextField(blank=True, null=True)
created_at = models.DateTimeField()
Expand All @@ -103,4 +107,119 @@ class DnsHostedZone(models.Model):

class Meta:
managed = False
db_table = 'dns_hosted_zones'
db_table = "dns_hosted_zones"


class RequestManager(models.Manager):

def __init__(self, lookup_field=None):
self.lookup_field = lookup_field
super(RequestManager, self).__init__()

def on_site(self, request=None):
site = Site.objects.get(id=settings.SITE_ID)
if request:
site = request.current_site

prefix = '' if not self.lookup_field else f'{self.lookup_field}__'

params = {
f'{prefix}community__dnshostedzone__domain_name': site.domain
}

return self.get_queryset().filter(**params)


class MobilizationStatus(models.TextChoices):
archived = "archived", "Arquivada"
active = "active", "Ativa"


class Mobilization(models.Model):
name = models.CharField(max_length=266, blank=True, null=True)
created_at = models.DateTimeField()
# user_id = models.IntegerField(blank=True, null=True)
# color_scheme = models.CharField(max_length=-1, blank=True, null=True)
# google_analytics_code = models.CharField(max_length=-1, blank=True, null=True)
# goal = models.TextField(blank=True, null=True)
# header_font = models.CharField(max_length=-1, blank=True, null=True)
# body_font = models.CharField(max_length=-1, blank=True, null=True)
# facebook_share_title = models.CharField(max_length=-1, blank=True, null=True)
# facebook_share_description = models.TextField(blank=True, null=True)
# facebook_share_image = models.CharField(max_length=-1, blank=True, null=True)
# slug = models.CharField(unique=True, max_length=-1, blank=True, null=True)
custom_domain = models.CharField(unique=True, max_length=255, blank=True, null=True)
# twitter_share_text = models.CharField(max_length=300, blank=True, null=True)
community = models.ForeignKey(Community, models.DO_NOTHING, blank=True, null=True)
# favicon = models.CharField(max_length=-1, blank=True, null=True)
# deleted_at = models.DateTimeField(blank=True, null=True)
status = models.CharField(
choices=MobilizationStatus.choices, max_length=30, blank=True, null=True
)
# traefik_host_rule = models.CharField(max_length=-1, blank=True, null=True)
# traefik_backend_address = models.CharField(max_length=-1, blank=True, null=True)
language = models.CharField(max_length=5, blank=True, null=True)
updated_at = models.DateTimeField(blank=True, null=True)
# theme = models.ForeignKey('Themes', models.DO_NOTHING, blank=True, null=True)

objects = RequestManager()

class Meta:
managed = False
db_table = "mobilizations"


class Block(models.Model):
mobilization = models.ForeignKey(
Mobilization, models.DO_NOTHING, blank=True, null=True
)
created_at = models.DateTimeField()
updated_at = models.DateTimeField()
# bg_class = models.CharField(max_length=-1, blank=True, null=True)
# position = models.IntegerField(blank=True, null=True)
# hidden = models.BooleanField(blank=True, null=True)
# bg_image = models.TextField(blank=True, null=True)
# name = models.CharField(max_length=-1, blank=True, null=True)
# menu_hidden = models.BooleanField(blank=True, null=True)
deleted_at = models.DateTimeField(blank=True, null=True)

class Meta:
managed = False
db_table = "blocks"


class WidgetKind(models.TextChoices):
content = "content", "Conteúdo"
donation = "donation", "Doação"
draft = "draft", "Rascunho"
form = "form", "Formulário"
phone = "phone", "Pressão por telefone"
plip = "plip", "PLIP"
pressure = "pressure", "Pressão por email"


class Widget(models.Model):
block = models.ForeignKey(Block, models.DO_NOTHING, blank=True, null=True)
# settings = models.JSONField(blank=True, null=True)
kind = models.CharField(
max_length=50, choices=WidgetKind.choices, blank=True, null=True
)
created_at = models.DateTimeField()
updated_at = models.DateTimeField()
# sm_size = models.IntegerField(blank=True, null=True)
# md_size = models.IntegerField(blank=True, null=True)
# lg_size = models.IntegerField(blank=True, null=True)
# mailchimp_segment_id = models.CharField(max_length=-1, blank=True, null=True)
# action_community = models.BooleanField(blank=True, null=True)
# exported_at = models.DateTimeField(blank=True, null=True)
# mailchimp_unique_segment_id = models.CharField(max_length=-1, blank=True, null=True)
# mailchimp_recurring_active_segment_id = models.CharField(max_length=-1, blank=True, null=True)
# mailchimp_recurring_inactive_segment_id = models.CharField(max_length=-1, blank=True, null=True)
# goal = models.DecimalField(max_digits=12, decimal_places=2, blank=True, null=True)
deleted_at = models.DateTimeField(blank=True, null=True)

objects = RequestManager(lookup_field='block__mobilization')

class Meta:
managed = False
db_table = "widgets"
3 changes: 3 additions & 0 deletions contrib/bonde/templates/bonde/widgets/bonde_widget.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% for subwidget in widget.subwidgets %}
{% include subwidget.template_name with widget=subwidget %}
{% endfor %}
5 changes: 4 additions & 1 deletion contrib/bonde/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from django.shortcuts import render

# Create your views here.

# def select_widget(request):
# if request.is_ajax():
# pass
20 changes: 20 additions & 0 deletions contrib/bonde/widgets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from django.forms import MultiWidget, Select


class BondeWidget(MultiWidget):
description = "A Bonde widget reference"
template_name = "bonde/widgets/bonde_widget.html"

def __init__(self, *args, **kwargs):
kwargs["widgets"] = {
"mobilization_id": Select,
"widget_id": Select
}

super(BondeWidget, self).__init__(*args, **kwargs)


def decompress(self, value):
if value:
return [value.mobilization_id, value.widget_id]
return []
153 changes: 97 additions & 56 deletions contrib/campaign/cms_plugins.py
Original file line number Diff line number Diff line change
@@ -1,74 +1,115 @@
from django.db.models import Q
from django.contrib import admin

from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool

from .models import ActionButton, Row, Column
from .forms import PressureForm
from contrib.bonde.models import Widget

from .models import Pressure, TargetGroup
from .forms import PressureForm, PressureSettingsForm

# @plugin_pool.register_plugin
# class BlockPlugin(CMSPluginBase):
# model = Block
# name = "Bloco"
# render_template = "campaign/plugins/block.html"
# allow_children = True
# child_classes = [
# "PicturePlugin",
# "TextPlugin",
# "ActionButtonPlugin",
# "RowPlugin",
# ]


# @plugin_pool.register_plugin
# class GridBlockPlugin(CMSPluginBase):
# model = Block
# name = "Grid"
# render_template = "campaign/plugins/grid-block.html"
# allow_children = True
# child_classes = ["TextPlugin", "PressurePlugin"]


@plugin_pool.register_plugin
class ActionButtonPlugin(CMSPluginBase):
model = ActionButton
name = "Botão de ação"
render_template = "campaign/plugins/action-button.html"
allow_children = False
class TargetGroupInline(admin.StackedInline):
fieldset = "Alvos"
model = TargetGroup
template = "campaign/admin/edit_inline/stacked.html"
extra = 1


@plugin_pool.register_plugin
class PressurePlugin(CMSPluginBase):
name = "Pressão"
render_template = "campaign/plugins/pressure.html"
change_form_template = "campaign/admin/change_form.html"
model = Pressure
# model = Dummy
form = PressureSettingsForm
inlines = [
TargetGroupInline,
]
fieldsets = [
("Alvos", {"fields": [], "classes": ["tab-active"]}),
("Email", {"fields": ["email_subject", "email_body", "disable_editing"]}),
("Envio", {"fields": ["submissions_limit", "submissions_interval"]}),
("Agradecimento", {"fields": ["thank_email_subject", "sender_name", "sender_email", "thank_email_body"]}),
("Pós-ação", {"fields": ["sharing", "whatsapp_text"]})
]
# fieldsets = [
# ("Alvos", {"fields": ["is_group", "email_subject"], "classes": ["tab-active"]}),
# ("Email", {"fields": ["disable_editing"]}),
# (
# "Envio",
# {
# "fields": ["submissions_limit", "submissions_interval"],
# },
# ),
# (
# "Agradecimento",
# {
# "fields": [
# "email_subject",
# "sender_name",
# "sender_email",
# "email_body",
# ],
# },
# ),
# ("Pós-ação", {"fields": ["sharing", "whatsapp_text"]}),
# ]

# return super().save_form(request, form, change)

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

# qs = Widget.objects.on_site(request=request).filter(kind="pressure")

# choices = list(
# map(lambda x: (x.id, f"{x.block.mobilization.name} {x.kind} {x.id}"), qs)
# )

# form.base_fields["widget"].widget.choices = choices

# return form

def render_change_form(
self, request, context, add=False, change=False, form_url="", obj=None
):
sorted_inline_formsets = {}
inline_admin_formsets = context["inline_admin_formsets"]
formsets_to_remove = []

for inline_formset in inline_admin_formsets:
if hasattr(inline_formset.opts, "fieldset"):
fieldset = inline_formset.opts.fieldset
if fieldset in sorted_inline_formsets:
sorted_inline_formsets[fieldset].append(inline_formset)
else:
sorted_inline_formsets.update(
{
fieldset: [
inline_formset,
]
}
)
formsets_to_remove.append(inline_formset)

for inline_formset in formsets_to_remove:
inline_admin_formsets.remove(inline_formset)

context.update(
{
"sorted_inline_formsets": sorted_inline_formsets,
"inline_admin_formsets": inline_admin_formsets,
}
)

# import ipdb;ipdb.set_trace()
return super(PressurePlugin, self).render_change_form(
request, context, add, change, form_url, obj
)

def render(self, context, instance, placeholder):
context = super(PressurePlugin, self).render(context, instance, placeholder)
context.update({"form": PressureForm()})
return context


@plugin_pool.register_plugin
class RowPlugin(CMSPluginBase):
model = Row
name = "Linha"
render_template = "campaign/plugins/row.html"
allow_children = True
child_classes = ["ColumnPlugin", "PicturePlugin"]


# @plugin_pool.register_plugin
# class ColumnPlugin(CMSPluginBase):
# model = Column
# name = "Coluna"
# render_template = "campaign/plugins/column.html"
# allow_children = True
# parent_classes = ["RowPlugin"]


@plugin_pool.register_plugin
class FooterPlugin(CMSPluginBase):
name = "Rodapé"
render_template = "campaign/plugins/footer.html"
allow_children = False
Loading