Add poll plugin

-  move poll base template to new plugin app
master
Pete Ley 7 months ago
parent 22ec046fbe
commit 98aae9de85

@ -63,6 +63,7 @@ INSTALLED_APPS = [
'djangocms_style',
'djangocms_admin_style',
'djangocms_text_ckeditor',
'polls_cms_integration',
'polls',
"django.contrib.admin",
"django.contrib.auth",

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

@ -0,0 +1,6 @@
from django.apps import AppConfig
class PollsCmsIntegrationConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "polls_cms_integration"

@ -0,0 +1,16 @@
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from polls_cms_integration.models import PollPluginModel
from django.utils.translation import gettext as _
@plugin_pool.register_plugin # register the plugin
class PollPluginPublisher(CMSPluginBase):
model = PollPluginModel # model where plugin data are saved
module = _("Polls")
name = _("Poll Plugin") # name of the plugin in the interface
render_template = "polls_cms_integration/poll_plugin.html"
def render(self, context, instance, placeholder):
context.update({'instance': instance})
return context

@ -0,0 +1,44 @@
# Generated by Django 4.2.6 on 2023-10-17 16:19
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
("polls", "0002_alter_choice_id_alter_poll_id"),
("cms", "0022_auto_20180620_1551"),
]
operations = [
migrations.CreateModel(
name="PollPluginModel",
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",
),
),
(
"poll",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="polls.poll"
),
),
],
options={
"abstract": False,
},
bases=("cms.cmsplugin",),
),
]

@ -0,0 +1,10 @@
from django.db import models
from cms.models import CMSPlugin
from polls.models import Poll
class PollPluginModel(CMSPlugin):
poll = models.ForeignKey(Poll, on_delete=models.CASCADE)
def __str__(self):
return self.poll.question

@ -0,0 +1,16 @@
<h1>{{ instance.poll.question }}</h1>
<form action="{% url 'polls:vote' instance.poll.id %}" method="post">
{% csrf_token %}
<div class="form-group">
{% for choice in instance.poll.choice_set.all %}
<div class="radio">
<label>
<input type="radio" name="choice" value="{{ choice.id }}">
{{ choice.choice_text }}
</label>
</div>
{% endfor %}
</div>
<input type="submit" value="Vote" />
</form>

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.
Loading…
Cancel
Save