liquid_feedback_frontend

view 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
line source
1 function util.autoapi_xml(args)
2 local relation_name = assert(args.relation_name)
3 local selector = assert(args.selector)
4 local fields = assert(args.fields)
5 local rows = selector:exec()
6 slot.set_layout("xml", "application/xml")
7 slot.put("<", relation_name, "_list>\n")
8 for i_row, row in ipairs(rows) do
9 slot.put(" <", relation_name, ">\n")
10 for i_field, field in ipairs(fields) do
11 slot.put(" <", field.name, ">")
12 local value
13 if field.func then
14 value = field.func(row)
15 elseif field.field then
16 value = row[field.name]
17 end
18 if value ~= nil then
19 slot.put(encode.html(tostring(value)))
20 else
21 slot.put("NULL")
22 end
23 slot.put("</", field.name, ">\n")
24 end
25 slot.put(" </", relation_name, ">\n")
26 end
27 slot.put("</", relation_name, "_list>\n")
28 end
30 function util.autoapi_json(args)
31 slot.set_layout("blank", "application/json")
32 local selector = assert(args.selector)
33 local fields = assert(args.fields)
34 local rows = selector:exec()
35 slot.put("[\n")
36 for i_row, row in ipairs(rows) do
37 slot.put(" {\n")
38 for i_field, field in ipairs(fields) do
39 slot.put(" \"", field.name, "\": ")
40 local value
41 if field.func then
42 value = field.func(row)
43 elseif field.field then
44 value = row[field.name]
45 end
46 slot.put(encode.json(value))
47 if i_field < #fields then
48 slot.put(",")
49 end
50 slot.put("\n")
51 end
52 slot.put(" }")
53 if i_row < #rows then
54 slot.put(",")
55 end
56 slot.put("\n")
57 end
58 slot.put("]\n")
59 end
61 function util.autoapi(args)
62 local relation_name = assert(args.relation_name)
63 local selector = assert(args.selector)
64 local fields = assert(args.fields)
65 local api_engine = assert(args.api_engine)
67 selector:reset_fields()
69 for i_field, field in ipairs(fields) do
70 if field.field then
71 selector:add_field(field.field, field.name)
72 end
73 end
75 if api_engine == "xml" then
76 util.autoapi_xml{
77 relation_name = relation_name,
78 selector = selector,
79 fields = fields
80 }
81 elseif api_engine == "json" then
82 util.autoapi_json{
83 selector = selector,
84 fields = fields
85 }
86 end
88 end

Impressum / About Us