allow staff to add sponsors directly via interface

This commit is contained in:
James Tauber 2012-10-18 12:38:03 -04:00
parent 1f98a6a754
commit 0f32fdcb74
4 changed files with 61 additions and 15 deletions

View file

@ -5,5 +5,6 @@ from django.views.generic.simple import direct_to_template
urlpatterns = patterns("symposion.sponsorship.views",
url(r"^$", direct_to_template, {"template": "sponsorship/list.html"}, name="sponsor_list"),
url(r"^apply/$", "sponsor_apply", name="sponsor_apply"),
url(r"^add/$", "sponsor_add", name="sponsor_add"),
url(r"^(?P<pk>\d+)/$", "sponsor_detail", name="sponsor_detail"),
)

View file

@ -1,3 +1,4 @@
from django.http import Http404
from django.shortcuts import render_to_response, redirect, get_object_or_404
from django.template import RequestContext
@ -23,6 +24,26 @@ def sponsor_apply(request):
}, context_instance=RequestContext(request))
@login_required
def sponsor_add(request):
if not request.user.is_staff:
raise Http404()
if request.method == "POST":
form = SponsorApplicationForm(request.POST, user=request.user)
if form.is_valid():
sponsor = form.save(commit=False)
sponsor.active = True
sponsor.save()
return redirect("dashboard")
else:
form = SponsorApplicationForm(user=request.user)
return render_to_response("sponsorship/add.html", {
"form": form,
}, context_instance=RequestContext(request))
@login_required
def sponsor_detail(request, pk):
sponsor = get_object_or_404(Sponsor, pk=pk)
@ -44,9 +65,9 @@ def sponsor_detail(request, pk):
form.save()
formset.save()
messages.success(request, "Your sponsorship application has been submitted!")
messages.success(request, "Sponsorship details have been updated")
return redirect(request.path)
return redirect("dashboard")
else:
form = SponsorDetailsForm(instance=sponsor)
formset = SponsorBenefitsFormSet(**formset_kwargs)

View file

@ -0,0 +1,22 @@
{% extends "site_base.html" %}
{% load bootstrap_tags %}
{% load i18n %}
{% load boxes_tags %}
{% block head_title %}{% trans "Add a Sponsor" %}{% endblock %}
{% block body_class %}sponsors{% endblock %}
{% block body %}
<form method="POST" action="{% url sponsor_add %}" class="form-horizontal">
{% csrf_token %}
<legend>{% trans "Add a Sponsor" %}</legend>
{{ form|as_bootstrap }}
<div class="form-actions">
<input class="btn btn-primary" type="submit" value="Add" />
<a class="btn" href="{% url dashboard %}">Cancel</a>
</div>
</form>
{% endblock %}

View file

@ -20,6 +20,7 @@
<h3>{{ level.name }}</h3>
{% for sponsor in level.sponsors %}
{% if sponsor.website_logo %}
<div class="row">
<div class="span2">
<h2>
@ -34,6 +35,7 @@
<p>{{ sponsor.listing_text|urlize|linebreaks }}</p>
</div>
</div>
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}