This repository has been archived by the owner on Mar 5, 2021. It is now read-only.
/
views.py
executable file
·369 lines (331 loc) · 13.4 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
from django.utils.translation import ugettext_lazy as _
import django.http as http
from django.template import RequestContext
from django.shortcuts import render_to_response, get_object_or_404
from models import Person, Building, Membership, Entity
from links.link_functions import object_links
from django.conf import settings
applications = getattr(settings, 'INSTALLED_APPS')
if 'publications' in applications:
from publications.models import BibliographicRecord
from publications.models import Researcher # required for publications
def contacts_and_people(request, slug=getattr(Entity.objects.base_entity(), "slug", None)):
# general values needed to set up and construct the page and menus
entity = Entity.objects.get(slug=slug)
# for the menu, because next we mess up the path
request.auto_page_url = request.path
# request.path = entity.get_website.get_absolute_url() # for the menu, so it knows where we are
request.current_page = entity.get_website
template = entity.get_template()
main_page_body_file = "contacts_and_people/entity_contacts_and_people.html"
# meta values - title and meta
title = "Contact information for %s" % entity
meta = {
"description": "Addresses, phone numbers, staff lists and other contact information",
}
people, initials = entity.get_people_and_initials()
# are there Key People to show?
if entity.get_key_people(): # if so we will show a list of people with key roles, then a list of other people
people_list_heading = _(u"Also")
# now remove the Key People from the people list
people = [ person for person in people if person not in set([role.person for role in entity.get_key_people()])]
else: # otherwise, just a list of the people with roles
people_list_heading = _(u"People")
people = entity.get_roles_for_members(people) # convert the list of Persons into a list of Members
return render_to_response(
"contacts_and_people/arkestra_page.html", # this is a catch-all template, that then uses includes to bring in extra information
{
"entity":entity,
"pagetitle": u"Contacts & people",
"entity.website.template": template,
"main_page_body_file": main_page_body_file,
"email": entity.email,
"title": title,
"meta": meta,
"location": entity.precise_location,
"intro_page_placeholder": entity.contacts_page_intro,
"phone": entity.phone_contacts.all(),
"full_address" : entity.get_full_address,
"building" : entity.get_building,
"people": people,
"people_list_heading": people_list_heading,
"initials_list": initials,
},
RequestContext(request),
)
def people(request, slug=getattr(Entity.objects.base_entity(), "slug", None), letter=None):
"""
Responsible for lists of people
"""
# general values needed to set up and construct the page and menus
entity = Entity.objects.get(slug=slug)
# for the menu, because next we mess up the path
request.auto_page_url = entity.get_related_info_page_url("contact")
# request.path = entity.get_website.get_absolute_url() # for the menu, so it knows where we are
request.current_page = entity.get_website
template = entity.get_template()
main_page_body_file = "includes/people_list_with_index.html"
# meta values - title and meta
meta = {
u"description": "People in %s" % entity,
}
title = u"%s: people" % entity
# content values
people, initials = entity.get_people_and_initials()
if letter:
people = entity.get_people(letter)
title = u"%s, people by surname: %s" % (entity, letter.upper())
return render_to_response(
"contacts_and_people/arkestra_page.html",
{
"entity":entity,
"pagetitle": entity,
"entity.website.template": template,
"main_page_body_file": main_page_body_file,
"title": title,
"meta": meta,
"people": people,
"initials_list": initials,
"letter": letter,
},
RequestContext(request),
)
def publications(request, slug):
entity = Entity.objects.get(slug=slug)
request.current_page = entity.website
return render_to_response(
"contacts_and_people/publications.html",
{"entity":entity,},
RequestContext(request),
)
def person(request, slug, active_tab=""):
"""
Responsible for the person pages
"""
person = get_object_or_404(Person,slug=slug)
person.links = object_links(person)
# we have a home_role, but we should also provide a role, even where it's good enough to give us an address
home_role = person.get_role
if home_role:
entity = home_role.entity
entity = person.get_entity # don't rely on home_role.entity - could be None or overridden
building = person.get_building
contact = person.get_please_contact()
email = contact.email
phone = contact.phone_contacts.all()
if person.please_contact:
precise_location = None
else:
precise_location = person.precise_location
access_note = person.access_note
if home_role:
description = ", ".join((home_role.__unicode__(), entity.__unicode__()))
request.current_page = entity.get_website
else:
description = Entity.objects.base_entity().__unicode__()
request.current_page = Entity.objects.base_entity().get_website
meta = {
"description": ": ".join((person.__unicode__(), description))
}
if entity:
template = entity.get_template()
else: # no memberships, no useful information
# print "no memberships, no useful information"
template = Entity.objects.base_entity().get_template()
tabs_dict = { # information for each kind of person tab
"default": {
"tab": "contact",
"title": "Contact information",
"address": "",
"meta_description_content": person,
},
"research": {
"tab": "research",
"title": "Research",
"address": "research",
"meta_description_content": unicode(person) + "- research interests",
},
"publications": {
"tab": "publications",
"title": "Publications",
"address": "publications",
"meta_description_content": unicode(person) + "- publications",
},
}
# mark the active tab, if there is one
if active_tab:
tabs_dict[active_tab]["active"] = True
# add tabs to the list of tabs
tabs = []
tabs.append(tabs_dict["default"])
if 'publications' in applications:
try:
if person.researcher and person.researcher.publishes:
tabs.append(tabs_dict["research"])
tabs.append(tabs_dict["publications"])
except Researcher.DoesNotExist:
pass
# were there any tabs created?
if tabs:
if not active_tab:
# find out what to add to the url for this tab
# print tabs[0]
active_tab=tabs[0]["address"]
# mark the tab as active for the template
tabs[0]["active"]=True
# fewer than 2? not worth having tabs!
if len(tabs)==1:
tabs=[]
meta_description_content = tabs_dict[active_tab or "default"]["meta_description_content"]
if active_tab:
active_tab = "_" + active_tab
meta = {
"description": meta_description_content,
}
# there's a problem here - pages such as Cardiff's /person/dr-kathrine-jane-craig/ don't
# get the menu right - why?
# print "****", request.auto_page_url, request.path, request.current_page, entity.get_website
return render_to_response(
"contacts_and_people/person%s.html" % active_tab,
{
"person":person, # personal information
"home_role": home_role, # entity and position
"entity": entity,
"template": template, # from entity
"building": building,
"email": email, # from person or please_contact
"precise_location": precise_location, # from person, or None
"contact": contact, # from person or please_contact
"phone": phone,
"full_address" : person.get_full_address,
"access_note": access_note, # from person
"tabs": tabs,
"tab_object": person,
"active_tab": active_tab,
"meta": meta,
# "links": links,
},
RequestContext(request),
)
def place(request, slug, active_tab=""):
"""
Receives active_tab from the slug.
The template receives "_" + active_tab to identify the correct template (from includes).
"""
place = Building.objects.get(slug=slug)
tabs_dict = { # information for each kind of place page
"about": {
"tab": "about",
"title": "About",
"address": "",
"meta_description_content": place.summary,
},
"map": {
"tab": "map",
"title": "Map",
"address": "map",
"meta_description_content": "Map for " + place.get_name(),
},
"getting-here": {
"tab": "getting-here",
"title": "Getting here",
"address": "getting-here",
"meta_description_content": "How to get to " + place.get_name(),
},
"events": {
"tab": "events",
"title": "What's on here",
"address": "events",
"meta_description_content": "What's on at " + place.get_name(),
},
}
# mark the active tab, if there is one
if active_tab:
tabs_dict[active_tab]["active"] = True
# add tabs to the list of tabs
tabs = []
if place.postcode or place.street or place.description.cmsplugin_set.all():
tabs.append(tabs_dict["about"])
if place.has_map:
tabs.append(tabs_dict["map"])
if (place.getting_here and place.getting_here.cmsplugin_set.all()) \
or (place.access_and_parking and place.access_and_parking.cmsplugin_set.all()):
tabs.append(tabs_dict["getting-here"])
if place.events().forthcoming_events:
tabs.append(tabs_dict["events"])
# were there any tabs created?
if tabs:
if not active_tab:
# find out what to add to the url for this tab
active_tab=tabs[0]["address"]
# mark the tab as active for the template
tabs[0]["active"]=True
# fewer than 2? not worth having tabs!
if len(tabs)==1:
tabs=[]
meta_description_content = tabs_dict[active_tab or "about"]["meta_description_content"]
if active_tab:
active_tab = "_" + active_tab
meta = {
"description": meta_description_content,
}
page = Entity.objects.base_entity().get_website
request.current_page = page
template = page.get_template()
# the three lines above were those below - which look quite wrong
# if default_entity:
# page = default_entity.get_website
# request.current_page = page
# template = page.get_template()
# else:
# page = entity.get_website
# request.current_page = page # for the menu, so it knows where we are
# template = page.get_template()
return render_to_response(
"contacts_and_people/place%s.html" % active_tab,
{
"place":place,
"tabs": tabs,
"tab_object": place,
"active_tab": active_tab,
"template": template,
"meta": meta,
},
RequestContext(request), )
def ajaxGetMembershipForPerson(request):
#Which person was/is selected
try:
person_id = int( request.GET.get("person_id") )
except ValueError:
person_id = 0
#If editing a current displayrole
try:
displayrole_id = int( request.GET.get("displayrole_id") )
except ValueError:
displayrole_id = 0
#If editing a current membership
try:
membership_id = int( request.GET.get("membership_id") )
except ValueError:
membership_id = 0
#Server response to AJAX
response = http.HttpResponse()
#BLANK option
response.write ('<option value="">---------</option>')
#If valid person selected make <option> list of all their existing memberships
if (person_id > 0 ):
membership_forperson_list = Membership.objects.filter(person__id = person_id).order_by('entity__name')
for membership in membership_forperson_list:
#dont include this membership if it is the one we are editing
if membership.id != membership_id:
#add a SELECTED clause if this is the display_role that was previously chosen
if membership.id == displayrole_id:
is_selected = " selected "
else:
is_selected = ""
#return an <option> entry for that membership
response.write('<option ' + is_selected + ' value="' + unicode(membership.id) + '">' + \
unicode(membership.entity) + ' - ' + unicode(membership.role) + \
'</option>')
#Done
return response