.7
This commit is contained in:
parent
e2ad03e446
commit
14bf8d7295
15
ERD.md
15
ERD.md
@ -7,7 +7,6 @@ erDiagram
|
||||
Tenant ||--o{ DonationMethod : defines
|
||||
Tenant ||--o{ ElectionType : defines
|
||||
Tenant ||--o{ EventType : defines
|
||||
Tenant ||--o{ ParticipationType : defines
|
||||
Tenant ||--o{ Voter : belongs_to
|
||||
Tenant ||--o{ Event : organizes
|
||||
|
||||
@ -25,7 +24,6 @@ erDiagram
|
||||
InteractionType ||--o{ Interaction : categorizes
|
||||
DonationMethod ||--o{ Donation : categorizes
|
||||
ElectionType ||--o{ VoterLikelihood : categorizes
|
||||
ParticipationType ||--o{ EventParticipation : categorizes
|
||||
|
||||
Tenant {
|
||||
int id PK
|
||||
@ -78,13 +76,6 @@ erDiagram
|
||||
boolean is_active
|
||||
}
|
||||
|
||||
ParticipationType {
|
||||
int id PK
|
||||
int tenant_id FK
|
||||
string name
|
||||
boolean is_active
|
||||
}
|
||||
|
||||
Voter {
|
||||
int id PK
|
||||
int tenant_id FK
|
||||
@ -105,6 +96,7 @@ erDiagram
|
||||
VotingRecord {
|
||||
int id PK
|
||||
int voter_id FK
|
||||
string participation_type
|
||||
date election_date
|
||||
string election_description
|
||||
string primary_party
|
||||
@ -122,12 +114,13 @@ erDiagram
|
||||
int id PK
|
||||
int event_id FK
|
||||
int voter_id FK
|
||||
int participation_type_id FK
|
||||
string participation_type
|
||||
}
|
||||
|
||||
Donation {
|
||||
int id PK
|
||||
int voter_id FK
|
||||
string participation_type
|
||||
date date
|
||||
int method_id FK
|
||||
decimal amount
|
||||
@ -136,6 +129,7 @@ erDiagram
|
||||
Interaction {
|
||||
int id PK
|
||||
int voter_id FK
|
||||
string participation_type
|
||||
int type_id FK
|
||||
date date
|
||||
string description
|
||||
@ -145,6 +139,7 @@ erDiagram
|
||||
VoterLikelihood {
|
||||
int id PK
|
||||
int voter_id FK
|
||||
string participation_type
|
||||
int election_type_id FK
|
||||
string likelihood
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,8 +1,7 @@
|
||||
from django.contrib import admin
|
||||
from .models import (
|
||||
Tenant, TenantUserRole, InteractionType, DonationMethod, ElectionType, EventType,
|
||||
ParticipationType, Voter, VotingRecord, Event, EventParticipation, Donation,
|
||||
Interaction, VoterLikelihood
|
||||
Tenant, TenantUserRole, InteractionType, DonationMethod, ElectionType, EventType, Voter,
|
||||
VotingRecord, Event, EventParticipation, Donation, Interaction, VoterLikelihood
|
||||
)
|
||||
|
||||
class TenantUserRoleInline(admin.TabularInline):
|
||||
@ -45,12 +44,6 @@ class EventTypeAdmin(admin.ModelAdmin):
|
||||
list_filter = ('tenant', 'is_active')
|
||||
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):
|
||||
model = VotingRecord
|
||||
extra = 1
|
||||
@ -82,4 +75,4 @@ class EventAdmin(admin.ModelAdmin):
|
||||
@admin.register(EventParticipation)
|
||||
class EventParticipationAdmin(admin.ModelAdmin):
|
||||
list_display = ('voter', 'event', 'participation_type')
|
||||
list_filter = ('event__tenant', 'event', 'participation_type')
|
||||
list_filter = ('event__tenant', 'event', 'participation_type')
|
||||
|
||||
@ -71,7 +71,7 @@ class VoterLikelihoodForm(forms.ModelForm):
|
||||
class EventParticipationForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = EventParticipation
|
||||
fields = ['event']
|
||||
fields = ['event', 'participation_type']
|
||||
|
||||
def __init__(self, *args, tenant=None, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
@ -80,6 +80,7 @@ class EventParticipationForm(forms.ModelForm):
|
||||
for field in self.fields.values():
|
||||
field.widget.attrs.update({'class': 'form-control'})
|
||||
self.fields['event'].widget.attrs.update({'class': 'form-select'})
|
||||
self.fields['participation_type'].widget.attrs.update({'class': 'form-select'})
|
||||
|
||||
class EventForm(forms.ModelForm):
|
||||
class Meta:
|
||||
@ -108,4 +109,4 @@ class EventTypeForm(forms.ModelForm):
|
||||
for field in self.fields.values():
|
||||
if not isinstance(field.widget, forms.CheckboxInput):
|
||||
field.widget.attrs.update({'class': 'form-control'})
|
||||
self.fields['is_active'].widget.attrs.update({'class': 'form-check-input'})
|
||||
self.fields['is_active'].widget.attrs.update({'class': 'form-check-input'})
|
||||
|
||||
@ -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),
|
||||
),
|
||||
]
|
||||
@ -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'),
|
||||
),
|
||||
]
|
||||
Binary file not shown.
@ -41,7 +41,7 @@ class InteractionType(models.Model):
|
||||
unique_together = ('tenant', 'name')
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
return f"{self.name} ({self.tenant.name})"
|
||||
|
||||
class DonationMethod(models.Model):
|
||||
tenant = models.ForeignKey(Tenant, on_delete=models.CASCADE, related_name='donation_methods')
|
||||
@ -52,7 +52,7 @@ class DonationMethod(models.Model):
|
||||
unique_together = ('tenant', 'name')
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
return f"{self.name} ({self.tenant.name})"
|
||||
|
||||
class ElectionType(models.Model):
|
||||
tenant = models.ForeignKey(Tenant, on_delete=models.CASCADE, related_name='election_types')
|
||||
@ -63,7 +63,7 @@ class ElectionType(models.Model):
|
||||
unique_together = ('tenant', 'name')
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
return f"{self.name} ({self.tenant.name})"
|
||||
|
||||
class EventType(models.Model):
|
||||
tenant = models.ForeignKey(Tenant, on_delete=models.CASCADE, related_name='event_types')
|
||||
@ -74,18 +74,7 @@ class EventType(models.Model):
|
||||
unique_together = ('tenant', 'name')
|
||||
|
||||
def __str__(self):
|
||||
return self.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
|
||||
return f"{self.name} ({self.tenant.name})"
|
||||
|
||||
class Voter(models.Model):
|
||||
SUPPORT_CHOICES = [
|
||||
@ -136,12 +125,18 @@ class Event(models.Model):
|
||||
return f"{self.event_type} on {self.date}"
|
||||
|
||||
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')
|
||||
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):
|
||||
return f"{self.voter} at {self.event}"
|
||||
return f"{self.voter} at {self.event} ({self.get_participation_type_display()})"
|
||||
|
||||
class Donation(models.Model):
|
||||
voter = models.ForeignKey(Voter, on_delete=models.CASCADE, related_name='donations')
|
||||
@ -176,4 +171,4 @@ class VoterLikelihood(models.Model):
|
||||
unique_together = ('voter', 'election_type')
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.voter} - {self.election_type}: {self.get_likelihood_display()}"
|
||||
return f"{self.voter} - {self.election_type}: {self.get_likelihood_display()}"
|
||||
|
||||
@ -283,6 +283,7 @@
|
||||
<tr>
|
||||
<th class="ps-4">Date</th>
|
||||
<th>Event Type</th>
|
||||
<th>Type</th>
|
||||
<th>Description</th>
|
||||
<th class="pe-4 text-end">Actions</th>
|
||||
</tr>
|
||||
@ -292,6 +293,15 @@
|
||||
<tr>
|
||||
<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>
|
||||
{% 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="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 }}">
|
||||
@ -303,7 +313,7 @@
|
||||
</td>
|
||||
</tr>
|
||||
{% 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 %}
|
||||
</tbody>
|
||||
</table>
|
||||
@ -685,10 +695,14 @@
|
||||
<form action="{% url 'add_event_participation' voter.id %}" method="POST">
|
||||
{% csrf_token %}
|
||||
<div class="modal-body p-4">
|
||||
<div class="mb-0">
|
||||
<div class="mb-3">
|
||||
<label class="form-label fw-medium">Select Event</label>
|
||||
{{ event_participation_form.event }}
|
||||
</div>
|
||||
<div class="mb-0">
|
||||
<label class="form-label fw-medium">Participation Status</label>
|
||||
{{ event_participation_form.participation_type }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer border-0 p-4 pt-0">
|
||||
<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">
|
||||
{% csrf_token %}
|
||||
<div class="modal-body p-4">
|
||||
<div class="mb-0">
|
||||
<div class="mb-3">
|
||||
<label class="form-label fw-medium">Event</label>
|
||||
<select name="event" class="form-select">
|
||||
{% for ev in event_participation_form.fields.event.queryset %}
|
||||
@ -719,6 +733,14 @@
|
||||
{% endfor %}
|
||||
</select>
|
||||
</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 class="modal-footer border-0 p-4 pt-0">
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal">Cancel</button>
|
||||
@ -778,5 +800,22 @@
|
||||
border-color: #059669;
|
||||
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>
|
||||
{% endblock %}
|
||||
|
||||
<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 %}
|
||||
@ -1,3 +1,4 @@
|
||||
from django.urls import reverse
|
||||
from django.shortcuts import render, redirect, get_object_or_404
|
||||
from django.db.models import Q
|
||||
from django.contrib import messages
|
||||
@ -125,7 +126,7 @@ def add_interaction(request, voter_id):
|
||||
interaction.voter = voter
|
||||
interaction.save()
|
||||
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):
|
||||
selected_tenant_id = request.session.get('tenant_id')
|
||||
@ -137,7 +138,7 @@ def edit_interaction(request, interaction_id):
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
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):
|
||||
selected_tenant_id = request.session.get('tenant_id')
|
||||
@ -148,7 +149,7 @@ def delete_interaction(request, interaction_id):
|
||||
if request.method == 'POST':
|
||||
interaction.delete()
|
||||
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):
|
||||
selected_tenant_id = request.session.get('tenant_id')
|
||||
@ -162,7 +163,7 @@ def add_donation(request, voter_id):
|
||||
donation.voter = voter
|
||||
donation.save()
|
||||
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):
|
||||
selected_tenant_id = request.session.get('tenant_id')
|
||||
@ -174,7 +175,7 @@ def edit_donation(request, donation_id):
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
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):
|
||||
selected_tenant_id = request.session.get('tenant_id')
|
||||
@ -185,7 +186,7 @@ def delete_donation(request, donation_id):
|
||||
if request.method == 'POST':
|
||||
donation.delete()
|
||||
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):
|
||||
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.")
|
||||
else:
|
||||
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):
|
||||
selected_tenant_id = request.session.get('tenant_id')
|
||||
@ -262,7 +263,7 @@ def edit_event_participation(request, participation_id):
|
||||
else:
|
||||
form.save()
|
||||
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):
|
||||
selected_tenant_id = request.session.get('tenant_id')
|
||||
@ -273,7 +274,7 @@ def delete_event_participation(request, participation_id):
|
||||
if request.method == 'POST':
|
||||
participation.delete()
|
||||
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):
|
||||
"""
|
||||
@ -330,4 +331,4 @@ def event_type_delete(request, type_id):
|
||||
messages.success(request, "Event type deleted.")
|
||||
except Exception as e:
|
||||
messages.error(request, f"Cannot delete event type: {e}")
|
||||
return redirect('event_type_list')
|
||||
return redirect('event_type_list')
|
||||
Loading…
x
Reference in New Issue
Block a user