Skip to content

Create Sponsor model and Sponsor view #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ django-hashid-field = "*"
django-celery-beat = "*"
flower = "*"
discord-py = "==2.5.0"
pillow = "*"

[dev-packages]

Expand Down
80 changes: 79 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ kombu==5.5.0; python_version >= '3.8'
multidict==6.1.0; python_version >= '3.8'
mysqlclient==2.2.7; python_version >= '3.8'
packaging==24.2; python_version >= '3.8'
pillow==11.1.0; python_version >= '3.9'
prometheus-client==0.21.1; python_version >= '3.8'
prompt-toolkit==3.0.50; python_full_version >= '3.8.0'
propcache==0.3.0; python_version >= '3.9'
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ kombu==5.5.0; python_version >= '3.8'
multidict==6.1.0; python_version >= '3.8'
mysqlclient==2.2.7; python_version >= '3.8'
packaging==24.2; python_version >= '3.8'
pillow==11.1.0; python_version >= '3.9'
prometheus-client==0.21.1; python_version >= '3.8'
prompt-toolkit==3.0.50; python_full_version >= '3.8.0'
propcache==0.3.0; python_version >= '3.9'
Expand Down
4 changes: 3 additions & 1 deletion src/contestsuite/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

from django.contrib import admin
from django.urls import include, path
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
path('', include('core.urls')),
Expand All @@ -27,4 +29,4 @@
path('lfg/', include('lfg.urls')),
path('manage/', include('manager.urls')),
path('register/', include('register.urls')),
]
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
33 changes: 25 additions & 8 deletions src/core/admin.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,49 @@
from django.contrib import admin
from django.contrib.auth.models import User
from django.utils.html import mark_safe
from . import models

from import_export import resources
from import_export.admin import ImportExportModelAdmin


class UserResource(resources.ModelResource):
"""
Attach User model to Django-Import-Export
https://django-import-export.readthedocs.io/en/latest/getting_started.html#creating-a-resource
"""
class Meta:
model = User
fields = ('first_name', 'last_name', 'email', 'is_active', 'profile__checked_in')
"""
Attach User model to Django-Import-Export
https://django-import-export.readthedocs.io/en/latest/getting_started.html#creating-a-resource
"""
class Meta:
model = User
fields = ('first_name', 'last_name', 'email', 'is_active', 'profile__checked_in')


class UserAdmin(ImportExportModelAdmin):
"""
Django-Import-Export resource admin intrgration
https://django-import-export.readthedocs.io/en/latest/advanced_usage.html#admin-integration
"""
resource_class = UserResource
list_display = ("last_name", "first_name", "username", "email", "is_active",)
list_filter = ("is_active",)
search_fields = ["last_name", "first_name", "username", "email"]


class SponsorAdmin(admin.ModelAdmin):
"""
Define Sponsor model interface in Django Admin.
https://docs.djangoproject.com/en/4.2/ref/contrib/admin/#modeladmin-objects
"""

list_display = ('name', 'url', 'logo_thumbnail', 'message')
search_fields = ['name', 'message']

def logo_thumbnail(self, obj):
if obj.logo:
return mark_safe(f'<img src="{obj.logo.url}" style="width: 300px; height: auto;" />')
return '-'

# Re-register User model for django-import-export integration
admin.site.unregister(User)
admin.site.register(User, UserAdmin)
admin.site.register(models.Sponsor, SponsorAdmin)
24 changes: 24 additions & 0 deletions src/core/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.20 on 2025-03-30 15:49

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Sponsor',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200, unique=True)),
('logo', models.ImageField(upload_to='sponsors')),
('url', models.URLField(blank=True)),
('message', models.TextField(blank=True)),
],
),
]
22 changes: 22 additions & 0 deletions src/core/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
from django.db import models

# Create your models here.

class Sponsor(models.Model):
"""
Contest sponsor model. Each model stores the details of a contest sponsor, including
name, logo, link to sponsor's website, and message.

name (CharField): the sponsor name (unique)

logo (ImageField): the sponsor logo

url (URLField): the sponsor URL

message (TextField): the sponsor message
"""

name = models.CharField(max_length=200, unique=True)
logo = models.ImageField(upload_to='sponsors')
url = models.URLField(blank=True)
message = models.TextField(blank=True)

def __str__(self):
return self.name
34 changes: 24 additions & 10 deletions src/core/templates/core/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,35 @@ <h4 class="text-center">Format</h4>
</div>
<!-- Sponsors Column -->
<div class="col-md-4 border-left border-secondary d-none d-md-block my-3">
<h4 class="text-center">Sponsors</h4>
<a href="{% url 'sponsors' %}" class="text-decoration-none text-reset disabled">
<h4 class="text-center">Sponsors</h4>
</a>
<div class="text-center">
<img src="{% static 'core/img/fsucslogo.png' %}" class="img-fluid w-75 my-2" alt="FSU CS Logo">
<img src="{% static 'core/img/L3Harris_logo.png' %}" class="img-fluid w-75 my-2" alt="L3Harris Logo">
<img src="{% static 'core/img/i2x.png' %}" class="img-fluid w-75 my-2" alt="i2x Solutions Logo">
<img src="{% static 'core/img/raymond_james.png' %}" class="img-fluid w-75 mt-2 mb-3" alt="Raymond James Logo">
{% for sponsor in sponsors %}
{% if sponsor.url %}
<a href="{{ sponsor.url }}" target="_blank">
{% endif %}
<img src="{{ sponsor.logo.url }}" class="img-fluid w-75 my-2" alt="{{ sponsor.name }}">
{% if sponsor.url %}
</a>
{% endif %}
{% endfor %}
</div>
</div>
<div class="col-md-4 d-block d-md-none">
<h4 class="text-center mt-3">Sponsors</h4>
<a href="{% url 'sponsors' %}" class="text-decoration-none text-reset disabled">
<h4 class="text-center mt-3">Sponsors</h4>
</a>
<div class="text-center">
<img src="{% static 'core/img/fsucslogo.png' %}" class="img-fluid w-75 my-2" alt="FSU CS Logo">
<img src="{% static 'core/img/L3Harris_logo.png' %}" class="img-fluid w-75 my-2" alt="L3Harris Logo">
<img src="{% static 'core/img/i2x.png' %}" class="img-fluid w-75 my-2" alt="i2x Solutions Logo">
<img src="{% static 'core/img/raymond_james.png' %}" class="img-fluid w-75 mt-2 mb-3" alt="Raymond James Logo">
{% for sponsor in sponsors %}
{% if sponsor.url %}
<a href="{{ sponsor.url }}" target="_blank">
{% endif %}
<img src="{{ sponsor.logo.url }}" class="img-fluid w-75 my-2" alt="{{ sponsor.name }}">
{% if sponsor.url %}
</a>
{% endif %}
{% endfor %}
</div>
</div>
</div>
Expand Down
61 changes: 61 additions & 0 deletions src/core/templates/core/sponsors.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{% extends 'base.html' %}
{% load static %}

{% block section %}Sponsors{% endblock %}

{% block content %}

<h1 class="text-center">Sponsors</h1>

{% if sponsors %}
<p class="text-center font-italic">This programming contest is made possible by...</p>
{% endif %}

<style>
.sponsor-card {
height: 180px;
transition: transform 0.3s ease;
background-color: #189cc5;
}

.sponsor-card:hover {
transform: scale(1.02);
}

.sponsor-overlay {
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.75);
transform: translateY(100%);
transition: transform 0.4s ease;
}

.sponsor-card:hover .sponsor-overlay {
transform: translateY(0);
}
</style>

<div class="row mt-5">
{% for sponsor in sponsors %}
<div class="col-md-4 mb-4">
{% if sponsor.url %}
<a href="{{ sponsor.url }}" target="_blank">
{% endif %}
<div class="sponsor-card position-relative overflow-hidden rounded shadow-sm">
<img src="{{ sponsor.logo.url }}" alt="{{ sponsor.name }}" class="p-2 w-100 h-100 d-block" style="object-fit: contain;">
<div class="sponsor-overlay p-3 position-absolute text-white text-center">
<h6 class="mb-2 font-weight-bold">{{ sponsor.name }}</h6>
<p class="mb-0 small font-italic">{{ sponsor.message }}</p>
</div>
</div>
{% if sponsor.url %}
</a>
{% endif %}
</div>
{% empty %}
<p class="text-center text-muted font-italic">No sponsors available.</p>
{% endfor %}
</div>

{% endblock %}
1 change: 1 addition & 0 deletions src/core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
path('contact/', views.ContactTemplateView.as_view(), name='contact'),
path('faq/', views.FaqTemplateView.as_view(), name='faq'),
path('teams/', views.TeamsTemplateView.as_view(), name='teams'),
path('sponsors/', views.SponsorsTemplateView.as_view(), name='sponsors'),
]
15 changes: 15 additions & 0 deletions src/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from register.models import Team
from manager.models import Course, Profile
from lfg.models import LFGProfile
from core.models import Sponsor

# Create your views here.

Expand Down Expand Up @@ -42,6 +43,8 @@ def get_context_data(self, **kwargs):

# Get published announcements
context['announcements'] = (Announcement.objects.filter(status=1))
context['sponsors'] = Sponsor.objects.all()

# Get all courses
context['courses'] = Course.objects.all()

Expand Down Expand Up @@ -131,3 +134,15 @@ def get_context_data(self, **kwargs):
context['num_faculty_participants'] = participants_set.filter(team__faculty=True).count()

return context

class SponsorsTemplateView(TemplateView):
"""
View to display sponsors page.
"""

template_name = 'core/sponsors.html'

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['sponsors'] = Sponsor.objects.all()
return context
Loading