This commit is contained in:
Flatlogic Bot 2026-01-24 16:24:42 +00:00
parent e2ad03e446
commit 14bf8d7295
13 changed files with 96 additions and 85 deletions

15
ERD.md
View File

@ -7,7 +7,6 @@ erDiagram
Tenant ||--o{ DonationMethod : defines Tenant ||--o{ DonationMethod : defines
Tenant ||--o{ ElectionType : defines Tenant ||--o{ ElectionType : defines
Tenant ||--o{ EventType : defines Tenant ||--o{ EventType : defines
Tenant ||--o{ ParticipationType : defines
Tenant ||--o{ Voter : belongs_to Tenant ||--o{ Voter : belongs_to
Tenant ||--o{ Event : organizes Tenant ||--o{ Event : organizes
@ -25,7 +24,6 @@ erDiagram
InteractionType ||--o{ Interaction : categorizes InteractionType ||--o{ Interaction : categorizes
DonationMethod ||--o{ Donation : categorizes DonationMethod ||--o{ Donation : categorizes
ElectionType ||--o{ VoterLikelihood : categorizes ElectionType ||--o{ VoterLikelihood : categorizes
ParticipationType ||--o{ EventParticipation : categorizes
Tenant { Tenant {
int id PK int id PK
@ -78,13 +76,6 @@ erDiagram
boolean is_active boolean is_active
} }
ParticipationType {
int id PK
int tenant_id FK
string name
boolean is_active
}
Voter { Voter {
int id PK int id PK
int tenant_id FK int tenant_id FK
@ -105,6 +96,7 @@ erDiagram
VotingRecord { VotingRecord {
int id PK int id PK
int voter_id FK int voter_id FK
string participation_type
date election_date date election_date
string election_description string election_description
string primary_party string primary_party
@ -122,12 +114,13 @@ erDiagram
int id PK int id PK
int event_id FK int event_id FK
int voter_id FK int voter_id FK
int participation_type_id FK string participation_type
} }
Donation { Donation {
int id PK int id PK
int voter_id FK int voter_id FK
string participation_type
date date date date
int method_id FK int method_id FK
decimal amount decimal amount
@ -136,6 +129,7 @@ erDiagram
Interaction { Interaction {
int id PK int id PK
int voter_id FK int voter_id FK
string participation_type
int type_id FK int type_id FK
date date date date
string description string description
@ -145,6 +139,7 @@ erDiagram
VoterLikelihood { VoterLikelihood {
int id PK int id PK
int voter_id FK int voter_id FK
string participation_type
int election_type_id FK int election_type_id FK
string likelihood string likelihood
} }

View File

@ -1,8 +1,7 @@
from django.contrib import admin from django.contrib import admin
from .models import ( from .models import (
Tenant, TenantUserRole, InteractionType, DonationMethod, ElectionType, EventType, Tenant, TenantUserRole, InteractionType, DonationMethod, ElectionType, EventType, Voter,
ParticipationType, Voter, VotingRecord, Event, EventParticipation, Donation, VotingRecord, Event, EventParticipation, Donation, Interaction, VoterLikelihood
Interaction, VoterLikelihood
) )
class TenantUserRoleInline(admin.TabularInline): class TenantUserRoleInline(admin.TabularInline):
@ -45,12 +44,6 @@ class EventTypeAdmin(admin.ModelAdmin):
list_filter = ('tenant', 'is_active') list_filter = ('tenant', 'is_active')
search_fields = ('name',) search_fields = ('name',)
@admin.register(ParticipationType)
class ParticipationTypeAdmin(admin.ModelAdmin):
list_display = ('name', 'tenant', 'is_active')
list_filter = ('tenant', 'is_active')
search_fields = ('name',)
class VotingRecordInline(admin.TabularInline): class VotingRecordInline(admin.TabularInline):
model = VotingRecord model = VotingRecord
extra = 1 extra = 1

View File

@ -71,7 +71,7 @@ class VoterLikelihoodForm(forms.ModelForm):
class EventParticipationForm(forms.ModelForm): class EventParticipationForm(forms.ModelForm):
class Meta: class Meta:
model = EventParticipation model = EventParticipation
fields = ['event'] fields = ['event', 'participation_type']
def __init__(self, *args, tenant=None, **kwargs): def __init__(self, *args, tenant=None, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
@ -80,6 +80,7 @@ class EventParticipationForm(forms.ModelForm):
for field in self.fields.values(): for field in self.fields.values():
field.widget.attrs.update({'class': 'form-control'}) field.widget.attrs.update({'class': 'form-control'})
self.fields['event'].widget.attrs.update({'class': 'form-select'}) self.fields['event'].widget.attrs.update({'class': 'form-select'})
self.fields['participation_type'].widget.attrs.update({'class': 'form-select'})
class EventForm(forms.ModelForm): class EventForm(forms.ModelForm):
class Meta: class Meta:

View File

@ -0,0 +1,18 @@
# Generated by Django 5.2.7 on 2026-01-24 16:11
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0004_remove_voter_geocode_donationmethod_is_active_and_more'),
]
operations = [
migrations.AddField(
model_name='eventparticipation',
name='participation_type',
field=models.CharField(choices=[('invited', 'Invited'), ('invited_not_attended', "Invited but didn't attend"), ('attended', 'Attended')], default='invited', max_length=50),
),
]

View File

@ -1,31 +0,0 @@
# Generated by Django 5.2.7 on 2026-01-24 15:43
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0004_remove_voter_geocode_donationmethod_is_active_and_more'),
]
operations = [
migrations.CreateModel(
name='ParticipationType',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('is_active', models.BooleanField(default=True)),
('tenant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='participation_types', to='core.tenant')),
],
options={
'unique_together': {('tenant', 'name')},
},
),
migrations.AddField(
model_name='eventparticipation',
name='participation_type',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='core.participationtype'),
),
]

View File

@ -41,7 +41,7 @@ class InteractionType(models.Model):
unique_together = ('tenant', 'name') unique_together = ('tenant', 'name')
def __str__(self): def __str__(self):
return self.name return f"{self.name} ({self.tenant.name})"
class DonationMethod(models.Model): class DonationMethod(models.Model):
tenant = models.ForeignKey(Tenant, on_delete=models.CASCADE, related_name='donation_methods') tenant = models.ForeignKey(Tenant, on_delete=models.CASCADE, related_name='donation_methods')
@ -52,7 +52,7 @@ class DonationMethod(models.Model):
unique_together = ('tenant', 'name') unique_together = ('tenant', 'name')
def __str__(self): def __str__(self):
return self.name return f"{self.name} ({self.tenant.name})"
class ElectionType(models.Model): class ElectionType(models.Model):
tenant = models.ForeignKey(Tenant, on_delete=models.CASCADE, related_name='election_types') tenant = models.ForeignKey(Tenant, on_delete=models.CASCADE, related_name='election_types')
@ -63,7 +63,7 @@ class ElectionType(models.Model):
unique_together = ('tenant', 'name') unique_together = ('tenant', 'name')
def __str__(self): def __str__(self):
return self.name return f"{self.name} ({self.tenant.name})"
class EventType(models.Model): class EventType(models.Model):
tenant = models.ForeignKey(Tenant, on_delete=models.CASCADE, related_name='event_types') tenant = models.ForeignKey(Tenant, on_delete=models.CASCADE, related_name='event_types')
@ -74,18 +74,7 @@ class EventType(models.Model):
unique_together = ('tenant', 'name') unique_together = ('tenant', 'name')
def __str__(self): def __str__(self):
return self.name return f"{self.name} ({self.tenant.name})"
class ParticipationType(models.Model):
tenant = models.ForeignKey(Tenant, on_delete=models.CASCADE, related_name='participation_types')
name = models.CharField(max_length=100)
is_active = models.BooleanField(default=True)
class Meta:
unique_together = ('tenant', 'name')
def __str__(self):
return self.name
class Voter(models.Model): class Voter(models.Model):
SUPPORT_CHOICES = [ SUPPORT_CHOICES = [
@ -136,12 +125,18 @@ class Event(models.Model):
return f"{self.event_type} on {self.date}" return f"{self.event_type} on {self.date}"
class EventParticipation(models.Model): class EventParticipation(models.Model):
PARTICIPATION_TYPE_CHOICES = [
("invited", "Invited"),
("invited_not_attended", "Invited but didn't attend"),
("attended", "Attended"),
]
event = models.ForeignKey(Event, on_delete=models.CASCADE, related_name='participations') event = models.ForeignKey(Event, on_delete=models.CASCADE, related_name='participations')
voter = models.ForeignKey(Voter, on_delete=models.CASCADE, related_name='event_participations') voter = models.ForeignKey(Voter, on_delete=models.CASCADE, related_name='event_participations')
participation_type = models.ForeignKey(ParticipationType, on_delete=models.SET_NULL, null=True, blank=True) participation_type = models.CharField(max_length=50, choices=PARTICIPATION_TYPE_CHOICES, default='invited')
def __str__(self): def __str__(self):
return f"{self.voter} at {self.event}" return f"{self.voter} at {self.event} ({self.get_participation_type_display()})"
class Donation(models.Model): class Donation(models.Model):
voter = models.ForeignKey(Voter, on_delete=models.CASCADE, related_name='donations') voter = models.ForeignKey(Voter, on_delete=models.CASCADE, related_name='donations')

View File

@ -283,6 +283,7 @@
<tr> <tr>
<th class="ps-4">Date</th> <th class="ps-4">Date</th>
<th>Event Type</th> <th>Event Type</th>
<th>Type</th>
<th>Description</th> <th>Description</th>
<th class="pe-4 text-end">Actions</th> <th class="pe-4 text-end">Actions</th>
</tr> </tr>
@ -292,6 +293,15 @@
<tr> <tr>
<td class="ps-4 text-nowrap">{{ participation.event.date|date:"M d, Y" }}</td> <td class="ps-4 text-nowrap">{{ participation.event.date|date:"M d, Y" }}</td>
<td><span class="badge bg-light text-dark border">{{ participation.event.event_type.name }}</span></td> <td><span class="badge bg-light text-dark border">{{ participation.event.event_type.name }}</span></td>
<td>
{% if participation.participation_type == 'attended' %}
<span class="badge bg-success-subtle text-success border border-success-subtle">Attended</span>
{% elif participation.participation_type == 'invited_not_attended' %}
<span class="badge bg-danger-subtle text-danger border border-danger-subtle">Did Not Attend</span>
{% else %}
<span class="badge bg-info-subtle text-info border border-info-subtle">Invited</span>
{% endif %}
</td>
<td class="small text-muted">{{ participation.event.description|truncatechars:60 }}</td> <td class="small text-muted">{{ participation.event.description|truncatechars:60 }}</td>
<td class="pe-4 text-end"> <td class="pe-4 text-end">
<button class="btn btn-sm btn-link text-primary p-0 me-2" data-bs-toggle="modal" data-bs-target="#editEventParticipationModal{{ participation.id }}"> <button class="btn btn-sm btn-link text-primary p-0 me-2" data-bs-toggle="modal" data-bs-target="#editEventParticipationModal{{ participation.id }}">
@ -303,7 +313,7 @@
</td> </td>
</tr> </tr>
{% empty %} {% empty %}
<tr><td colspan="4" class="text-center py-4 text-muted">No event participations found.</td></tr> <tr><td colspan="5" class="text-center py-4 text-muted">No event participations found.</td></tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
@ -685,10 +695,14 @@
<form action="{% url 'add_event_participation' voter.id %}" method="POST"> <form action="{% url 'add_event_participation' voter.id %}" method="POST">
{% csrf_token %} {% csrf_token %}
<div class="modal-body p-4"> <div class="modal-body p-4">
<div class="mb-0"> <div class="mb-3">
<label class="form-label fw-medium">Select Event</label> <label class="form-label fw-medium">Select Event</label>
{{ event_participation_form.event }} {{ event_participation_form.event }}
</div> </div>
<div class="mb-0">
<label class="form-label fw-medium">Participation Status</label>
{{ event_participation_form.participation_type }}
</div>
</div> </div>
<div class="modal-footer border-0 p-4 pt-0"> <div class="modal-footer border-0 p-4 pt-0">
<button type="button" class="btn btn-light" data-bs-dismiss="modal">Cancel</button> <button type="button" class="btn btn-light" data-bs-dismiss="modal">Cancel</button>
@ -711,7 +725,7 @@
<form action="{% url 'edit_event_participation' participation.id %}" method="POST"> <form action="{% url 'edit_event_participation' participation.id %}" method="POST">
{% csrf_token %} {% csrf_token %}
<div class="modal-body p-4"> <div class="modal-body p-4">
<div class="mb-0"> <div class="mb-3">
<label class="form-label fw-medium">Event</label> <label class="form-label fw-medium">Event</label>
<select name="event" class="form-select"> <select name="event" class="form-select">
{% for ev in event_participation_form.fields.event.queryset %} {% for ev in event_participation_form.fields.event.queryset %}
@ -719,6 +733,14 @@
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
<div class="mb-0">
<label class="form-label fw-medium">Participation Status</label>
<select name="participation_type" class="form-select">
{% for val, label in event_participation_form.fields.participation_type.choices %}
<option value="{{ val }}" {% if val == participation.participation_type %}selected{% endif %}>{{ label }}</option>
{% endfor %}
</select>
</div>
</div> </div>
<div class="modal-footer border-0 p-4 pt-0"> <div class="modal-footer border-0 p-4 pt-0">
<button type="button" class="btn btn-light" data-bs-dismiss="modal">Cancel</button> <button type="button" class="btn btn-light" data-bs-dismiss="modal">Cancel</button>
@ -778,5 +800,22 @@
border-color: #059669; border-color: #059669;
box-shadow: 0 0 0 0.25rem rgba(5, 150, 105, 0.1); box-shadow: 0 0 0 0.25rem rgba(5, 150, 105, 0.1);
} }
.bg-success-subtle { background-color: #d1fae5; }
.bg-danger-subtle { background-color: #fee2e2; }
.bg-info-subtle { background-color: #e0f2fe; }
</style> </style>
<script>
document.addEventListener('DOMContentLoaded', function() {
const urlParams = new URLSearchParams(window.location.search);
const activeTab = urlParams.get('active_tab');
if (activeTab) {
const tabButton = document.getElementById(activeTab + '-tab');
if (tabButton) {
const tab = new bootstrap.Tab(tabButton);
tab.show();
}
}
});
</script>
{% endblock %} {% endblock %}

View File

@ -1,3 +1,4 @@
from django.urls import reverse
from django.shortcuts import render, redirect, get_object_or_404 from django.shortcuts import render, redirect, get_object_or_404
from django.db.models import Q from django.db.models import Q
from django.contrib import messages from django.contrib import messages
@ -125,7 +126,7 @@ def add_interaction(request, voter_id):
interaction.voter = voter interaction.voter = voter
interaction.save() interaction.save()
messages.success(request, "Interaction added.") messages.success(request, "Interaction added.")
return redirect('voter_detail', voter_id=voter.id) return redirect(reverse('voter_detail', kwargs={'voter_id': voter.id}) + '?active_tab=interactions')
def edit_interaction(request, interaction_id): def edit_interaction(request, interaction_id):
selected_tenant_id = request.session.get('tenant_id') selected_tenant_id = request.session.get('tenant_id')
@ -137,7 +138,7 @@ def edit_interaction(request, interaction_id):
if form.is_valid(): if form.is_valid():
form.save() form.save()
messages.success(request, "Interaction updated.") messages.success(request, "Interaction updated.")
return redirect('voter_detail', voter_id=interaction.voter.id) return redirect(reverse('voter_detail', kwargs={'voter_id': interaction.voter.id}) + '?active_tab=interactions')
def delete_interaction(request, interaction_id): def delete_interaction(request, interaction_id):
selected_tenant_id = request.session.get('tenant_id') selected_tenant_id = request.session.get('tenant_id')
@ -148,7 +149,7 @@ def delete_interaction(request, interaction_id):
if request.method == 'POST': if request.method == 'POST':
interaction.delete() interaction.delete()
messages.success(request, "Interaction deleted.") messages.success(request, "Interaction deleted.")
return redirect('voter_detail', voter_id=voter_id) return redirect(reverse('voter_detail', kwargs={'voter_id': voter_id}) + '?active_tab=interactions')
def add_donation(request, voter_id): def add_donation(request, voter_id):
selected_tenant_id = request.session.get('tenant_id') selected_tenant_id = request.session.get('tenant_id')
@ -162,7 +163,7 @@ def add_donation(request, voter_id):
donation.voter = voter donation.voter = voter
donation.save() donation.save()
messages.success(request, "Donation recorded.") messages.success(request, "Donation recorded.")
return redirect('voter_detail', voter_id=voter.id) return redirect(reverse('voter_detail', kwargs={'voter_id': voter.id}) + '?active_tab=donations')
def edit_donation(request, donation_id): def edit_donation(request, donation_id):
selected_tenant_id = request.session.get('tenant_id') selected_tenant_id = request.session.get('tenant_id')
@ -174,7 +175,7 @@ def edit_donation(request, donation_id):
if form.is_valid(): if form.is_valid():
form.save() form.save()
messages.success(request, "Donation updated.") messages.success(request, "Donation updated.")
return redirect('voter_detail', voter_id=donation.voter.id) return redirect(reverse('voter_detail', kwargs={'voter_id': donation.voter.id}) + '?active_tab=donations')
def delete_donation(request, donation_id): def delete_donation(request, donation_id):
selected_tenant_id = request.session.get('tenant_id') selected_tenant_id = request.session.get('tenant_id')
@ -185,7 +186,7 @@ def delete_donation(request, donation_id):
if request.method == 'POST': if request.method == 'POST':
donation.delete() donation.delete()
messages.success(request, "Donation deleted.") messages.success(request, "Donation deleted.")
return redirect('voter_detail', voter_id=voter_id) return redirect(reverse('voter_detail', kwargs={'voter_id': voter_id}) + '?active_tab=donations')
def add_likelihood(request, voter_id): def add_likelihood(request, voter_id):
selected_tenant_id = request.session.get('tenant_id') selected_tenant_id = request.session.get('tenant_id')
@ -246,7 +247,7 @@ def add_event_participation(request, voter_id):
messages.success(request, "Event participation added.") messages.success(request, "Event participation added.")
else: else:
messages.warning(request, "Voter is already participating in this event.") messages.warning(request, "Voter is already participating in this event.")
return redirect('voter_detail', voter_id=voter.id) return redirect(reverse('voter_detail', kwargs={'voter_id': voter.id}) + '?active_tab=events')
def edit_event_participation(request, participation_id): def edit_event_participation(request, participation_id):
selected_tenant_id = request.session.get('tenant_id') selected_tenant_id = request.session.get('tenant_id')
@ -262,7 +263,7 @@ def edit_event_participation(request, participation_id):
else: else:
form.save() form.save()
messages.success(request, "Event participation updated.") messages.success(request, "Event participation updated.")
return redirect('voter_detail', voter_id=participation.voter.id) return redirect(reverse('voter_detail', kwargs={'voter_id': participation.voter.id}) + '?active_tab=events')
def delete_event_participation(request, participation_id): def delete_event_participation(request, participation_id):
selected_tenant_id = request.session.get('tenant_id') selected_tenant_id = request.session.get('tenant_id')
@ -273,7 +274,7 @@ def delete_event_participation(request, participation_id):
if request.method == 'POST': if request.method == 'POST':
participation.delete() participation.delete()
messages.success(request, "Event participation removed.") messages.success(request, "Event participation removed.")
return redirect('voter_detail', voter_id=voter_id) return redirect(reverse('voter_detail', kwargs={'voter_id': voter_id}) + '?active_tab=events')
def event_type_list(request): def event_type_list(request):
""" """