Skip to content
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ This project (not yet) adheres to [Semantic Versioning](https://semver.org/spec/

### Unreleased

### Added

- CreatorContactExportMixin for Contact information fields for submission of ideas/proposals

### Fixed

- Offline events no longer trigger notification on phase start (only 72 hours before event)
Expand Down
24 changes: 24 additions & 0 deletions adhocracy4/exports/mixins/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,30 @@
from .base import VirtualFieldMixin


class CreatorContactExportMixin:
"""Add creator contact fields to exports."""

def get_virtual_fields(self, virtual):
virtual = super().get_virtual_fields(virtual)
virtual["creator_contact_consent"] = str(_("Contact consent"))
virtual["creator_email"] = str(_("Creator email"))
virtual["creator_phone"] = str(_("Creator phone"))
return virtual

def get_field_data(self, item, name):
"""Handle contact fields."""
if name == "creator_contact_consent":
value = getattr(item, name, False)
return "yes" if value else "no"

if name in ["creator_email", "creator_phone"]:
value = getattr(item, name, "")
return str(value) if value else ""

# Fall back to parent
return super().get_field_data(item, name)


class UserGeneratedContentExportMixin(VirtualFieldMixin):
"""
Adds link to item.
Expand Down
50 changes: 50 additions & 0 deletions adhocracy4/forms/fields.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django import forms
from django.forms.fields import SplitDateTimeField
from django.utils.translation import gettext_lazy as _

Expand Down Expand Up @@ -52,3 +53,52 @@ def _set_default_time(self, value):
):
value[1] = self.widget.get_default_time()
return value


class CreatorContactFieldMixin(forms.ModelForm):
creator_email = forms.EmailField(
required=False,
label=_("Your email address"),
help_text=_("We will use this to contact you about your submission"),
)
creator_phone = forms.CharField(
required=False,
label=_("Phone number (optional)"),
help_text=_("Optional contact number for follow-up questions"),
)
creator_contact_consent = forms.BooleanField(
required=False,
label=_("Contact consent"),
help_text=_(
"I expressly consent to the storage of the contact information I have provided. This information may only be used by the responsible authority to get in touch with me in connection with this project. I can withdraw this consent at any time. I have read and accept the Privacy Policy."
),
)

def __init__(self, *args, **kwargs):
self.user = kwargs.get("user", None)
super().__init__(*args, **kwargs)

# Set default creator_email to user's email
if self.user and self.user.email:
self.fields["creator_email"].initial = self.user.email

self.fields["creator_email"].widget.attrs.update({"placeholder": _("Optional")})
self.fields["creator_phone"].widget.attrs.update({"placeholder": _("Optional")})

def clean_creator_email(self):
"""Ensure creator_email is either blank or a valid email."""
email = self.cleaned_data.get("creator_email", "")
return email if email else ""

def save(self, commit=True):
instance = super().save(commit=commit)
if commit:
if hasattr(instance, "creator_contact_consent"):
instance.creator_contact_consent = self.cleaned_data.get("creator_contact_consent", False)
if hasattr(instance, "creator_email"):
instance.creator_email = self.cleaned_data.get("creator_email", "")
if hasattr(instance, "creator_phone"):
instance.creator_phone = self.cleaned_data.get("creator_phone", "")
if commit and hasattr(instance, "save"):
instance.save()
return instance
Loading