Skip to content

Commit

Permalink
apps/projects: add insight model and form
Browse files Browse the repository at this point in the history
  • Loading branch information
m4ra committed Jul 13, 2023
1 parent aea944b commit 9330fdc
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 2 deletions.
43 changes: 43 additions & 0 deletions apps/projects/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

from adhocracy4.dashboard import DashboardComponent
from adhocracy4.dashboard import components
from adhocracy4.dashboard.components.forms import ProjectDashboardForm
from adhocracy4.dashboard.components.forms import ProjectFormComponent

from . import views
from .models import Insight


class ParticipantsComponent(DashboardComponent):
Expand Down Expand Up @@ -61,5 +64,45 @@ def get_urls(self):
]


class InsightForm(ProjectDashboardForm):
class Meta:
model = Insight
fields = [
"active_participants",
"comments",
"ratings",
"written_ideas",
"poll_answers",
"live_questions",
"display",
]
required_for_project_publish = []

help_texts = {
"display": _(
"Show insights with numbers "
"of contributions and participants "
"during the participation process"
),
}

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
for name, field in self.fields.items():
if not name == "display":
field.widget.attrs["readonly"] = "true"


class ProjectInsightComponent(ProjectFormComponent):
identifier = "insight"
weight = 12
label = _("Insights")

form_title = _("Insights")
form_class = InsightForm
form_template_name = "a4_candy_projects/includes/project_insight_form.html"


components.register_project(ProjectInsightComponent())
components.register_project(ModeratorsComponent())
components.register_project(ParticipantsComponent())
60 changes: 60 additions & 0 deletions apps/projects/migrations/0005_insight.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Generated by Django 3.2.19 on 2023-07-13 12:58

from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


class Migration(migrations.Migration):
dependencies = [
("a4projects", "0038_verbose_name_created_modified"),
("a4_candy_projects", "0004_verbose_name_created_modified"),
]

operations = [
migrations.CreateModel(
name="Insight",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"created",
models.DateTimeField(
default=django.utils.timezone.now,
editable=False,
verbose_name="Created",
),
),
(
"modified",
models.DateTimeField(
blank=True, editable=False, null=True, verbose_name="Modified"
),
),
("active_participants", models.PositiveIntegerField()),
("comments", models.IntegerField()),
("ratings", models.IntegerField()),
("written_ideas", models.IntegerField()),
("poll_answers", models.IntegerField()),
("live_questions", models.IntegerField()),
("display", models.BooleanField(default=False)),
(
"project",
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
to="a4projects.project",
),
),
],
options={
"abstract": False,
},
),
]
16 changes: 14 additions & 2 deletions apps/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def invite(self, creator, project, email, site):


class ParticipantInvite(Invite):

objects = ParticipantInviteManager()

def __str__(self):
Expand Down Expand Up @@ -68,7 +67,6 @@ def invite(self, creator, project, email, site):


class ModeratorInvite(Invite):

objects = ModeratorInviteManager()

def __str__(self):
Expand All @@ -87,3 +85,17 @@ def accept(self, user):

class Meta:
unique_together = ("email", "project")


class Insight(base.TimeStampedModel):
project = models.OneToOneField(Project, on_delete=models.CASCADE)
active_participants = models.PositiveIntegerField()
comments = models.IntegerField()
ratings = models.IntegerField()
written_ideas = models.IntegerField()
poll_answers = models.IntegerField()
live_questions = models.IntegerField()
display = models.BooleanField(default=False)

def __str__(self):
return "Insights for project %s" % self.project.name
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% load i18n widget_tweaks %}

<div class="form-group">
<label for="{{ field.id_for_label }}">
{{ field.label }}{% if field.field.required %}<span role="presentation" title="{% translate 'This field is required' %}">*</span>{% endif %}
{% block after_label %}
{% if field.field.required_for_publish and not field.value %}
<i class="fa fa-exclamation-circle u-danger" title="{% translate 'Missing field for publication' %}" aria-label="{% translate 'Missing field for publication' %}"></i>
{% endif %}
{% endblock %}
</label>
{% if field.help_text %}
<div class="form-hint">
{{ field.help_text }}
</div>
{% endif %}
{% block field %}
<div class="widget widget--{{ field|widget_type }}">
{{ field }}
</div>
{% endblock %}
{{ field.errors }}
</div>

0 comments on commit 9330fdc

Please sign in to comment.