Hi all,
I have been scouring the docs but with no joy, or perhaps just my own
stupidity. I am fairly new to Django / Python as a whole. I am
developing a site where I need to set or pass a global variable between
pages. Currently I am simply requesting it each time in my views.py
file...but I am sure there must be a simpler way of retrieving the same
information site wide and on each page where needed? Below is an
example extract from my views.py file...see what I mean? I seem to be
calling / using the "c = Context({" too many times. Is this the best
way of doing things? An example would be something like displaying the
First name and Last name of a user that is logged in accross all my
pages. Take a look below:
"...
c = Context({
'device_list': device_list,
'online_user' : request.user,
'online_group_name' : getOnlineGroupName(request),
})
return HttpResponse(t.render(c))
index = login_required(index)
#-------------------------------------------------------------------------------
def indexJobs(request, device_id):
"""
Shows a list of all the jobs for a given device
"""
job_list = jobs.get_list(device__id__exact=device_id)
t = loader.get_template('devicemanager/jobs')
c = Context({
'job_list': job_list,
'online_user' : request.user,
'online_group_name' : getOnlineGroupName(request),
})
return HttpResponse(t.render(c))
indexJobs = login_required(indexJobs)
#-------------------------------------------------------------------------------
[EMAIL PROTECTED]
def editDevice(request, device_id):
device = devices.get_object(id__exact=device_id)
t = loader.get_template('devicemanager/edit')
c = Context({
'online_user' : request.user,
'online_group_name' : getOnlineGroupName(request),
'device' : device,
})
return HttpResponse(t.render(c))
editDevice = login_required(editDevice)
#-------------------------------------------------------------------------------
[EMAIL PROTECTED]
def editDeviceSite(request, device_id):
t = loader.get_template('devicemanager/edit_site')
c = Context({
'online_user' : request.user,
'online_group_name' : getOnlineGroupName(request),
})
return HttpResponse(t.render(c))
editDeviceSite = login_required(editDeviceSite)
#-------------------------------------------------------------------------------
[EMAIL PROTECTED]
def editDeviceConfig(request, device_id):
t = loader.get_template('devicemanager/edit_config')
c = Context({
'online_user' : request.user,
'online_group_name' : getOnlineGroupName(request),
})
return HttpResponse(t.render(c))
editDeviceConfig = login_required(editDeviceConfig)
#-------------------------------------------------------------------------------
[EMAIL PROTECTED]
def editDeviceStats(request, device_id):
t = loader.get_template('devicemanager/edit_stats')
c = Context({
'online_user' : request.user,
'online_group_name' : getOnlineGroupName(request),
})
return HttpResponse(t.render(c))
editDeviceStats = login_required(editDeviceStats)
#-------------------------------------------------------------------------------
[EMAIL PROTECTED]
def editDevicePurse(request, device_id):
t = loader.get_template('devicemanager/edit_purse')
c = Context({
'online_user' : request.user,
'online_group_name' : getOnlineGroupName(request),
})
return HttpResponse(t.render(c))
editDevicePurse = login_required(editDevicePurse)
#-------------------------------------------------------------------------------
[EMAIL PROTECTED]
def editDeviceAlerts(request, device_id):
t = loader.get_template('devicemanager/edit_alerts')
device = devices.get_object(id__exact=device_id)
alert_list = device.get_alert_list()
c = Context({
'alert_list' : alert_list,
'online_user' : request.user,
'online_group_name' : getOnlineGroupName(request),
})
return HttpResponse(t.render(c))
editDeviceAlerts = login_required(editDeviceAlerts)
#-------------------------------------------------------------------------------
[EMAIL PROTECTED]
def editDeviceHistory(request, device_id):
t = loader.get_template('devicemanager/edit_history')
device = devices.get_object(id__exact=device_id)
event_list = device.get_event_list()
c = Context({
'event_list' : event_list,
'online_user' : request.user,
'online_group_name' : getOnlineGroupName(request),
})
return HttpResponse(t.render(c))
editDeviceHistory = login_required(editDeviceHistory)
#-------------------------------------------------------------------------------
..."
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---