Module:SOM.Page.School Board Resolution
From SunshinePPS Wiki
This module defines the class School Board Resolution
which defines
pages in the category Category:School Board Resolution.
A School Board Resolution is a XXXXXXXYYYY.
- page_category(
frame
) - Generates the definition for this class' category, Category:School Board Resolution. Typically, invoked by
SOM.util.auto_generate_page_category
- page_form(
frame
) - Generates the definition for this class' form, Form:School Board Resolution. 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 Board Resolution. Typically, invoked by
SOM.util.auto_generate_page_template
require("Module:No globals")
local Page = require("Module:SOM.meta.Page")
local StringBuffer = require("Module:SOM.util.StringBuffer")
local util = require("Module:SOM.util")
local RA = require("Module:SOM.meta.ReferencingAttribute")
local BelongsToSchoolDistrict = require("Module:SOM.Simple.BelongsToSchoolDistrict")
local HasBoardResolutionNumber = require("Module:SOM.Simple.HasBoardResolutionNumber")
local HasBoardResolutionVersion = require("Module:SOM.Simple.HasBoardResolutionVersion")
local HasBoardResolutionTopic = require("Module:SOM.Composite.HasBoardResolutionTopic")
local AffectsBoardPolicyNumber = require("Module:SOM.Composite.AffectsBoardPolicyNumber")
local HasRelatedPage = require("Module:SOM.Composite.HasRelatedPage")
local FreeWikitext = require("Module:SOM.Simple.FreeWikitext")
local BoardResolutionEvent = require("Module:SOM.Composite.BoardResolutionEvent")
local BoardResolutionWorkItem = require("Module:SOM.Composite.BoardResolutionWorkItem")
local function make_document_renderer(section)
return function (value, frame)
local filenames = StringBuffer.new()
local count = 0
for _, d in ipairs(value or {}) do
-- Skip entries that do not match section
if d.section == section then
if (d.file == nil) or (d.file == "") then
filenames:add_uformat(
"File:QuestionMark.svg|%s", util.MISSING_VALUE):nl()
else
filenames:add_uformat(
"%s|%s", d.file, d.description or ""):nl()
end
count = count + 1
end
end
if count == 0 then
return "''None''"
end
return frame:extensionTag{
name = "gallery",
content = filenames:output(),
args = { mode = "traditional", showfilename = "yo" }
}
end
end
local function get_latest_event(events)
local latest = nil
for i, v in ipairs(events) do
if latest == nil then
latest = v
elseif v.meeting_date >= latest.meeting_date then
latest = v
end
end
return latest
end
return Page.generate_page{
class_name = "School Board Resolution",
parent_categories = { "Legislative Action" },
category_description = [==[
A ''School Board Resolution'' is a XXXXXXXYYYY.
]==],
attributes = {
district = {
arg = "district",
class = BelongsToSchoolDistrict,
label = "District",
},
number = {
arg = "number",
class = HasBoardResolutionNumber,
label = "Number",
},
version = {
arg = "version",
class = HasBoardResolutionVersion,
label = "Version",
},
topics = {
arg = "topics",
class = HasBoardResolutionTopic,
label = "Topics",
},
affected_policies = {
arg = "affected_policies",
class = AffectsBoardPolicyNumber,
label = "Affected Policies",
},
events = {
arg = "events",
class = BoardResolutionEvent,
label = "Work Events",
},
work_items = {
arg = "work_items",
class = BoardResolutionWorkItem,
label = "Work Items",
},
related_pages = {
arg = "related_pages",
class = HasRelatedPage,
label = "Related Pages",
},
free_text = {
arg = "free_text",
class = FreeWikitext,
label = "Article Text"
},
},
form_layout = {
{ section2 = "Basic Facts" },
{ table = {
{ attribute = "district" },
{ attribute = "number" },
{ attribute = "version" },
}
},
{ attribute = "topics" },
{ attribute = "affected_policies" },
{ attribute = "events" },
{ attribute = "work_items" },
{ attribute = "related_pages" },
{ section2 = "Article Text" },
{ attribute = "free_text" },
},
page_layout = {
{ infobox = {
{ attribute = "district" },
{ render_any = function (values, frame)
if values.version and (tonumber(values.version) > 0) then
return "Number", mw.ustring.format("%s (version %d)", values.number, values.version)
end
return "Number", values.number
end },
{ render_any = function (data, frame)
local latest = get_latest_event(data.events)
local status = latest and latest.action
return "Status", util.show_nil_as_missing(status)
end },
{ render_any = function (data, frame)
local latest = get_latest_event(data.events)
local year = latest and latest.school_year
return "School Year", util.show_nil_as_missing(year)
end },
{ attribute = "affected_policies",
label = "Policies Affected",
render = function (value, frame)
if (value == nil) or (#value == 0) then
return "''none''"
end
local buffer = StringBuffer.new()
for _, d in ipairs(value) do
if _ > 1 then
buffer:add("<br>\n")
end
buffer
-- TODO maddog Should use a class.render method
:add_uformat("%s", d.value)
end
return buffer:output()
end },
}
},
{ renderer = function (data, buffer)
-- Find newest title, e.g. from newest event.
local events = data["events"]
local latest = get_latest_event(events)
-- for i, v in ipairs(events) do
-- if latest == nil then
-- latest = v
-- elseif v.meeting_date >= latest.meeting_date then
-- latest = v
-- end
-- end
local latest_title = latest and latest.title
if latest_title == nil then
latest_title = util.make_missing_value("missing title")
end
-- buffer:add_uformat("<b>\"%s\"</b>\n",
if (latest and latest.action) == 'skipped' then
util.assertf(latest.title == nil, "Skipped resolution should not have title.")
buffer:add_uformat("''No such resolution; this sequence number was skipped.\n")
else
buffer:add_uformat("<b><i>\"%s\"</i></b>\n",
latest_title)
local alt_title = latest and latest.alt_title
if alt_title then
buffer:add_uformat("\n<i>\"%s\"</i>\n",
alt_title)
end
end
buffer:add('\n')
end
},
{ attribute = "free_text" },
{ renderer = function (data, buffer)
local links = data["related_pages"]
if #links > 0 then
buffer:add("\n==== Related To ====\n")
for _, v in ipairs(links) do
buffer:add_uformat("* [[%s]]\n", v.value)
end
end
end
},
{ section4 = "Events" },
{ attribute = "events", render = "render_table_and_references",
render_args = {
--sort = DBA.sort_current_first,
columns = {
{ label = "School Year",
render = function(v, frame)
local s = tonumber(v.school_year)
local e = s + 1
return mw.ustring.format("%d-%d", s, e)
end
},
{ label = "Date/Meeting",
render = function(v, frame)
if v.meeting_date == nil then
return util.MISSING_VALUE
elseif v.meeting_page == nil then
return v.meeting_date .. util.make_missing_value(" (meeting missing)")
else
return util.show_as_piped_link(v.meeting_page, v.meeting_date)
end
-- return util.show_nil_as_missing(util.show_as_piped_link(v.meeting_page, v.meeting_date))
-- return mw.ustring.format("[[%s|%s]]", v.meeting_page, v.meeting_date)
end
},
{ label = "Action",
render = function(v, frame)
if v.acted_by then
return mw.ustring.format("%s (by [[%s]])", v.action, v.acted_by)
else
return v.action
end
end
},
{ label = "Title",
render = function(v, frame)
if v.alt_title then
return mw.ustring.format("%s\n(Alternate: %s)", util.show_nil_as_missing(v.title), v.alt_title)
else
return util.show_nil_as_missing(v.title)
end
end
},
RA.COLUMN_REFERENCES,
}
}
},
{ section4 = "Tasks" },
{ attribute = "work_items",
render = "render_table_and_references",
render_args = {
--sort = DBA.sort_current_first,
columns = {
{ label = "Due Date",
render = function(v, frame)
if v.deadline_date then
return v.deadline_date
else
return v.deadline_desc
end
end
},
{ label = "Status", key = "status"
},
{ label = "Party", key = "responsible_party"
},
{ label = "Description", key = "description"
},
--{ label = "Comments", key = "comments"
--},
RA.COLUMN_REFERENCES,
}
}
},
{ section4 = "Topics" },
{ attribute = "topics",
render = function (value, frame)
if (value == nil) or (#value == 0) then
return util.MISSING_VALUE
end
local buffer = StringBuffer.new()
for _, d in ipairs(value) do
-- TODO maddog Should use a class.render method
if _ > 1 then
buffer:add(" | ")
end
buffer:add_uformat("%s", d.value)
end
return buffer:output()
end },
--SOON { section2 = "Documents / Media" },
--SOON { section3 = "Notices/Agendas" },
--SOON { attribute = "documents",
--SOON render = make_document_renderer("notices"),
--SOON },
--SOON { section3 = "Materials" },
--SOON { attribute = "documents",
--SOON render = make_document_renderer("materials"),
--SOON },
--SOON { section3 = "Minutes" },
--SOON { attribute = "documents",
--SOON render = make_document_renderer("minutes"),
--SOON },
--SOON { section2 = "Sources" },
--SOON { attribute = "sources",
--SOON render = function (value, frame)
--SOON if (value == nil) or (#value == 0) then
--SOON return util.MISSING_VALUE
--SOON end
--SOON local buffer = StringBuffer.new()
--SOON for _, d in ipairs(value) do
--SOON buffer
--SOON -- TODO maddog Should use a class.render method
--SOON :add_uformat(
--SOON "* %s, %s <span style=\"font-size:84%%;\">(accessed: %s)</span>",
--SOON d.description,
--SOON util.show_url_as_external_link(d.url),
--SOON d.access_timestamp)
--SOON :nl()
--SOON end
--SOON return buffer:output()
--SOON end },
}
}