Skip to content

Instantly share code, notes, and snippets.

@adam-davis
Created February 24, 2012 18:24
Show Gist options
  • Save adam-davis/1902723 to your computer and use it in GitHub Desktop.
Save adam-davis/1902723 to your computer and use it in GitHub Desktop.
Views and Templated Open Block
{
'schema_list': s_list,
'browsable_locationtype_list': browsable_locationtype_list,
'bodyclass': 'schema-list',
}
def homepage(request):
#......various other code in the homepage view
numberOfNewsItems = 8
recentNews = NewsItem.objects.all().order_by("pub_date").reverse()[0:numberOfNewsItems]
return eb_render(request, 'homepage.html', {
'location_type_list': lt_list,
'street_count': street_count,
'more_schemas': more_schemas,
'non_empty_date_charts': non_empty_date_charts,
'empty_date_charts': empty_date_charts,
'num_days': settings.DEFAULT_DAYS,
'default_lon': settings.DEFAULT_MAP_CENTER_LON,
'default_lat': settings.DEFAULT_MAP_CENTER_LAT,
'default_zoom': settings.DEFAULT_MAP_ZOOM,
'bodyclass': 'homepage',
'breadcrumbs': breadcrumbs.home({}),
'newsItems' : recentNews,
'map_configuration': _preconfigured_map({})
})
return eb_render(request, 'homepage.html', {
'location_type_list': lt_list,
'street_count': street_count,
'more_schemas': more_schemas,
'non_empty_date_charts': non_empty_date_charts,
'empty_date_charts': empty_date_charts,
'num_days': settings.DEFAULT_DAYS,
'default_lon': settings.DEFAULT_MAP_CENTER_LON,
'default_lat': settings.DEFAULT_MAP_CENTER_LAT,
'default_zoom': settings.DEFAULT_MAP_ZOOM,
'bodyclass': 'homepage',
'breadcrumbs': breadcrumbs.home({}),
'map_configuration': _preconfigured_map({})
})
return eb_render(request, 'db/schema_list.html', {
'schema_list': s_list,
'browsable_locationtype_list': browsable_locationtype_list,
'bodyclass': 'schema-list',
}
def schema_list(request):
schema_list = Schema.objects.select_related().filter(is_public=True,
is_special_report=False).order_by('plural_name')
schemafield_list = list(SchemaField.objects.filter(is_filter=True).order_by('display_order'))
browsable_locationtype_list = LocationType.objects.filter(is_significant=True)
# Populate s_list, which contains a schema and schemafield list for each schema.
s_list = []
for s in schema_list:
s_list.append({
'schema': s,
'schemafield_list': [sf for sf in schemafield_list if sf.schema_id == s.id],
})
return eb_render(request, 'db/schema_list.html', {
'schema_list': s_list,
'browsable_locationtype_list': browsable_locationtype_list,
'bodyclass': 'schema-list',
})
{% for schemabunch in schema_list %}
<h2><a href="{{ schemabunch.schema.url }}">{{ schemabunch.schema.plural_name|capfirst }}</a></h2>
<p>{{ schemabunch.schema.short_description }} <a href="{{ schemabunch.schema.url }}about/">More info&hellip;</a></p>
<h3>Browse:</h3>
<ul>
{% if schemabunch.schema.allow_charting %}{% for schemafield in schemabunch.schemafield_list %}
<li><a href="{{ schemabunch.schema.url }}by-{{ schemafield.name }}/">By {{ schemafield.browse_by_title }}</a></li>
{% endfor %}{% endif %}
{% for locationtype in browsable_locationtype_list %}
<li><a href="{{ schemabunch.schema.url }}locations/{{ locationtype.slug }}/">By {{ locationtype.name }}</a></li>
{% endfor %}
{% if schemabunch.schema.allow_charting %}<li><a href="{{ schemabunch.schema.url }}filter/">Custom filter</a></li>{% endif %}
</ul>
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment