Adding models to the sponsor.
This commit is contained in:
parent
cf81dbe870
commit
7cd82ea3bb
|
@ -49,6 +49,7 @@ INSTALLED_APPS = [
|
|||
'django_extensions',
|
||||
]
|
||||
|
||||
MEDIA_URL = '/media/'
|
||||
STATIC_URL = '/static/'
|
||||
STATIC_ROOT = local_dir('static')
|
||||
STATICFILES_DIRS = [local_dir('static_src')]
|
||||
|
@ -70,6 +71,7 @@ TEMPLATES = [
|
|||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.template.context_processors.media',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
'shop.context_processors.current_order',
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from django.conf.urls.static import static
|
||||
from allauth.account.views import (
|
||||
LoginView,
|
||||
LogoutView,
|
||||
|
@ -333,3 +334,5 @@ if settings.DEBUG:
|
|||
urlpatterns = [
|
||||
url(r'^__debug__/', include(debug_toolbar.urls)),
|
||||
] + urlpatterns
|
||||
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
|
|
16
src/sponsors/admin.py
Normal file
16
src/sponsors/admin.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
from django.contrib import admin
|
||||
|
||||
from .models import Sponsor, SponsorTier
|
||||
|
||||
|
||||
@admin.register(Sponsor)
|
||||
class SponsorAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'tier')
|
||||
|
||||
|
||||
@admin.register(SponsorTier)
|
||||
class SponsorTierAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'camp', 'weight')
|
||||
list_editable = ('weight',)
|
||||
list_filter = ('camp',)
|
||||
ordering = ('weight', )
|
32
src/sponsors/migrations/0001_initial.py
Normal file
32
src/sponsors/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11 on 2017-07-11 21:35
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import sponsors.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')),
|
||||
('created', models.DateTimeField(auto_now_add=True)),
|
||||
('updated', models.DateTimeField(auto_now=True)),
|
||||
('name', models.CharField(help_text='Name of the sponsor', max_length=150)),
|
||||
('tier', models.IntegerField(choices=[(1, 'Gold'), (2, 'Silver'), (3, 'Bronze'), (4, 'Sponsor')], help_text='The tier of the sponsorship')),
|
||||
('description', models.TextField(help_text='A short description of the sponsorship')),
|
||||
('logo', models.ImageField(help_text='A logo for the sponsor', upload_to=sponsors.models.get_sponsor_upload_path)),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
]
|
34
src/sponsors/migrations/0002_auto_20170711_2341.py
Normal file
34
src/sponsors/migrations/0002_auto_20170711_2341.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11 on 2017-07-11 21:41
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('sponsors', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='SponsorTier',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('created', models.DateTimeField(auto_now_add=True)),
|
||||
('updated', models.DateTimeField(auto_now=True)),
|
||||
('name', models.CharField(help_text='Name of the tier (gold, silver, etc.)', max_length=25)),
|
||||
('description', models.TextField(help_text='A description of what the tier includes.')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='sponsor',
|
||||
name='tier',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='sponsors.SponsorTier'),
|
||||
),
|
||||
]
|
22
src/sponsors/migrations/0003_sponsortier_camp.py
Normal file
22
src/sponsors/migrations/0003_sponsortier_camp.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11 on 2017-07-11 21:45
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('camps', '0021_auto_20170711_2247'),
|
||||
('sponsors', '0002_auto_20170711_2341'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='sponsortier',
|
||||
name='camp',
|
||||
field=models.ForeignKey(help_text='The camp this sponsor tier belongs to', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='sponsor_tiers', to='camps.Camp'),
|
||||
),
|
||||
]
|
20
src/sponsors/migrations/0004_sponsortier_weight.py
Normal file
20
src/sponsors/migrations/0004_sponsortier_weight.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.5 on 2017-07-14 21:09
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('sponsors', '0003_sponsortier_camp'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='sponsortier',
|
||||
name='weight',
|
||||
field=models.IntegerField(default=0, help_text='This decides where on the list the tier will be shown. I.e.\n gold should have a lower value than silver.'),
|
||||
),
|
||||
]
|
20
src/sponsors/migrations/0005_sponsor_url.py
Normal file
20
src/sponsors/migrations/0005_sponsor_url.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.5 on 2017-07-14 21:56
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('sponsors', '0004_sponsortier_weight'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='sponsor',
|
||||
name='url',
|
||||
field=models.URLField(blank=True, help_text='A URL to the sponsor.', null=True),
|
||||
),
|
||||
]
|
67
src/sponsors/models.py
Normal file
67
src/sponsors/models.py
Normal file
|
@ -0,0 +1,67 @@
|
|||
from django.db import models
|
||||
|
||||
from utils.models import CampRelatedModel, CreatedUpdatedModel
|
||||
|
||||
|
||||
def get_sponsor_upload_path(instance, filename):
|
||||
return 'public/sponsors/{camp_slug}/{filename}'.format(
|
||||
camp_slug=instance.tier.camp.slug,
|
||||
filename='{}_logo.{}'.format(
|
||||
instance.name.lower(),
|
||||
filename.split('.')[-1]
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class Sponsor(CreatedUpdatedModel):
|
||||
name = models.CharField(
|
||||
max_length=150,
|
||||
help_text='Name of the sponsor'
|
||||
)
|
||||
|
||||
tier = models.ForeignKey('sponsors.SponsorTier')
|
||||
|
||||
description = models.TextField(
|
||||
help_text='A short description of the sponsorship'
|
||||
)
|
||||
|
||||
logo = models.ImageField(
|
||||
upload_to=get_sponsor_upload_path,
|
||||
help_text='A logo for the sponsor'
|
||||
)
|
||||
|
||||
url = models.URLField(
|
||||
null=True,
|
||||
blank=True,
|
||||
help_text="A URL to the sponsor."
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return '{} ({})'.format(self.name, self.tier.camp)
|
||||
|
||||
|
||||
class SponsorTier(CampRelatedModel):
|
||||
name = models.CharField(
|
||||
max_length=25,
|
||||
help_text='Name of the tier (gold, silver, etc.)'
|
||||
)
|
||||
|
||||
description = models.TextField(
|
||||
help_text='A description of what the tier includes.'
|
||||
)
|
||||
|
||||
camp = models.ForeignKey(
|
||||
'camps.Camp',
|
||||
null=True,
|
||||
related_name='sponsor_tiers',
|
||||
help_text='The camp this sponsor tier belongs to',
|
||||
)
|
||||
|
||||
weight = models.IntegerField(
|
||||
default=0,
|
||||
help_text="""This decides where on the list the tier will be shown. I.e.
|
||||
gold should have a lower value than silver."""
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return '{} ({})'.format(self.name, self.camp)
|
54
src/sponsors/templates/sponsors.html
Normal file
54
src/sponsors/templates/sponsors.html
Normal file
|
@ -0,0 +1,54 @@
|
|||
{% extends 'base.html' %}
|
||||
{% load static from staticfiles %}
|
||||
|
||||
{% block title %}
|
||||
Sponsors | {{ block.super }}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h2>{{ view.camp.title }} Sponsors</h2>
|
||||
|
||||
<p class="lead">
|
||||
This is a list of the {{ view.camp.title }} sponsors. An event like BornHack
|
||||
can not be built on hard work and good intentions alone - it would simply not
|
||||
have been possible without the financial help from these organisations. Thank
|
||||
you, we are immensely grateful!
|
||||
</p>
|
||||
|
||||
|
||||
{% for sponsor in sponsors %}
|
||||
|
||||
{% ifchanged sponsor.tier %}
|
||||
{% if forloop.first != True %}
|
||||
</section>
|
||||
{% endif %}
|
||||
<div class="page-header">
|
||||
<h1>{{ sponsor.tier.name}} <small>{{ sponsor.tier.description}}</small></h1>
|
||||
</div>
|
||||
<section>
|
||||
|
||||
{% endifchanged %}
|
||||
|
||||
<div class="sponsor thumbnail">
|
||||
{% if sponsor.url %}
|
||||
<a href="{{ sponsor.url }}">
|
||||
{% endif %}
|
||||
<img src="{{ sponsor.logo.url }}" />
|
||||
|
||||
<div class="caption">
|
||||
{{ sponsor.description }}
|
||||
</div>
|
||||
|
||||
{% if sponsor.url %}
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if forloop.last == True %}
|
||||
</section>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% endblock %}
|
|
@ -1,10 +1,17 @@
|
|||
from django.views.generic import TemplateView
|
||||
from django.views.generic import TemplateView, ListView
|
||||
from camps.mixins import CampViewMixin
|
||||
|
||||
from .models import Sponsor
|
||||
|
||||
class SponsorsView(CampViewMixin, TemplateView):
|
||||
def get_template_names(self):
|
||||
return '%s_sponsors.html' % self.camp.slug
|
||||
|
||||
class SponsorsView(CampViewMixin, ListView):
|
||||
model = Sponsor
|
||||
template_name = 'sponsors.html'
|
||||
context_object_name = 'sponsors'
|
||||
|
||||
def get_queryset(self, **kwargs):
|
||||
queryset = super().get_queryset()
|
||||
return queryset.filter(tier__camp=self.camp).order_by('tier__weight')
|
||||
|
||||
|
||||
class CallForSponsorsView(CampViewMixin, TemplateView):
|
||||
|
|
|
@ -117,10 +117,6 @@ a, a:active, a:focus {
|
|||
height: 500px;
|
||||
}
|
||||
|
||||
.thumbnail {
|
||||
height: 350px;
|
||||
}
|
||||
|
||||
/* Footer */
|
||||
footer {
|
||||
position: fixed;
|
||||
|
@ -263,3 +259,11 @@ footer {
|
|||
-webkit-box-shadow: inset 0 3px 5px rgba(0,0,0,.125);
|
||||
box-shadow: inset 0 3px 5px rgba(0,0,0,.125);
|
||||
}
|
||||
|
||||
.sponsor {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.sponsor .caption {
|
||||
text-align: center;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue