diff --git a/.gitignore b/.gitignore index 1123098e..26e1accf 100644 --- a/.gitignore +++ b/.gitignore @@ -30,4 +30,5 @@ staticroot/ site/ htmlcov/ +/media/ diff --git a/portal/settings.py b/portal/settings.py index 62bd9e3b..0a68f9e8 100644 --- a/portal/settings.py +++ b/portal/settings.py @@ -15,6 +15,11 @@ import dj_database_url +# from dotenv import load_dotenv + +# load_dotenv() + + # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -28,9 +33,9 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = bool(os.environ.get("DEBUG", default=0)) -ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS") -if ALLOWED_HOSTS: - ALLOWED_HOSTS = ALLOWED_HOSTS.split(",") +ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS", "127.0.0.1,localhost") +ALLOWED_HOSTS = ALLOWED_HOSTS.split(",") + # Application definition @@ -49,9 +54,11 @@ "allauth.account", "storages", "portal", + 'sponsorship', "volunteer", "portal_account", "widget_tweaks", + "sponsorship", ] DJANGO_TABLES2_TEMPLATE = "portal/base-tables-responsive.html" @@ -110,6 +117,7 @@ "PORT": os.environ.get("SQL_PORT", "5432"), } } + # Password validation @@ -298,3 +306,5 @@ "LOCATION": "stats_cache_table", } } + +DEBUG = True diff --git a/portal/urls.py b/portal/urls.py index dd361574..d8baf9cb 100644 --- a/portal/urls.py +++ b/portal/urls.py @@ -28,6 +28,7 @@ path("volunteer/", include("volunteer.urls", namespace="volunteer")), path("admin/", admin.site.urls), path("accounts/", include("allauth.urls")), + path("sponsorship/", include("sponsorship.urls", namespace="sponsorship")), path( "portal_account/", include("portal_account.urls", namespace="portal_account"), diff --git a/portal/views.py b/portal/views.py index aa9f178a..2b806a94 100644 --- a/portal/views.py +++ b/portal/views.py @@ -53,3 +53,6 @@ def index(request): context["teams"] = teams return render(request, "portal/index.html", context) + +def sponsorship_success(request): + return render(request, "sponsorship/success.html") \ No newline at end of file diff --git a/portal_account/urls.py b/portal_account/urls.py index d02c312c..227e3445 100644 --- a/portal_account/urls.py +++ b/portal_account/urls.py @@ -3,7 +3,7 @@ from . import views -app_name = "volunteer" +app_name = "portal_account" urlpatterns = [ path("", views.index, name="index"), diff --git a/requirements-app.txt b/requirements-app.txt index cd67911c..042c277c 100644 --- a/requirements-app.txt +++ b/requirements-app.txt @@ -14,3 +14,4 @@ boto3==1.38.5 django-storages==1.14.6 django-widget-tweaks==1.5.0 pillow==11.2.1 +python-dotenv diff --git a/requirements-dev.txt b/requirements-dev.txt index e7d3b481..638e9aa2 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -10,3 +10,4 @@ pytest-django==4.8.0 pytest==8.3.5 pytest-cov==6.1.1 coverage==7.7.0 +python-dotenv diff --git a/requirements-docs.txt b/requirements-docs.txt index bf4d970c..c152bbc8 100644 --- a/requirements-docs.txt +++ b/requirements-docs.txt @@ -3,4 +3,5 @@ mkdocs-awesome-nav==3.1.1 mkdocs-material[imaging] mkdocs-rss-plugin mkdocs-git-revision-date-localized-plugin -mkdocs-git-committers-plugin-2 \ No newline at end of file +mkdocs-git-committers-plugin-2 +python-dotenv \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 12514f2e..da091061 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,14 @@ -r requirements-docs.txt +python-dotenv +asgiref==3.8.1 +Django==5.1.7 +django-allauth==65.5.0 +gunicorn==23.0.0 +packaging==24.2 +psycopg2-binary==2.9.10 +sqlparse==0.5.3 +django-bootstrap5==25.1 +whitenoise==6.9.0 +dj-database-url==2.3.0 +Pillow==11.1.0 + diff --git a/sponsorship/__init__.py b/sponsorship/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/sponsorship/admin.py b/sponsorship/admin.py new file mode 100644 index 00000000..b34cc0a9 --- /dev/null +++ b/sponsorship/admin.py @@ -0,0 +1,15 @@ +from django.contrib import admin +from .models import SponsorshipProfile, SponsorshipTier + +# Register your models here. +@admin.register(SponsorshipTier) +class SponsorshipTierAdmin(admin.ModelAdmin): + list_display = ('name', 'amount') + search_fields = ('name',) + ordering = ('amount',) + +@admin.register(SponsorshipProfile) +class SponsorshipProfileAdmin(admin.ModelAdmin): + list_display = ('sponsor_organization_name', 'main_contact','sponsorship_type', 'application_status') + list_filter = ('sponsorship_type', 'application_status', 'sponsorship_tier') + search_fields = ('sponsor_organization_name', 'main_contact__username') diff --git a/sponsorship/apps.py b/sponsorship/apps.py new file mode 100644 index 00000000..95cda0af --- /dev/null +++ b/sponsorship/apps.py @@ -0,0 +1,8 @@ +from django.apps import AppConfig + +class SponsorshipConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'sponsorship' + + def ready(self): + import sponsorship.signals # this registers the signals diff --git a/sponsorship/emails.py b/sponsorship/emails.py new file mode 100644 index 00000000..fcadceba --- /dev/null +++ b/sponsorship/emails.py @@ -0,0 +1,47 @@ +from django.core.mail import send_mail +from django.template.loader import render_to_string +from django.conf import settings + +def send_sponsorship_status_emails(profile): + user = profile.user + + # Email to sponsor + sponsor_subject = "Your Sponsorship Profile Has Been Approved" + sponsor_message = render_to_string("sponsorship/email/sponsor_status_update.txt", { + "user": user, + "profile": profile + }) + send_mail( + sponsor_subject, + sponsor_message, + settings.DEFAULT_FROM_EMAIL, + [user.email] + ) + + # Email to internal team (hardcoded for now) + team_subject = f"New Sponsorship Approved: {profile.organization_name}" + team_message = render_to_string("sponsorship/email/team_status_notification.txt", { + "user": user, + "profile": profile + }) + send_mail( + team_subject, + team_message, + settings.DEFAULT_FROM_EMAIL, + ["team@example.com"] # Replace with actual team emails later + ) +def send_sponsorship_profile_email(user, profile, is_update=False): + subject = "Sponsorship Profile Submission Received" + message = render_to_string("sponsorship/email/sponsor_status_update.txt", { + "user": user, + "profile": profile, + "is_update": is_update + }) + + send_mail( + subject, + message, + settings.DEFAULT_FROM_EMAIL, + [user.email], + fail_silently=False, + ) diff --git a/sponsorship/forms.py b/sponsorship/forms.py new file mode 100644 index 00000000..c4ba33c2 --- /dev/null +++ b/sponsorship/forms.py @@ -0,0 +1,37 @@ +from django import forms + +from .models import SponsorshipProfile + + +class SponsorshipProfileForm(forms.ModelForm): + class Meta: + model = SponsorshipProfile + fields = [ + 'main_contact', + 'sponsor_organization_name', + 'sponsorship_type', + 'sponsorship_tier', + 'logo', + 'company_description', + 'application_status', + ] + widgets = { + 'company_description': forms.Textarea(attrs={'rows': 4,}), + } + + def __init__(self, *args, **kwargs): + user = kwargs.pop("user", None) # Expecting current user from the view + super().__init__(*args, **kwargs) + + if user: + self.fields["main_contact"].initial = user + self.fields["main_contact"].disabled = True # Makes it read-only + + def save(self, commit=True): + instance = super().save(commit=False) + instance.main_contact = self._user # Enforce value + instance.application_status = 'pending' # Set status manually + if commit: + instance.save() + self.save_m2m() + return instance diff --git a/sponsorship/migrations/0001_initial.py b/sponsorship/migrations/0001_initial.py new file mode 100644 index 00000000..699ddf5f --- /dev/null +++ b/sponsorship/migrations/0001_initial.py @@ -0,0 +1,41 @@ +# Generated by Django 5.1.7 on 2025-03-29 05:58 + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='SponsorshipTier', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('amount', models.DecimalField(decimal_places=2, max_digits=10)), + ('name', models.CharField(max_length=100)), + ('description', models.TextField()), + ], + ), + migrations.CreateModel( + name='SponsorshipProfile', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('sponsor_organization_name', models.CharField(max_length=255)), + ('sponsorship_type', models.CharField(choices=[('individual', 'Individual'), ('organization', 'Organization/Company')], max_length=20)), + ('logo', models.ImageField(upload_to='sponsor_logos/')), + ('company_description', models.TextField()), + ('application_status', models.CharField(choices=[('pending', 'Pending'), ('approved', 'Approved'), ('rejected', 'Rejected'), ('cancelled', 'Cancelled')], default='pending', max_length=20)), + ('additional_contacts', models.ManyToManyField(blank=True, related_name='additional_sponsorship_contacts', to=settings.AUTH_USER_MODEL)), + ('main_contact', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='main_contact_for', to=settings.AUTH_USER_MODEL)), + ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='sponsorship_profile', to=settings.AUTH_USER_MODEL)), + ('sponsorship_tier', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='sponsorship.sponsorshiptier')), + ], + ), + ] diff --git a/sponsorship/migrations/__init__.py b/sponsorship/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/sponsorship/models.py b/sponsorship/models.py new file mode 100644 index 00000000..dafaac5f --- /dev/null +++ b/sponsorship/models.py @@ -0,0 +1,45 @@ +from django.db import models +from django.contrib.auth.models import User +from enum import StrEnum + + +class SponsorshipTier(models.Model): + amount = models.DecimalField(max_digits=10, decimal_places=2) + name = models.CharField(max_length=100) + description = models.TextField() + + def __str__(self): + return self.name + +class ApplicationStatus(StrEnum): + PENDING = "pending" + APPROVED = "approved" + REJECTED = "rejected" + CANCELLED = "cancelled" + +class SponsorshipProfile(models.Model): + INDIVIDUAL = 'individual' + ORGANIZATION = 'organization' + + SPONSORSHIP_TYPE_CHOICES = [ + (INDIVIDUAL, 'Individual'), + (ORGANIZATION, 'Organization/Company'), + ] + + user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='sponsorship_profile') + main_contact = models.OneToOneField(User, on_delete=models.CASCADE, related_name='main_contact_for') + additional_contacts = models.ManyToManyField(User, blank=True, related_name='additional_sponsorship_contacts') + sponsor_organization_name = models.CharField(max_length=255) + sponsorship_type = models.CharField(max_length=20, choices=SPONSORSHIP_TYPE_CHOICES) + sponsorship_tier = models.ForeignKey(SponsorshipTier, on_delete=models.SET_NULL, null=True) + logo = models.ImageField(upload_to='sponsor_logos/') + company_description = models.TextField() + application_status = models.CharField( + max_length=20, + choices=[(status.value, status.name.capitalize()) for status in ApplicationStatus], + default=ApplicationStatus.PENDING.value, +) + + + def __str__(self): + return self.sponsor_organization_name diff --git a/sponsorship/signals.py b/sponsorship/signals.py new file mode 100644 index 00000000..6bdee4da --- /dev/null +++ b/sponsorship/signals.py @@ -0,0 +1,59 @@ +from django.db.models.signals import post_save +from django.dispatch import receiver +from .models import SponsorshipProfile +from django.conf import settings +from django.template.loader import render_to_string +from django.core.mail import EmailMultiAlternatives +from django.contrib.sites.models import Site + + +def _send_email(subject, recipient_list, *, html_template=None, text_template=None, context=None): + context = context or {} + context["current_site"] = Site.objects.get_current() + + text_content = render_to_string(text_template, context) + html_content = render_to_string(html_template, context) + + msg = EmailMultiAlternatives( + subject, + text_content, + settings.DEFAULT_FROM_EMAIL, + recipient_list, + ) + msg.attach_alternative(html_content, "text/html") + msg.send() + + +@receiver(post_save, sender=SponsorshipProfile) +def sponsorship_profile_signal(sender, instance, created, **kwargs): + """Send emails when sponsorship profile is submitted or approved.""" + if created: + # Email on submission + subject = f"{settings.ACCOUNT_EMAIL_SUBJECT_PREFIX} Sponsorship Application Received" + _send_email( + subject, + [instance.user.email], + html_template="sponsorship/email/sponsor_status_update.html", + text_template="sponsorship/email/sponsor_status_update.txt", + context={"profile": instance}, + ) + elif instance.application_status == "approved": + # Email on approval + subject = f"{settings.ACCOUNT_EMAIL_SUBJECT_PREFIX} Sponsorship Profile Approved" + _send_email( + subject, + [instance.user.email], + html_template="sponsorship/email/sponsor_approved.html", + text_template="sponsorship/email/sponsor_approved.txt", + context={"profile": instance}, + ) + + # Internal team notification + internal_subject = f"{settings.ACCOUNT_EMAIL_SUBJECT_PREFIX} New Sponsorship Approved: {instance.organization_name}" + _send_email( + internal_subject, + ["team@example.com"], # Replace with real internal emails later + html_template="sponsorship/email/team_status_notification.html", + text_template="sponsorship/email/team_status_notification.txt", + context={"profile": instance}, + ) diff --git a/sponsorship/templates/sponsorship/create_profile.html b/sponsorship/templates/sponsorship/create_profile.html new file mode 100644 index 00000000..09981df0 --- /dev/null +++ b/sponsorship/templates/sponsorship/create_profile.html @@ -0,0 +1,13 @@ +{% extends "base.html" %} +{% block content %} +

+ Create Sponsorship Profile +

+
+ {% csrf_token %} + {{ form.as_p }} + +
+{% endblock content %} diff --git a/sponsorship/templates/sponsorship/email/sponsor_approved.html b/sponsorship/templates/sponsorship/email/sponsor_approved.html new file mode 100644 index 00000000..28dd7064 --- /dev/null +++ b/sponsorship/templates/sponsorship/email/sponsor_approved.html @@ -0,0 +1,7 @@ +

Hi {{ profile.user.first_name }},

+ +

Congratulations! Your sponsorship application for {{ profile.organization_name }} has been approved 🎉

+ +

We're excited to have you as a sponsor for PyLadiesCon. A team member will reach out soon with next steps and onboarding information.

+ +

Best,
The PyLadiesCon Team

diff --git a/sponsorship/templates/sponsorship/email/sponsor_approved.txt b/sponsorship/templates/sponsorship/email/sponsor_approved.txt new file mode 100644 index 00000000..92dfeee2 --- /dev/null +++ b/sponsorship/templates/sponsorship/email/sponsor_approved.txt @@ -0,0 +1,8 @@ +Hi {{ profile.user.first_name }}, + +Congratulations! Your sponsorship application for {{ profile.organization_name }} has been approved 🎉 + +We're excited to have you as a sponsor for PyLadiesCon. A team member will reach out soon with next steps and onboarding information. + +Best, +The PyLadiesCon Team diff --git a/sponsorship/templates/sponsorship/email/sponsor_status_update.html b/sponsorship/templates/sponsorship/email/sponsor_status_update.html new file mode 100644 index 00000000..3196eb62 --- /dev/null +++ b/sponsorship/templates/sponsorship/email/sponsor_status_update.html @@ -0,0 +1,7 @@ +

Hi {{ profile.user.first_name }},

+ +

Thank you for submitting your sponsorship application for {{ profile.organization_name }}!

+ +

We’ve received your profile and our team will review it shortly. You will receive a follow-up email once a decision has been made.

+ +

Best,
The PyLadiesCon Team

diff --git a/sponsorship/templates/sponsorship/email/sponsor_status_update.txt b/sponsorship/templates/sponsorship/email/sponsor_status_update.txt new file mode 100644 index 00000000..2e57e652 --- /dev/null +++ b/sponsorship/templates/sponsorship/email/sponsor_status_update.txt @@ -0,0 +1,8 @@ +Hi {{ profile.user.first_name }}, + +Thank you for submitting your sponsorship application for {{ profile.organization_name }}! + +We’ve received your profile and our team will review it shortly. You will receive a follow-up email once a decision has been made. + +Best, +The PyLadiesCon Team diff --git a/sponsorship/templates/sponsorship/email/team_status_notification.html b/sponsorship/templates/sponsorship/email/team_status_notification.html new file mode 100644 index 00000000..3b35e7bb --- /dev/null +++ b/sponsorship/templates/sponsorship/email/team_status_notification.html @@ -0,0 +1,9 @@ +

Hello team,

+ +

The sponsorship profile for {{ profile.organization_name }} has been approved.

+ +

Please review the profile and begin the sponsor onboarding process.

+ +

View profile: (Add internal link if available)

+ +

Thanks,
The System

diff --git a/sponsorship/templates/sponsorship/email/team_status_notification.txt b/sponsorship/templates/sponsorship/email/team_status_notification.txt new file mode 100644 index 00000000..d02d5bde --- /dev/null +++ b/sponsorship/templates/sponsorship/email/team_status_notification.txt @@ -0,0 +1,8 @@ +Hello team, + +The sponsorship profile for {{ profile.organization_name }} has been approved. + +Please review the profile and begin the sponsor onboarding process. + +Thanks, +The System diff --git a/sponsorship/templates/sponsorship/profile_form.html b/sponsorship/templates/sponsorship/profile_form.html new file mode 100644 index 00000000..638a337c --- /dev/null +++ b/sponsorship/templates/sponsorship/profile_form.html @@ -0,0 +1,29 @@ +{% extends "portal/base.html" %} +{% load static %} + +{% block content %} +
+

Create Sponsorship Profile

+ + {% if form.errors %} +
+ +
+ {% endif %} + +
+ {% csrf_token %} + {{ form.as_p }} + +
+
+{% endblock %} diff --git a/sponsorship/templates/sponsorship/sponsorship_profile_form.html b/sponsorship/templates/sponsorship/sponsorship_profile_form.html new file mode 100644 index 00000000..126a4081 --- /dev/null +++ b/sponsorship/templates/sponsorship/sponsorship_profile_form.html @@ -0,0 +1,23 @@ +{% extends "portal/base.html" %} +{% block content %} +

+ Create Sponsorship Profile +

+ {% if messages %} + + {% endif %} +
+ {% csrf_token %} + {{ form.as_p }} + +
+{% endblock content %} + diff --git a/sponsorship/templates/sponsorship/success.html b/sponsorship/templates/sponsorship/success.html new file mode 100644 index 00000000..b2e75873 --- /dev/null +++ b/sponsorship/templates/sponsorship/success.html @@ -0,0 +1,9 @@ +{% extends "portal/base.html" %} + +{% block content %} +
+

🎉 Thank you for your sponsorship submission!

+

Your sponsorship profile has been submitted successfully. We will review it and get back to you soon.

+ Return to Home +
+{% endblock %} diff --git a/sponsorship/tests.py b/sponsorship/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/sponsorship/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/sponsorship/urls.py b/sponsorship/urls.py new file mode 100644 index 00000000..ef4c53d0 --- /dev/null +++ b/sponsorship/urls.py @@ -0,0 +1,11 @@ +from . import views +from django.urls import path, include + + +app_name = 'sponsorship' + +urlpatterns = [ + path('profile/new/', views.create_sponsorship_profile, name='create'), + path('profile/success/', views.sponsorship_success, name='success'), + +] diff --git a/sponsorship/utils.py b/sponsorship/utils.py new file mode 100644 index 00000000..4b1d60cc --- /dev/null +++ b/sponsorship/utils.py @@ -0,0 +1,47 @@ +from django.template.loader import render_to_string +from django.core.mail import EmailMultiAlternatives +from django.conf import settings +from django.contrib.sites.models import Site +from django.contrib.auth.models import User +from django.db.models import Q + +from .models import SponsorshipProfile + +def _send_email(subject, recipient_list, *, html_template=None, text_template=None, context=None): + context = context or {} + context["current_site"] = Site.objects.get_current() + text_content = render_to_string(text_template, context=context) + html_content = render_to_string(html_template, context=context) + + msg = EmailMultiAlternatives(subject, text_content, settings.DEFAULT_FROM_EMAIL, recipient_list) + msg.attach_alternative(html_content, "text/html") + msg.send() + +def send_sponsor_onboarding_email(instance): + if instance.application_status == "approved": + context = {"profile": instance} + subject = f"{settings.ACCOUNT_EMAIL_SUBJECT_PREFIX} Welcome Sponsor!" + _send_email( + subject, + [instance.user.email], + html_template="sponsorship/email/sponsor_onboarding.html", + text_template="sponsorship/email/sponsor_onboarding.txt", + context=context, + ) + +def send_internal_sponsor_onboarding_email(instance): + if instance.application_status == "approved": + context = {"profile": instance} + subject = f"{settings.ACCOUNT_EMAIL_SUBJECT_PREFIX} New Sponsor Approved: {instance.organization_name}" + + # Notify internal team + internal_team = User.objects.filter(Q(is_staff=True) | Q(is_superuser=True)).distinct() + for user in internal_team: + context["recipient_name"] = user.get_full_name() or user.username + _send_email( + subject, + [user.email], + html_template="sponsorship/email/internal_sponsor_onboarding.html", + text_template="sponsorship/email/internal_sponsor_onboarding.txt", + context=context, + ) diff --git a/sponsorship/views.py b/sponsorship/views.py new file mode 100644 index 00000000..26fd83b2 --- /dev/null +++ b/sponsorship/views.py @@ -0,0 +1,26 @@ +from django.shortcuts import render, redirect +from .forms import SponsorshipProfileForm +from django.contrib.auth.decorators import login_required +from django.http import HttpResponse + +# Create your views here. + +@login_required +def create_sponsorship_profile(request): + if request.method == 'POST': + form = SponsorshipProfileForm(request.POST, request.FILES, user =request.user) + if form.is_valid(): + sponsorship_profile = form.save(commit=False) + sponsorship_profile.user = request.user # Assuming the user is logged in + sponsorship_profile.save() + form.save_m2m() # Save many-to-many relationships + return redirect('sponsorship:success') # Redirect to a success page or profile page + else: + form = SponsorshipProfileForm(user = request.user) + return render(request, 'portal/sponsorship/create_sponsorship_profile.html', {'form': form}) + +def success(request): + return HttpResponse("Sponsorship profile created successfully!") + +def sponsorship_success(request): + return render(request, "sponsorship/success.html") diff --git a/templates/portal/index.html b/templates/portal/index.html index a13ea3d7..a2073bcd 100644 --- a/templates/portal/index.html +++ b/templates/portal/index.html @@ -161,13 +161,12 @@

-

- Sponsor Us -

-

- Sponsorship package is coming soon! -

- +

Sponsor Us

+

Want to become a sponsor? Fill out your sponsorship profile and we'll follow up with details!

+ + Become a sponsor! + +
@@ -281,6 +280,9 @@

Sponsor and donate to the conference!

Sponsorship Prospectus + Create Sponsorship Profile + +

diff --git a/templates/portal/sponsorship/create_sponsorship_profile.html b/templates/portal/sponsorship/create_sponsorship_profile.html new file mode 100644 index 00000000..8e73b977 --- /dev/null +++ b/templates/portal/sponsorship/create_sponsorship_profile.html @@ -0,0 +1,13 @@ +{% extends "portal/base.html" %} +{% load static %} + +{% block content %} +
+

Create Sponsorship Profile

+
+ {% csrf_token %} + {{ form.as_p }} + +
+
+{% endblock %} diff --git a/tests/portal_account/test_views.py b/tests/portal_account/test_views.py index 6fdcf62c..fc1b613c 100644 --- a/tests/portal_account/test_views.py +++ b/tests/portal_account/test_views.py @@ -1,15 +1,24 @@ +from io import BytesIO + import pytest +from django.contrib.messages import get_messages +from django.core.files.uploadedfile import SimpleUploadedFile from django.urls import reverse +from PIL import Image from pytest_django.asserts import assertRedirects from portal_account.models import PortalProfile +from sponsorship.models import SponsorshipProfile + +# ----------------------------------------------------------------------------------- +# Portal Profile Tests +# ----------------------------------------------------------------------------------- @pytest.mark.django_db class TestPortalProfile: def test_portal_profile_view_requires_login(self, client): - response = client.get(reverse("portal_account:index")) assertRedirects(response, reverse("account_login") + "?next=/portal_account/") @@ -22,10 +31,8 @@ def test_portal_profile_view_no_profile(self, client, portal_user): def test_portal_profile_view_with_profile(self, client, portal_user): profile = PortalProfile(user=portal_user) profile.save() - client.force_login(portal_user) response = client.get(reverse("portal_account:index")) - assert response.context["profile_id"] == profile.id assert response.status_code == 200 @@ -41,12 +48,9 @@ def test_portal_profile_update_own_profile(self, client, portal_user): def test_portal_profile_cannot_edit_other_profile( self, client, portal_user, django_user_model ): - another_user = django_user_model.objects.create_user( - username="other", - ) + another_user = django_user_model.objects.create_user(username="other") another_profile = PortalProfile(user=another_user) another_profile.save() - client.force_login(portal_user) response = client.get( reverse( @@ -58,12 +62,9 @@ def test_portal_profile_cannot_edit_other_profile( def test_portal_profile_cannot_view_other_profile( self, client, portal_user, django_user_model ): - another_user = django_user_model.objects.create_user( - username="other", - ) + another_user = django_user_model.objects.create_user(username="other") another_profile = PortalProfile(user=another_user) another_profile.save() - client.force_login(portal_user) response = client.get( reverse( @@ -87,11 +88,70 @@ def test_portal_profile_cannot_create_another(self, client, portal_user): profile.save() client.force_login(portal_user) response = client.get(reverse("portal_account:portal_profile_new")) - assertRedirects(response, reverse("portal_account:index")) def test_portal_profile_create_if_doesnt_exist(self, client, portal_user): client.force_login(portal_user) response = client.get(reverse("portal_account:portal_profile_new")) + assert response.status_code == 200 + + +# ----------------------------------------------------------------------------------- +# Sponsorship Profile View Tests +# ----------------------------------------------------------------------------------- + +def create_sample_image(): + image = Image.new("RGB", (100, 100), color="red") + image_bytes = BytesIO() + image.save(image_bytes, format="PNG") + image_bytes.seek(0) + return image_bytes.read() + + +@pytest.mark.django_db +class TestSponsorshipViews: + + def test_create_sponsorship_profile_get(self, client, portal_user): + client.force_login(portal_user) + response = client.get(reverse("sponsorship:create_sponsorship_profile")) assert response.status_code == 200 + assert "form" in response.context + + def test_create_sponsorship_profile_post_valid(self, client, portal_user): + sample_image = create_sample_image() + logo = SimpleUploadedFile("logo.png", sample_image, content_type="image/png") + client.force_login(portal_user) + + data = { + "main_contact_user": portal_user.id, + "organization_name": "Test Organization", + "sponsorship_type": "Champion", + "company_description": "We support tech initiatives.", + } + file_data = {"logo": logo} + + response = client.post( + reverse("sponsorship:create_sponsorship_profile"), + data={**data, **file_data}, + follow=True, + ) + + assert response.status_code == 200 + assert SponsorshipProfile.objects.filter(user=portal_user).exists() + messages = [str(m) for m in get_messages(response.wsgi_request)] + assert "Sponsorship profile submitted successfully!" in messages + + def test_sponsorship_profile_str_returns_org_name(self, portal_user): + sample_image = create_sample_image() + logo = SimpleUploadedFile("logo.png", sample_image, content_type="image/png") + + profile = SponsorshipProfile.objects.create( + user=portal_user, + main_contact_user=portal_user, + organization_name="Test Org", + sponsorship_type="Champion", + logo=logo, + company_description="Test description", + ) + assert str(profile) == "Test Org" diff --git a/volunteer/migrations/0001_initial.py b/volunteer/migrations/0001_initial.py index a5b53395..322a2043 100644 --- a/volunteer/migrations/0001_initial.py +++ b/volunteer/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 5.1.7 on 2025-03-18 22:57 +# Generated by Django 5.1.7 on 2025-04-07 21:41 import django.db.models.deletion from django.conf import settings @@ -20,13 +20,13 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ("portal", "0001_initial"), + ('portal', '0001_initial'), migrations.swappable_dependency(settings.AUTH_USER_MODEL), ] operations = [ migrations.CreateModel( - name="Role", + name='Role', fields=[ ( "basemodel_ptr", @@ -48,291 +48,41 @@ class Migration(migrations.Migration): models.CharField(max_length=1000, verbose_name="description"), ), ], - bases=("portal.basemodel",), + bases=('portal.basemodel',), ), migrations.CreateModel( - name="Team", + name='Team', fields=[ - ( - "basemodel_ptr", - models.OneToOneField( - auto_created=True, - on_delete=django.db.models.deletion.CASCADE, - parent_link=True, - primary_key=True, - serialize=False, - to="portal.basemodel", - ), - ), - ( - "short_name", - models.CharField(max_length=40, verbose_name="name"), - ), - ( - "description", - models.CharField(max_length=1000, verbose_name="description"), - ), + ('basemodel_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='portal.basemodel')), + ('short_name', models.CharField(max_length=40, verbose_name='name')), + ('description', models.CharField(max_length=1000, verbose_name='description')), ], - bases=("portal.basemodel",), + bases=('portal.basemodel',), ), migrations.CreateModel( - name="VolunteerProfile", + name='VolunteerProfile', fields=[ - ( - "basemodel_ptr", - models.OneToOneField( - auto_created=True, - on_delete=django.db.models.deletion.CASCADE, - parent_link=True, - primary_key=True, - serialize=False, - to="portal.basemodel", - ), - ), - ( - "application_status", - models.CharField( - choices=[ - ( - volunteer.constants.ApplicationStatus["PENDING"], - volunteer.constants.ApplicationStatus["PENDING"], - ), - ( - volunteer.constants.ApplicationStatus["APPROVED"], - volunteer.constants.ApplicationStatus["APPROVED"], - ), - ( - volunteer.constants.ApplicationStatus["REJECTED"], - volunteer.constants.ApplicationStatus["REJECTED"], - ), - ( - volunteer.constants.ApplicationStatus["CANCELLED"], - volunteer.constants.ApplicationStatus["CANCELLED"], - ), - ], - default=volunteer.constants.ApplicationStatus["PENDING"], - max_length=50, - ), - ), - ("coc_agreement", models.BooleanField(default=False)), - ( - "github_username", - models.CharField(blank=True, max_length=50, null=True), - ), - ( - "discord_username", - models.CharField(blank=True, max_length=50, null=True), - ), - ( - "instagram_username", - models.CharField(blank=True, max_length=50, null=True), - ), - ( - "bluesky_username", - models.CharField(blank=True, max_length=100, null=True), - ), - ( - "mastodon_url", - models.CharField(blank=True, max_length=100, null=True), - ), - ( - "x_username", - models.CharField(blank=True, max_length=100, null=True), - ), - ( - "linkedin_url", - models.CharField(blank=True, max_length=100, null=True), - ), - ( - "pronouns", - models.CharField(blank=True, max_length=100, null=True), - ), - ( - "languages_spoken", - portal.models.ChoiceArrayField( - base_field=models.CharField( - blank=True, - choices=[ - ("af", "Afrikaans"), - ("ar", "Arabic"), - ("ar-dz", "Algerian Arabic"), - ("ast", "Asturian"), - ("az", "Azerbaijani"), - ("bg", "Bulgarian"), - ("be", "Belarusian"), - ("bn", "Bengali"), - ("br", "Breton"), - ("bs", "Bosnian"), - ("ca", "Catalan"), - ("ckb", "Central Kurdish (Sorani)"), - ("cs", "Czech"), - ("cy", "Welsh"), - ("da", "Danish"), - ("de", "German"), - ("dsb", "Lower Sorbian"), - ("el", "Greek"), - ("en", "English"), - ("en-au", "Australian English"), - ("en-gb", "British English"), - ("eo", "Esperanto"), - ("es", "Spanish"), - ("es-ar", "Argentinian Spanish"), - ("es-co", "Colombian Spanish"), - ("es-mx", "Mexican Spanish"), - ("es-ni", "Nicaraguan Spanish"), - ("es-ve", "Venezuelan Spanish"), - ("et", "Estonian"), - ("eu", "Basque"), - ("fa", "Persian"), - ("fi", "Finnish"), - ("fr", "French"), - ("fy", "Frisian"), - ("ga", "Irish"), - ("gd", "Scottish Gaelic"), - ("gl", "Galician"), - ("he", "Hebrew"), - ("hi", "Hindi"), - ("hr", "Croatian"), - ("hsb", "Upper Sorbian"), - ("hu", "Hungarian"), - ("hy", "Armenian"), - ("ia", "Interlingua"), - ("id", "Indonesian"), - ("ig", "Igbo"), - ("io", "Ido"), - ("is", "Icelandic"), - ("it", "Italian"), - ("ja", "Japanese"), - ("ka", "Georgian"), - ("kab", "Kabyle"), - ("kk", "Kazakh"), - ("km", "Khmer"), - ("kn", "Kannada"), - ("ko", "Korean"), - ("ky", "Kyrgyz"), - ("lb", "Luxembourgish"), - ("lt", "Lithuanian"), - ("lv", "Latvian"), - ("mk", "Macedonian"), - ("ml", "Malayalam"), - ("mn", "Mongolian"), - ("mr", "Marathi"), - ("ms", "Malay"), - ("my", "Burmese"), - ("nb", "Norwegian Bokmål"), - ("ne", "Nepali"), - ("nl", "Dutch"), - ("nn", "Norwegian Nynorsk"), - ("os", "Ossetic"), - ("pa", "Punjabi"), - ("pl", "Polish"), - ("pt", "Portuguese"), - ("pt-br", "Brazilian Portuguese"), - ("ro", "Romanian"), - ("ru", "Russian"), - ("sk", "Slovak"), - ("sl", "Slovenian"), - ("sq", "Albanian"), - ("sr", "Serbian"), - ("sr-latn", "Serbian Latin"), - ("sv", "Swedish"), - ("sw", "Swahili"), - ("ta", "Tamil"), - ("te", "Telugu"), - ("tg", "Tajik"), - ("th", "Thai"), - ("tk", "Turkmen"), - ("tr", "Turkish"), - ("tt", "Tatar"), - ("udm", "Udmurt"), - ("ug", "Uyghur"), - ("uk", "Ukrainian"), - ("ur", "Urdu"), - ("uz", "Uzbek"), - ("vi", "Vietnamese"), - ("zh-hans", "Simplified Chinese"), - ("zh-hant", "Traditional Chinese"), - ], - max_length=32, - ), - size=None, - ), - ), - ( - "pyladies_chapter", - models.CharField(blank=True, max_length=50, null=True), - ), - ( - "timezone", - models.CharField( - choices=[ - ("UTC+14", "UTC+14"), - ("UTC+13", "UTC+13"), - ("UTC+12", "UTC+12"), - ("UTC+11", "UTC+11"), - ("UTC+10", "UTC+10"), - ("UTC+9", "UTC+9"), - ("UTC+8", "UTC+8"), - ("UTC+7", "UTC+7"), - ("UTC+6", "UTC+6"), - ("UTC+5", "UTC+5"), - ("UTC+4", "UTC+4"), - ("UTC+3", "UTC+3"), - ("UTC+2", "UTC+2"), - ("UTC+1", "UTC+1"), - ("UTC", "UTC"), - ("UTC-1", "UTC-1"), - ("UTC-2", "UTC-2"), - ("UTC-3", "UTC-3"), - ("UTC-4", "UTC-4"), - ("UTC-5", "UTC-5"), - ("UTC-6", "UTC-6"), - ("UTC-7", "UTC-7"), - ("UTC-8", "UTC-8"), - ("UTC-9", "UTC-9"), - ("UTC-10", "UTC-10"), - ("UTC-11", "UTC-11"), - ("UTC-12", "UTC-12"), - ], - max_length=6, - ), - ), - ( - "roles", - models.ManyToManyField( - blank=True, - related_name="roles", - to="volunteer.role", - verbose_name="Roles", - ), - ), - ( - "teams", - models.ManyToManyField( - blank=True, - related_name="team", - to="volunteer.team", - verbose_name="team", - ), - ), - ( - "user", - models.OneToOneField( - on_delete=django.db.models.deletion.CASCADE, - to=settings.AUTH_USER_MODEL, - ), - ), + ('basemodel_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='portal.basemodel')), + ('application_status', models.CharField(choices=[(volunteer.constants.ApplicationStatus['PENDING'], volunteer.constants.ApplicationStatus['PENDING']), (volunteer.constants.ApplicationStatus['APPROVED'], volunteer.constants.ApplicationStatus['APPROVED']), (volunteer.constants.ApplicationStatus['REJECTED'], volunteer.constants.ApplicationStatus['REJECTED']), (volunteer.constants.ApplicationStatus['CANCELLED'], volunteer.constants.ApplicationStatus['CANCELLED'])], default=volunteer.constants.ApplicationStatus['PENDING'], max_length=50)), + ('github_username', models.CharField(blank=True, max_length=50, null=True)), + ('discord_username', models.CharField(blank=True, max_length=50, null=True)), + ('instagram_username', models.CharField(blank=True, max_length=50, null=True)), + ('bluesky_username', models.CharField(blank=True, max_length=100, null=True)), + ('mastodon_url', models.CharField(blank=True, max_length=100, null=True)), + ('x_username', models.CharField(blank=True, max_length=100, null=True)), + ('linkedin_url', models.CharField(blank=True, max_length=100, null=True)), + ('languages_spoken', models.CharField(blank=True, help_text='Comma-separated list of languages', max_length=255, null=True)), + ('pyladies_chapter', models.CharField(blank=True, max_length=50, null=True)), + ('timezone', models.CharField(choices=[('UTC+14', 'UTC+14'), ('UTC+13', 'UTC+13'), ('UTC+12', 'UTC+12'), ('UTC+11', 'UTC+11'), ('UTC+10', 'UTC+10'), ('UTC+9', 'UTC+9'), ('UTC+8', 'UTC+8'), ('UTC+7', 'UTC+7'), ('UTC+6', 'UTC+6'), ('UTC+5', 'UTC+5'), ('UTC+4', 'UTC+4'), ('UTC+3', 'UTC+3'), ('UTC+2', 'UTC+2'), ('UTC+1', 'UTC+1'), ('UTC', 'UTC'), ('UTC-1', 'UTC-1'), ('UTC-2', 'UTC-2'), ('UTC-3', 'UTC-3'), ('UTC-4', 'UTC-4'), ('UTC-5', 'UTC-5'), ('UTC-6', 'UTC-6'), ('UTC-7', 'UTC-7'), ('UTC-8', 'UTC-8'), ('UTC-9', 'UTC-9'), ('UTC-10', 'UTC-10'), ('UTC-11', 'UTC-11'), ('UTC-12', 'UTC-12')], max_length=6)), + ('roles', models.ManyToManyField(blank=True, related_name='roles', to='volunteer.role', verbose_name='Roles')), + ('teams', models.ManyToManyField(blank=True, related_name='team', to='volunteer.team', verbose_name='team')), + ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), ], - bases=("portal.basemodel",), + bases=('portal.basemodel',), ), migrations.AddField( - model_name="team", - name="team_leads", - field=models.ManyToManyField( - related_name="team_leads", - to="volunteer.volunteerprofile", - verbose_name="team leads", - ), + model_name='team', + name='team_leads', + field=models.ManyToManyField(related_name='team_leads', to='volunteer.volunteerprofile', verbose_name='team leads'), ), - migrations.RunPython(create_initial_roles, migrations.RunPython.noop), ] diff --git a/volunteer/migrations/0002_remove_volunteerprofile_coc_agreement_and_more.py b/volunteer/migrations/0002_remove_volunteerprofile_coc_agreement_and_more.py deleted file mode 100644 index 2c26f98b..00000000 --- a/volunteer/migrations/0002_remove_volunteerprofile_coc_agreement_and_more.py +++ /dev/null @@ -1,21 +0,0 @@ -# Generated by Django 5.1.7 on 2025-03-23 20:38 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("volunteer", "0001_initial"), - ] - - operations = [ - migrations.RemoveField( - model_name="volunteerprofile", - name="coc_agreement", - ), - migrations.RemoveField( - model_name="volunteerprofile", - name="pronouns", - ), - ] diff --git a/volunteer/models.py b/volunteer/models.py index 18687417..5a2374f6 100644 --- a/volunteer/models.py +++ b/volunteer/models.py @@ -15,6 +15,39 @@ from portal.models import BaseModel, ChoiceArrayField from portal.validators import validate_linked_in_pattern +from portal.models import BaseModel +from .constants import ApplicationStatus +from django.urls import reverse + +TIMEZONE_CHOICES = [ + ("UTC+14", "UTC+14"), + ("UTC+13", "UTC+13"), + ("UTC+12", "UTC+12"), + ("UTC+11", "UTC+11"), + ("UTC+10", "UTC+10"), + ("UTC+9", "UTC+9"), + ("UTC+8", "UTC+8"), + ("UTC+7", "UTC+7"), + ("UTC+6", "UTC+6"), + ("UTC+5", "UTC+5"), + ("UTC+4", "UTC+4"), + ("UTC+3", "UTC+3"), + ("UTC+2", "UTC+2"), + ("UTC+1", "UTC+1"), + ("UTC", "UTC"), + ("UTC-1", "UTC-1"), + ("UTC-2", "UTC-2"), + ("UTC-3", "UTC-3"), + ("UTC-4", "UTC-4"), + ("UTC-5", "UTC-5"), + ("UTC-6", "UTC-6"), + ("UTC-7", "UTC-7"), + ("UTC-8", "UTC-8"), + ("UTC-9", "UTC-9"), + ("UTC-10", "UTC-10"), + ("UTC-11", "UTC-11"), + ("UTC-12", "UTC-12"), +] from .constants import ApplicationStatus, Region, RoleTypes from .languages import LANGUAGES @@ -94,8 +127,11 @@ class VolunteerProfile(BaseModel): mastodon_url = models.CharField(max_length=100, blank=True, null=True) x_username = models.CharField(max_length=100, blank=True, null=True) linkedin_url = models.CharField(max_length=100, blank=True, null=True) - languages_spoken = ChoiceArrayField( - models.CharField(max_length=32, blank=True, choices=LANGUAGES) + languages_spoken = models.CharField( + max_length=255, + blank=True, + null=True, + help_text="Comma-separated list of languages" ) teams = models.ManyToManyField( "volunteer.Team", verbose_name="members", related_name="members", blank=True diff --git a/volunteer/urls.py b/volunteer/urls.py index 61f71904..a8ed0f6a 100644 --- a/volunteer/urls.py +++ b/volunteer/urls.py @@ -1,6 +1,5 @@ from django.contrib.auth.decorators import login_required -from django.urls import path - +from django.urls import path, include from . import views app_name = "volunteer" diff --git a/volunteer/views.py b/volunteer/views.py index 4da40ad2..c55b9399 100644 --- a/volunteer/views.py +++ b/volunteer/views.py @@ -21,6 +21,10 @@ VolunteerProfile, send_volunteer_onboarding_email, ) +from django.http import HttpResponse + +from .models import VolunteerProfile +from .forms import VolunteerProfileForm @login_required @@ -307,3 +311,5 @@ def post(self, request, pk): ) return redirect("volunteer:volunteer_profile_manage", pk=pk) +def sponsorship_success(request): + return HttpResponse("Thank you for submitting your sponsorship profile!")