liquid_feedback_frontend
annotate env/util/autoapi.lua @ 52:88ac7798b562
Several bugfixes (getpic.c, accepted but canceled issues, ...); Listing of available policies
- Bugfixes in fastpath/getpic.c (related to crashes since alpha5)
- Respect Content-Types of images in database
(needs database update, as Content-Type was incorrectly stored by previous versions)
- Typo fixed in help messages
- RSS-Feed (currently only after manual authentication while session is valid)
- Listing of available policies
- German translation fixed: "gebe" -> "gib" (Imperativ)
- Bugfixes related to issues which had been accepted but canceled afterwards
- Prohibit creation of initiatives in disabled areas or with disabled policies
- Bugfixes in fastpath/getpic.c (related to crashes since alpha5)
- Respect Content-Types of images in database
(needs database update, as Content-Type was incorrectly stored by previous versions)
- Typo fixed in help messages
- RSS-Feed (currently only after manual authentication while session is valid)
- Listing of available policies
- German translation fixed: "gebe" -> "gib" (Imperativ)
- Bugfixes related to issues which had been accepted but canceled afterwards
- Prohibit creation of initiatives in disabled areas or with disabled policies
author | bsw/jbe |
---|---|
date | Thu Apr 15 19:58:25 2010 +0200 (2010-04-15) |
parents | 0849be391140 |
children | 733f65c0c0a0 |
rev | line source |
---|---|
bsw@51 | 1 function util.autoapi_xml(args) |
bsw@51 | 2 local selector = assert(args.selector) |
bsw@51 | 3 local fields = assert(args.fields) |
bsw@51 | 4 local rows = selector:exec() |
bsw@51 | 5 slot.set_layout("xml") |
bsw@51 | 6 slot.put("<initiative_list>\n") |
bsw@51 | 7 for i_row, row in ipairs(rows) do |
bsw@51 | 8 slot.put(" <initiative>\n") |
bsw@51 | 9 for i_field, field in ipairs(fields) do |
bsw@51 | 10 slot.put(" <", field.name, ">") |
bsw@51 | 11 local value |
bsw@51 | 12 if field.func then |
bsw@51 | 13 value = field.func(row) |
bsw@51 | 14 elseif field.field then |
bsw@51 | 15 value = row[field.name] |
bsw@51 | 16 end |
bsw/jbe@52 | 17 if value ~= nil then |
bsw@51 | 18 slot.put(encode.html(tostring(value))) |
bsw/jbe@52 | 19 else |
bsw/jbe@52 | 20 slot.put("NULL") |
bsw@51 | 21 end |
bsw@51 | 22 slot.put("</", field.name, ">\n") |
bsw@51 | 23 end |
bsw@51 | 24 slot.put(" </initiative>\n") |
bsw@51 | 25 end |
bsw@51 | 26 slot.put("</initiative_list>\n") |
bsw@51 | 27 end |
bsw@51 | 28 |
bsw@51 | 29 function util.autoapi_json(args) |
bsw@51 | 30 slot.set_layout("blank") |
bsw@51 | 31 local selector = assert(args.selector) |
bsw@51 | 32 local fields = assert(args.fields) |
bsw@51 | 33 local rows = selector:exec() |
bsw@51 | 34 slot.put("{\n") |
bsw@51 | 35 for i_row, row in ipairs(rows) do |
bsw@51 | 36 slot.put(" {\n") |
bsw@51 | 37 for i_field, field in ipairs(fields) do |
bsw@51 | 38 slot.put(" ", field.name, ": ") |
bsw@51 | 39 local value |
bsw@51 | 40 if field.func then |
bsw@51 | 41 value = field.func(row) |
bsw@51 | 42 elseif field.field then |
bsw@51 | 43 value = row[field.name] |
bsw@51 | 44 end |
bsw@51 | 45 slot.put(encode.json(value)) |
bsw@51 | 46 slot.put(",\n") |
bsw@51 | 47 end |
bsw@51 | 48 slot.put(" },\n") |
bsw@51 | 49 end |
bsw@51 | 50 slot.put("}\n") |
bsw@51 | 51 end |
bsw@51 | 52 |
bsw@51 | 53 function util.autoapi(args) |
bsw@51 | 54 local selector = assert(args.selector) |
bsw@51 | 55 local fields = assert(args.fields) |
bsw@51 | 56 local api_engine = assert(args.api_engine) |
bsw@51 | 57 |
bsw@51 | 58 selector:reset_fields() |
bsw@51 | 59 |
bsw@51 | 60 for i_field, field in ipairs(fields) do |
bsw@51 | 61 if field.field then |
bsw@51 | 62 selector:add_field(field.field, field.name) |
bsw@51 | 63 end |
bsw@51 | 64 end |
bsw@51 | 65 |
bsw@51 | 66 if api_engine == "xml" then |
bsw@51 | 67 util.autoapi_xml{ |
bsw@51 | 68 selector = selector, |
bsw@51 | 69 fields = fields |
bsw@51 | 70 } |
bsw@51 | 71 elseif api_engine == "json" then |
bsw@51 | 72 util.autoapi_json{ |
bsw@51 | 73 selector = selector, |
bsw@51 | 74 fields = fields |
bsw@51 | 75 } |
bsw@51 | 76 end |
bsw@51 | 77 |
bsw@51 | 78 end |