Module:SOM.Page.School

From SunshinePPS Wiki

This module defines the class School which defines pages in the category Category:School.

A School is a XXXXXXXYYYY.


page_category(frame)
Generates the definition for this class' category, Category:School. Typically, invoked by SOM.util.auto_generate_page_category
page_form(frame)
Generates the definition for this class' form, Form:School. Typically, invoked by SOM.util.auto_generate_page_form
page_template(frame)
Generates the definition for the template which instantiates this class, Template:SOM.Page.School. Typically, invoked by SOM.util.auto_generate_page_template

(/doc page)


require("Module:No globals")

local DBA = require("Module:SOM.meta.DateBoundedAttribute")
local Page = require("Module:SOM.meta.Page")
local StringBuffer = require("Module:SOM.util.StringBuffer")
local util = require("Module:SOM.util")

local BelongsToSchoolDistrict = require("Module:SOM.Simple.BelongsToSchoolDistrict")
local FreeWikitext = require("Module:SOM.Simple.FreeWikitext")
local HasMotto = require("Module:SOM.DateBounded.HasMotto")
local HasName = require("Module:SOM.DateBounded.HasName")
local HasWebsite = require("Module:SOM.DateBounded.HasWebsite")
local SchoolAssistantPrincipal = require("Module:SOM.DateBounded.Role.OrgPerson.SchoolAssistantPrincipal")
local SchoolPrincipal = require("Module:SOM.DateBounded.Role.OrgPerson.SchoolPrincipal")
local SchoolCampus = require("Module:SOM.DateBounded.Role.OrgPlace.SchoolCampus")
local StreetAddress = require("Module:SOM.DateBounded.StreetAddress")
local SystemSpecificIdentifier = require("Module:SOM.DateBounded.SystemSpecificIdentifier")

local ENTITY_ROOT_CATEGORY = require("Module:SOM.const.ENTITY_ROOT_CATEGORY")


local function render_campus_with_address(instance, frame)
	local buffer = StringBuffer.new()
	if not instance.place then
		buffer:add(util.MISSING_VALUE)
	else
		local names = HasName.ask(
			instance.place, nil, "[[SOM/Is current::true]]")
		if (#names > 0) and (util.empty_to_nil(names[1].name)) then
			-- TODO(maddog) What if there is more than one current name?
			buffer:add(util.show_as_piped_link(instance.place, names[1].name))
		else
			buffer:add(
				util.show_as_piped_link(instance.place, util.style_as_missing("missing name")))
		end
		local addresses = StreetAddress.ask(
			instance.place, nil, "[[SOM/Is current::true]]")
		if #addresses > 0 then
			buffer:add("<br>")
			-- TODO(maddog) What if there is more than one current address?
			buffer:add(StreetAddress.render_address(addresses[1]))
		end
	end
	return buffer:output()
end


return Page.generate_page{
	class_name = "School",
	parent_categories = { ENTITY_ROOT_CATEGORY },
	category_description = [==[
A ''School'' is a XXXXXXXYYYY.
]==],
	naming_advice = [[
New pages should be named using the most current, full name of the school (e.g., "Clara Sweet Elementary School").]],
	attributes = {
		district = {
			arg = "district",
			class = BelongsToSchoolDistrict,
			label = "District",
		},
		names = {
			arg = "names",
			class = HasName,
			label = "Name"
		},
		websites = {
			arg = "websites",
			class = HasWebsite,
			label = "Website"
		},
		mottos = {
			arg = "mottos",
			class = HasMotto,
			label = "Motto"
		},
		principals = {
			arg = "principals",
			class = SchoolPrincipal,
			label = "Principal",
			link_to_key = "school"
		},
		assistant_principals = {
			arg = "assistant_principals",
			class = SchoolAssistantPrincipal,
			label = "Assistant Principal",
			link_to_key = "school"
		},
		campuses = {
			arg = "campuses",
			class = SchoolCampus,
			label = "Campus",
			link_to_key = "school"
		},
		system_identifiers = {
			arg = "system_identifiers",
			class = SystemSpecificIdentifier,
			label = "Identifier",
		},
		text = {
			arg = "text",
			class = FreeWikitext,
			label = "Article Text"
		},
	},
	form_layout = {
		{ section2 = "Basic Facts" },
		{ table = {
			{ attribute = "district" },
			}
		},
		{ section4 = "Names" },
		{ attribute = "names" },
		{ section4 = "Websites" },
		{ attribute = "websites" },
		{ section4 = "Mottos" },
		{ attribute = "mottos" },
		{ section2 = "Administration" },
		{ section4 = "Principals" },
		{ attribute = "principals" },
		{ section4 = "Assistant Principals" },
		{ attribute = "assistant_principals" },
		{ section4 = "Campuses" },
		{ attribute = "campuses" },
		{ section4 = "Identifiers" },
		{ attribute = "system_identifiers" },
		{ section2 = "Article Text" },
		{ attribute = "text" },
	},
	page_layout = {
		{ infobox = {
			{ attribute = "names", render = "render_current" },
			{ attribute = "websites", render = "render_current" },
			{ attribute = "campuses", render = "render_current",
				render_args = { render_with = render_campus_with_address }},
			{ attribute = "district" },
			{ attribute = "mottos", render = "render_current" },
			{ section = "Administration" },
			{ attribute = "principals", render = "render_current",
				render_args = { key = "person"} },
			{ attribute = "assistant_principals", render = "render_current",
				render_args = { key = "person"} },
			{ section = "Technical" },
			{ attribute = "system_identifiers", 
				label = "Identifiers",
				render = "render_current",
				render_args = { render_with = SystemSpecificIdentifier.render_pair } },
			}
		},
		{ attribute = "text" },
		{ references = {} },
		{ section2 = "Fact History" },
--		{ section5 = "Names" },
		{ attribute = "names", render = "render_table_and_references",
			render_args = HasName.basic_current_first_table_args() },
--		{ section5 = "Websites" },
		{ attribute = "websites", render = "render_table_and_references",
			render_args = HasWebsite.basic_current_first_table_args() },
--		{ section5 = "Mottos" },
		{ attribute = "mottos", render = "render_table_and_references",
			render_args = HasMotto.basic_current_first_table_args() },
--		{ section5 = "Principals" },
		{ attribute = "principals", render = "render_table_and_references",
			render_args = {
				sort = DBA.sort_current_first,
				columns = {
					{ label = "Principal", key = "person" },
					{ label = "Role", key = "role" },
					{ label = "Attributes", -- key = "role_attributes",
						render = function (instance)
							return table.concat(
								instance.role_attributes, ", ")
						end,
					 },
					-- { label = "School", key = "school" },
					DBA.COLUMN_FROM,
					DBA.COLUMN_UNTIL,
					DBA.COLUMN_REFERENCES,
				}
			}
		},
--		{ section5 = "Assistant Principals" },
		{ attribute = "assistant_principals", render = "render_table_and_references",
			render_args = {
				sort = DBA.sort_current_first,
				columns = {
					{ label = "Assistant Principal", key = "person" },
					{ label = "Role", key = "role" },
					{ label = "Attributes", -- key = "role_attributes",
						render = function (instance)
							return table.concat(
								instance.role_attributes, ", ")
						end,
					 },
					-- { label = "School", key = "school" },
					DBA.COLUMN_FROM,
					DBA.COLUMN_UNTIL,
					DBA.COLUMN_REFERENCES,
				}
			}
		},
		{ attribute = "campuses", render = "render_table_and_references",
			render_args = {
				sort = DBA.sort_current_first,
				columns = {
					{ label = "Campus", key = "place" },
--					{ label = "Role", key = "role" },
--					{ label = "Attributes", -- key = "role_attributes",
--						render = function (instance)
--							return table.concat(
--								instance.role_attributes, ", ")
--						end,
--					 },
					-- { label = "School", key = "school" },
					DBA.COLUMN_FROM,
					DBA.COLUMN_UNTIL,
					DBA.COLUMN_REFERENCES,
				}
			}
		},
		{ attribute = "system_identifiers", render = "render_table_and_references",
			render_args = {
				sort = DBA.sort_current_first,
				columns = {
					{ label = "System", key = "system" },
					{ label = "Identifier", key = "identifier" },
--					{ label = "Attributes", -- key = "role_attributes",
--						render = function (instance)
--							return table.concat(
--								instance.role_attributes, ", ")
--						end,
--					 },
					-- { label = "School", key = "school" },
					DBA.COLUMN_FROM,
					DBA.COLUMN_UNTIL,
					DBA.COLUMN_REFERENCES,
				}
			}
		},
	}
}