initial sponsorship app adapted from DjangoCon
This commit is contained in:
parent
0f6843b08d
commit
46e38bc758
5 changed files with 82 additions and 0 deletions
0
symposion_project/apps/sponsorship/__init__.py
Normal file
0
symposion_project/apps/sponsorship/__init__.py
Normal file
7
symposion_project/apps/sponsorship/admin.py
Normal file
7
symposion_project/apps/sponsorship/admin.py
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
from symposion.sponsors.models import SponsorLevel, Sponsor
|
||||||
|
|
||||||
|
|
||||||
|
admin.site.register(SponsorLevel)
|
||||||
|
admin.site.register(Sponsor)
|
32
symposion_project/apps/sponsorship/models.py
Normal file
32
symposion_project/apps/sponsorship/models.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
|
class SponsorLevel(models.Model):
|
||||||
|
|
||||||
|
name = models.CharField(max_length=100)
|
||||||
|
order = models.IntegerField(default=0)
|
||||||
|
description = models.TextField(blank=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
ordering = ["order"]
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
|
class Sponsor(models.Model):
|
||||||
|
|
||||||
|
name = models.CharField(max_length=100)
|
||||||
|
external_url = models.URLField("external URL")
|
||||||
|
annotation = models.TextField(blank=True)
|
||||||
|
contact_name = models.CharField(max_length=100)
|
||||||
|
contact_email = models.EmailField(u"Contact e\u2011mail")
|
||||||
|
logo = models.ImageField(upload_to="sponsor_logos/")
|
||||||
|
level = models.ForeignKey(SponsorLevel)
|
||||||
|
added = models.DateTimeField(default=datetime.datetime.now)
|
||||||
|
active = models.BooleanField(default=False)
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return self.name
|
|
@ -0,0 +1,43 @@
|
||||||
|
from django import template
|
||||||
|
|
||||||
|
from sponsorship.models import Sponsor
|
||||||
|
|
||||||
|
|
||||||
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
|
class SponsorsNode(template.Node):
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def handle_token(cls, parser, token):
|
||||||
|
bits = token.split_contents()
|
||||||
|
if len(bits) != 4:
|
||||||
|
raise template.TemplateSyntaxError("%r takes exactly three arguments "
|
||||||
|
"(second argument must be 'as')" % bits[0])
|
||||||
|
if bits[2] != "as":
|
||||||
|
raise template.TemplateSyntaxError("Second argument to %r must be "
|
||||||
|
"'as'" % bits[0])
|
||||||
|
return cls(bits[1], bits[3])
|
||||||
|
|
||||||
|
def __init__(self, level, context_var):
|
||||||
|
self.level = template.Variable(level)
|
||||||
|
self.context_var = context_var
|
||||||
|
|
||||||
|
def render(self, context):
|
||||||
|
level = self.level.resolve(context)
|
||||||
|
queryset = Sponsor.objects.filter(
|
||||||
|
level__name__iexact = level,
|
||||||
|
active = True
|
||||||
|
).order_by(
|
||||||
|
"added"
|
||||||
|
)
|
||||||
|
context[self.context_var] = queryset
|
||||||
|
return u""
|
||||||
|
|
||||||
|
|
||||||
|
@register.tag
|
||||||
|
def sponsors(parser, token):
|
||||||
|
"""
|
||||||
|
{% sponsors "gold" as sponsors %}
|
||||||
|
"""
|
||||||
|
return SponsorsNode.handle_token(parser, token)
|
Loading…
Reference in a new issue