liquid_feedback_frontend

annotate env/util/autoapi.lua @ 75:733f65c0c0a0

Bugfixes, feature enhancements, code-cleanup, and major work on API

Details:
- API
-- Allow relation name to be passed to helper function util.autoapi{...}
-- Added area API
-- Bugfixes in API
--- Correctly return initiatives (bug #162)
--- Correctly process "id" parameter for initiative API
--- Bugfix related to "state" parameter (bug #165)
--- Changed constant "discussion" to "accepted" (in model/issue.lua, used by API)
--- Fixed JSON encoding in auto_api (bug #181)
--- Ignore list filter "voted" in case of public access
--- Enable access to API without session
- Work on RSS feed (incomplete yet)
- Other bugfixes
-- Handle empty browser identification string
-- Handle invalid date in member/update.lua (bugs #24 #109 #115 #136)
-- Better handle errors while converting uploaded images. (bug #79 +5 duplicates)
-- Don't display revoked initiatives in list of new drafts (bug #134)
-- Fixed syntax error in app/main/member/_action/update_name.lua throwing unexpected error, when new name was too short
-- Do not display refresh support button for revoked initiatives
-- Repaired issue search (bug #150)
-- Fixed typos in german translation files
--- "initi(i)erte"
--- "Er(g)eignisse" (bug #161)
- Code cleanup
-- Removed deprecated motd files locale/motd/de.txt and locale/motd/de_public.txt
-- Removed redundant code in app/main/index/_updated_drafts.lua
- New features and (optical) enhancements
-- Support change of notify email; notification of not approved address added to start page
-- Settings dialog splitted into single pages
-- Mark deactivated members
-- Calendar for birthday selection in profile
-- Policy list public readable when public access is enabled
author bsw
date Thu Jul 08 18:44:02 2010 +0200 (2010-07-08)
parents 88ac7798b562
children
rev   line source
bsw@51 1 function util.autoapi_xml(args)
bsw@75 2 local relation_name = assert(args.relation_name)
bsw@51 3 local selector = assert(args.selector)
bsw@51 4 local fields = assert(args.fields)
bsw@51 5 local rows = selector:exec()
bsw@75 6 slot.set_layout("xml", "application/xml")
bsw@75 7 slot.put("<", relation_name, "_list>\n")
bsw@51 8 for i_row, row in ipairs(rows) do
bsw@75 9 slot.put(" <", relation_name, ">\n")
bsw@51 10 for i_field, field in ipairs(fields) do
bsw@51 11 slot.put(" <", field.name, ">")
bsw@51 12 local value
bsw@51 13 if field.func then
bsw@51 14 value = field.func(row)
bsw@51 15 elseif field.field then
bsw@51 16 value = row[field.name]
bsw@51 17 end
bsw/jbe@52 18 if value ~= nil then
bsw@51 19 slot.put(encode.html(tostring(value)))
bsw/jbe@52 20 else
bsw/jbe@52 21 slot.put("NULL")
bsw@51 22 end
bsw@51 23 slot.put("</", field.name, ">\n")
bsw@51 24 end
bsw@75 25 slot.put(" </", relation_name, ">\n")
bsw@51 26 end
bsw@75 27 slot.put("</", relation_name, "_list>\n")
bsw@51 28 end
bsw@51 29
bsw@51 30 function util.autoapi_json(args)
bsw@75 31 slot.set_layout("blank", "application/json")
bsw@51 32 local selector = assert(args.selector)
bsw@51 33 local fields = assert(args.fields)
bsw@51 34 local rows = selector:exec()
bsw@75 35 slot.put("[\n")
bsw@51 36 for i_row, row in ipairs(rows) do
bsw@51 37 slot.put(" {\n")
bsw@51 38 for i_field, field in ipairs(fields) do
bsw@75 39 slot.put(" \"", field.name, "\": ")
bsw@51 40 local value
bsw@51 41 if field.func then
bsw@51 42 value = field.func(row)
bsw@51 43 elseif field.field then
bsw@51 44 value = row[field.name]
bsw@51 45 end
bsw@75 46 slot.put(encode.json(value))
bsw@75 47 if i_field < #fields then
bsw@75 48 slot.put(",")
bsw@75 49 end
bsw@75 50 slot.put("\n")
bsw@51 51 end
bsw@75 52 slot.put(" }")
bsw@75 53 if i_row < #rows then
bsw@75 54 slot.put(",")
bsw@75 55 end
bsw@75 56 slot.put("\n")
bsw@51 57 end
bsw@75 58 slot.put("]\n")
bsw@51 59 end
bsw@51 60
bsw@51 61 function util.autoapi(args)
bsw@75 62 local relation_name = assert(args.relation_name)
bsw@51 63 local selector = assert(args.selector)
bsw@51 64 local fields = assert(args.fields)
bsw@51 65 local api_engine = assert(args.api_engine)
bsw@51 66
bsw@51 67 selector:reset_fields()
bsw@51 68
bsw@51 69 for i_field, field in ipairs(fields) do
bsw@51 70 if field.field then
bsw@51 71 selector:add_field(field.field, field.name)
bsw@51 72 end
bsw@51 73 end
bsw@51 74
bsw@51 75 if api_engine == "xml" then
bsw@51 76 util.autoapi_xml{
bsw@75 77 relation_name = relation_name,
bsw@51 78 selector = selector,
bsw@51 79 fields = fields
bsw@51 80 }
bsw@51 81 elseif api_engine == "json" then
bsw@51 82 util.autoapi_json{
bsw@51 83 selector = selector,
bsw@51 84 fields = fields
bsw@51 85 }
bsw@51 86 end
bsw@51 87
bsw@51 88 end

Impressum / About Us