allow staff to add sponsors directly via interface
This commit is contained in:
		
							parent
							
								
									1f98a6a754
								
							
						
					
					
						commit
						0f32fdcb74
					
				
					 4 changed files with 61 additions and 15 deletions
				
			
		|  | @ -5,5 +5,6 @@ from django.views.generic.simple import direct_to_template | ||||||
| urlpatterns = patterns("symposion.sponsorship.views", | urlpatterns = patterns("symposion.sponsorship.views", | ||||||
|     url(r"^$", direct_to_template, {"template": "sponsorship/list.html"}, name="sponsor_list"), |     url(r"^$", direct_to_template, {"template": "sponsorship/list.html"}, name="sponsor_list"), | ||||||
|     url(r"^apply/$", "sponsor_apply", name="sponsor_apply"), |     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"), |     url(r"^(?P<pk>\d+)/$", "sponsor_detail", name="sponsor_detail"), | ||||||
| ) | ) | ||||||
|  |  | ||||||
|  | @ -1,3 +1,4 @@ | ||||||
|  | from django.http import Http404 | ||||||
| from django.shortcuts import render_to_response, redirect, get_object_or_404 | from django.shortcuts import render_to_response, redirect, get_object_or_404 | ||||||
| from django.template import RequestContext | from django.template import RequestContext | ||||||
| 
 | 
 | ||||||
|  | @ -23,6 +24,26 @@ def sponsor_apply(request): | ||||||
|     }, context_instance=RequestContext(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 | @login_required | ||||||
| def sponsor_detail(request, pk): | def sponsor_detail(request, pk): | ||||||
|     sponsor = get_object_or_404(Sponsor, pk=pk) |     sponsor = get_object_or_404(Sponsor, pk=pk) | ||||||
|  | @ -44,9 +65,9 @@ def sponsor_detail(request, pk): | ||||||
|             form.save() |             form.save() | ||||||
|             formset.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: |     else: | ||||||
|         form = SponsorDetailsForm(instance=sponsor) |         form = SponsorDetailsForm(instance=sponsor) | ||||||
|         formset = SponsorBenefitsFormSet(**formset_kwargs) |         formset = SponsorBenefitsFormSet(**formset_kwargs) | ||||||
|  |  | ||||||
							
								
								
									
										22
									
								
								symposion/templates/sponsorship/add.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								symposion/templates/sponsorship/add.html
									
										
									
									
									
										Normal 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 %} | ||||||
|  | @ -20,20 +20,22 @@ | ||||||
|                     <h3>{{ level.name }}</h3> |                     <h3>{{ level.name }}</h3> | ||||||
| 
 | 
 | ||||||
|                     {% for sponsor in level.sponsors %} |                     {% for sponsor in level.sponsors %} | ||||||
|                         <div class="row"> |                         {% if sponsor.website_logo %} | ||||||
|                             <div class="span2"> |                             <div class="row"> | ||||||
|                                 <h2> |                                 <div class="span2"> | ||||||
|                                     <a href="{{ sponsor.external_url }}"> |                                     <h2> | ||||||
|                                         <img src="{% thumbnail sponsor.website_logo '150x80' %}" alt="{{ sponsor.name }}" /> |                                         <a href="{{ sponsor.external_url }}"> | ||||||
|                                     </a> |                                             <img src="{% thumbnail sponsor.website_logo '150x80' %}" alt="{{ sponsor.name }}" /> | ||||||
|                                 </h2> |                                         </a> | ||||||
|  |                                     </h2> | ||||||
|  |                                 </div> | ||||||
|  |                                 <div class="span10"> | ||||||
|  |                                     <h5>{{ sponsor.name }}</h5> | ||||||
|  |                                     <p><a href="{{ sponsor.external_url }}">{{ sponsor.external_url }}</a></p> | ||||||
|  |                                     <p>{{ sponsor.listing_text|urlize|linebreaks }}</p> | ||||||
|  |                                 </div> | ||||||
|                             </div> |                             </div> | ||||||
|                             <div class="span10"> |                         {% endif %} | ||||||
|                                 <h5>{{ sponsor.name }}</h5> |  | ||||||
|                                 <p><a href="{{ sponsor.external_url }}">{{ sponsor.external_url }}</a></p> |  | ||||||
|                                 <p>{{ sponsor.listing_text|urlize|linebreaks }}</p> |  | ||||||
|                             </div> |  | ||||||
|                         </div> |  | ||||||
|                     {% endfor %} |                     {% endfor %} | ||||||
|                 {% endif %} |                 {% endif %} | ||||||
|             {% endfor %} |             {% endfor %} | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 James Tauber
						James Tauber