From f91c04df5bc3b9032cf0ced8dcfe82c30b9d86e6 Mon Sep 17 00:00:00 2001 From: Thierry Carrez Date: Thu, 3 Jan 2013 17:45:55 +0100 Subject: [PATCH] Make event name configurable Event name is now configurable in settings.py. Uses the render() shortcut (RequestContext) and a new context processor to pass event to all templates. --- cfp/context_processors.py | 20 ++++++++++++ cfp/templates/base.html | 10 +++--- cfp/templates/cfpdelete.html | 2 +- cfp/templates/cfpdetails.html | 2 +- cfp/templates/cfpedit.html | 4 +-- cfp/templates/cfplist.html | 2 +- cfp/templates/cfpswitch.html | 2 +- cfp/views.py | 57 +++++++++++++---------------------- local_settings.py.sample | 4 ++- scheduling/views.py | 43 +++++++++++--------------- settings.py | 4 +++ 11 files changed, 77 insertions(+), 73 deletions(-) create mode 100644 cfp/context_processors.py diff --git a/cfp/context_processors.py b/cfp/context_processors.py new file mode 100644 index 0000000..cefe44d --- /dev/null +++ b/cfp/context_processors.py @@ -0,0 +1,20 @@ +# Copyright 2012 Thierry Carrez +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +from django.conf import settings + + +def event(request): + return {'event': {'title': settings.EVENT_TITLE, + 'subtitle': settings.EVENT_SUBTITLE}} diff --git a/cfp/templates/base.html b/cfp/templates/base.html index bec7229..fe76098 100644 --- a/cfp/templates/base.html +++ b/cfp/templates/base.html @@ -17,8 +17,8 @@ function overlay() { -

Sessions for the Grizzly Design Summit

-

OpenStack Conference, San Diego, Oct 15-18, 2012

+

{{ event.title }}

+

{{ event.subtitle }}

@@ -41,10 +41,10 @@ function overlay() {
Need Help?
{% block extrafooter %}{% endblock %} - {% if req.user.is_authenticated %} -You are logged in as {{ req.user.username }}. Logout + {% if user.is_authenticated %} +You are logged in as {{ user.username }}. Logout {% else %} -You are not logged in. Log in +You are not logged in. Log in {% endif %} diff --git a/cfp/templates/cfpdelete.html b/cfp/templates/cfpdelete.html index 648219d..478f123 100644 --- a/cfp/templates/cfpdelete.html +++ b/cfp/templates/cfpdelete.html @@ -8,5 +8,5 @@ {% endblock %} {% block formfooter %} -Cancel +Cancel {% endblock %} diff --git a/cfp/templates/cfpdetails.html b/cfp/templates/cfpdetails.html index 49b5fab..7a894dc 100644 --- a/cfp/templates/cfpdetails.html +++ b/cfp/templates/cfpdetails.html @@ -19,5 +19,5 @@ in topic {{ proposal.topic }}

{% endif %}

Status

This proposal is in {{ proposal.get_status_display }} state.

-Back +Back {% endblock %} diff --git a/cfp/templates/cfpedit.html b/cfp/templates/cfpedit.html index d6efbd8..7989e01 100644 --- a/cfp/templates/cfpedit.html +++ b/cfp/templates/cfpedit.html @@ -13,8 +13,8 @@ {% endblock %} {% block formfooter %} -{% if proposal.proposer == req.user and proposal.status != 'A' and proposal.status != 'S' %} +{% if proposal.proposer == user and proposal.status != 'A' and proposal.status != 'S' %} Delete {% endif %} -Cancel +Cancel {% endblock %} diff --git a/cfp/templates/cfplist.html b/cfp/templates/cfplist.html index 76fd30d..e3cdb1c 100644 --- a/cfp/templates/cfplist.html +++ b/cfp/templates/cfplist.html @@ -31,7 +31,7 @@ {{ proposal.topic.name }} -{% if proposal.proposer == req.user and proposal.status != 'A' %} +{% if proposal.proposer == user and proposal.status != 'A' %} {% else %} diff --git a/cfp/templates/cfpswitch.html b/cfp/templates/cfpswitch.html index deccf9d..d2e7cb5 100644 --- a/cfp/templates/cfpswitch.html +++ b/cfp/templates/cfpswitch.html @@ -9,5 +9,5 @@ {% endblock %} {% block formfooter %} -Cancel +Cancel {% endblock %} diff --git a/cfp/views.py b/cfp/views.py index 6c7e287..f294450 100644 --- a/cfp/views.py +++ b/cfp/views.py @@ -15,7 +15,7 @@ from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User -from django.shortcuts import render_to_response +from django.shortcuts import render from django.conf import settings from django.contrib.auth import logout from django.core.mail import EmailMessage @@ -49,10 +49,9 @@ def list(request): reviewable_topics = Topic.objects.filter( lead_username=request.user.username) request.session['lastlist'] = "" - return render_to_response("cfplist.html", - {'req': request, - 'proposals': proposals, - 'reviewable_topics': reviewable_topics}) + return render(request, "cfplist.html", + {'proposals': proposals, + 'reviewable_topics': reviewable_topics}) @login_required @@ -62,27 +61,23 @@ def topiclist(request, topicid): return forbidden() proposals = Proposal.objects.filter(topic=topicid) request.session['lastlist'] = "cfp/topic/%s" % topicid - return render_to_response("topiclist.html", - {'req': request, - 'proposals': proposals, - 'topic': topic}) + return render(request, "topiclist.html", + {'proposals': proposals, + 'topic': topic}) @login_required def topicstatus(request): topics = Topic.objects.all() - return render_to_response("topicstatus.html", - {'req': request, - 'topics': topics}) + return render(request, "topicstatus.html", {'topics': topics}) @login_required def details(request, proposalid): proposal = Proposal.objects.get(id=proposalid) - return render_to_response("cfpdetails.html", - {'req': request, - 'proposal': proposal, - 'blueprints': linkify(proposal.blueprints)}) + return render(request, "cfpdetails.html", + {'proposal': proposal, + 'blueprints': linkify(proposal.blueprints)}) @login_required @@ -99,10 +94,7 @@ def create(request): form = ProposalForm() topics = Topic.objects.all() - return render_to_response('cfpcreate.html', - {'req': request, - 'topics': topics, - 'form': form}) + return render(request, 'cfpcreate.html', {'topics': topics, 'form': form}) @login_required @@ -118,10 +110,8 @@ def edit(request, proposalid): return HttpResponseRedirect('/%s' % request.session['lastlist']) else: form = ProposalEditForm(instance=proposal) - return render_to_response('cfpedit.html', - {'req': request, - 'form': form, - 'proposal': proposal}) + return render(request, 'cfpedit.html', {'form': form, + 'proposal': proposal}) @login_required @@ -132,9 +122,7 @@ def delete(request, proposalid): if request.method == 'POST': proposal.delete() return HttpResponseRedirect('/%s' % request.session['lastlist']) - return render_to_response('cfpdelete.html', - {'req': request, - 'proposal': proposal}) + return render(request, 'cfpdelete.html', {'proposal': proposal}) @login_required @@ -153,10 +141,8 @@ def switch(request, proposalid): return HttpResponseRedirect('/%s' % request.session['lastlist']) else: form = ProposalSwitchForm(instance=proposal) - return render_to_response('cfpswitch.html', - {'req': request, - 'form': form, - 'proposal': proposal}) + return render(request, 'cfpswitch.html', {'form': form, + 'proposal': proposal}) @login_required @@ -199,11 +185,10 @@ You can edit your proposal at: %s/cfp/edit/%s""" \ return HttpResponseRedirect('/cfp/topic/%d' % proposal.topic.id) else: form = ProposalReviewForm(instance=proposal) - return render_to_response('cfpreview.html', - {'req': request, - 'form': form, - 'proposal': proposal, - 'blueprints': linkify(proposal.blueprints)}) + return render(request, 'cfpreview.html', + {'form': form, + 'proposal': proposal, + 'blueprints': linkify(proposal.blueprints)}) def dologout(request): diff --git a/local_settings.py.sample b/local_settings.py.sample index 0f4465f..fdfbe7c 100644 --- a/local_settings.py.sample +++ b/local_settings.py.sample @@ -32,7 +32,9 @@ DEBUG = False TEMPLATE_DEBUG = DEBUG #OPENID_USE_AS_ADMIN_LOGIN = True -# Change to match your Sched event +# Change to match your event +EVENT_TITLE = "Grizzly Design Summit" +EVENT_SUBTITLE = "OpenStack Summit, San Diego, Oct 15-18, 2012" SCHED_URL = "essexdesignsummit" SCHED_API_KEY = "getThisFromSched" diff --git a/scheduling/views.py b/scheduling/views.py index 5d47609..b1552b1 100644 --- a/scheduling/views.py +++ b/scheduling/views.py @@ -16,7 +16,7 @@ import urllib import urllib2 -from django.shortcuts import render_to_response +from django.shortcuts import render from django.conf import settings from django.http import HttpResponseRedirect from django.utils.encoding import smart_str @@ -91,11 +91,10 @@ def scheduling(request, topicid): accepted = Proposal.objects.filter(status='A', scheduled=False, topic=topic) schedule = Slot.objects.filter(topic=topic) - return render_to_response("scheduling.html", - {'req': request, - 'accepted': accepted, - 'schedule': schedule, - 'topic': topic}) + return render(request, "scheduling.html", + {'accepted': accepted, + 'schedule': schedule, + 'topic': topic}) def end_time(start_time): @@ -140,10 +139,9 @@ def publish(request, topicid): f.close() f = urllib2.urlopen(baseurl + "add", data) f.close() - return render_to_response("sched.html", - {'req': request, - 'list_calls': list_calls, - 'topic': topic}) + return render(request, "sched.html", + {'list_calls': list_calls, + 'topic': topic}) def edit(request, slotid): @@ -157,12 +155,11 @@ def edit(request, slotid): return HttpResponseRedirect('/scheduling/%s' % slot.topic.id) else: form = SlotForm(instance=slot) - return render_to_response('slotedit.html', - {'req': request, - 'form': form, - 'title': combined_title(slot), - 'full_desc': combined_description(slot), - 'slot': slot}) + return render(request, 'slotedit.html', + {'form': form, + 'title': combined_title(slot), + 'full_desc': combined_description(slot), + 'slot': slot}) def swap(request, slotid): @@ -188,11 +185,10 @@ def swap(request, slotid): for slot in available_slots: triplet = (slot.start_time, slot.id, combined_title(slot)) newslots.append(triplet) - return render_to_response('slotswap.html', - {'req': request, - 'title': combined_title(oldslot), - 'oldslot': oldslot, - 'newslots': newslots}) + return render(request, 'slotswap.html', + {'title': combined_title(oldslot), + 'oldslot': oldslot, + 'newslots': newslots}) def graph(request, topicid): @@ -215,7 +211,4 @@ def graph(request, topicid): nbproposed += 1 stats['max'] = max(stats['avail'], nbproposed + nbscheduled) - return render_to_response("graph.html", - {'req': request, - 'stats': stats, - 'topic': topic}) + return render(request, "graph.html", {'stats': stats, 'topic': topic}) diff --git a/settings.py b/settings.py index 546f3bd..14f47a0 100644 --- a/settings.py +++ b/settings.py @@ -34,6 +34,9 @@ DATABASES = { } } +EVENT_TITLE = "Grizzly Design Summit" +EVENT_SUBTITLE = "OpenStack Summit, San Diego, Oct 15-18, 2012" + SCHED_URL = "essexdesignsummit" SCHED_API_KEY = "getThisFromSched" @@ -56,6 +59,7 @@ TEMPLATE_CONTEXT_PROCESSORS = ( "django.core.context_processors.i18n", "django.core.context_processors.media", "django.core.context_processors.request", + "cfp.context_processors.event", ) MIDDLEWARE_CLASSES = (