liquid_feedback_frontend
changeset 81:134fce4bede3 beta22
Cache for rendered wiki texts; Accountless API keys; Reverse id order for initiative API
- Support for caching html version of drafts
- Using pre-rendered html versions of help messages
- Added Support for api keys not connected to an account
- Added order option "id_desc" to initiative API
- Support for caching html version of drafts
- Using pre-rendered html versions of help messages
- Added Support for api keys not connected to an account
- Added order option "id_desc" to initiative API
author | bsw |
---|---|
date | Sat Jul 24 17:22:05 2010 +0200 (2010-07-24) |
parents | d898c9058d2d |
children | 9cb7b5c7caa0 |
files | Makefile README app/main/api/_filter/00_api.lua app/main/api/initiative.lua app/main/draft/_action/add.lua app/main/draft/_show.lua app/main/initiative/_action/create.lua config/default.lua env/util/help.lua model/draft.lua model/rendered_draft.lua |
line diff
1.1 --- a/Makefile Thu Jul 15 18:28:24 2010 +0200 1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 @@ -1,6 +0,0 @@ 1.4 -default: 1.5 - 1.6 - 1.7 -translations-de: 1.8 - cd ../webmcp/framework/bin/ && ./langtool.lua ~/workspace/liquid_feedback/locale/translations.de.lua ~/workspace/liquid_feedback/app ~/workspace/liquid_feedback/locale/translations.de.lua 1.9 -
2.1 --- a/README Thu Jul 15 18:28:24 2010 +0200 2.2 +++ b/README Sat Jul 24 17:22:05 2010 +0200 2.3 @@ -59,3 +59,10 @@ 2.4 your webserver appropriatly. 2.5 2.6 2.7 +7. Compile help messages from wiki to html 2.8 + 2.9 +cd /opt/liquid_feedback_frontend/locale/help 2.10 +for file in *.txt; do /opt/rocketwiki-lqfb/rocketwiki-lqfb < $file > $file.html; done 2.11 + 2.12 + 2.13 +
3.1 --- a/app/main/api/_filter/00_api.lua Thu Jul 15 18:28:24 2010 +0200 3.2 +++ b/app/main/api/_filter/00_api.lua Sat Jul 24 17:22:05 2010 +0200 3.3 @@ -8,17 +8,33 @@ 3.4 error("No API key supplied.") 3.5 end 3.6 3.7 -local setting_key = "liquidfeedback_frontend_api_key" 3.8 +local accepted = false 3.9 + 3.10 +if config.api_keys then 3.11 + for i, config_api_key in ipairs(config.api_keys) do 3.12 + if api_key == config_api_key then 3.13 + accepted = true 3.14 + end 3.15 + end 3.16 +end 3.17 + 3.18 +if not accepted then 3.19 + local setting_key = "liquidfeedback_frontend_api_key" 3.20 3.21 -local setting = Setting:new_selector() 3.22 - :add_where{ "key = ?", setting_key } 3.23 - :add_where{ "value = ?", api_key } 3.24 - :join("member", nil, "member.id = setting.member_id") 3.25 - :add_where("member.active") 3.26 - :optional_object_mode() 3.27 - :exec() 3.28 + local setting = Setting:new_selector() 3.29 + :add_where{ "key = ?", setting_key } 3.30 + :add_where{ "value = ?", api_key } 3.31 + :join("member", nil, "member.id = setting.member_id") 3.32 + :add_where("member.active") 3.33 + :optional_object_mode() 3.34 + :exec() 3.35 3.36 -if not setting then 3.37 + if setting then 3.38 + accepted = true 3.39 + end 3.40 +end 3.41 + 3.42 +if not accepted then 3.43 error("Supplied API key is not valid.") 3.44 end 3.45
4.1 --- a/app/main/api/initiative.lua Thu Jul 15 18:28:24 2010 +0200 4.2 +++ b/app/main/api/initiative.lua Sat Jul 24 17:22:05 2010 +0200 4.3 @@ -63,7 +63,11 @@ 4.4 initiatives_selector:add_order_by("initiative.supporter_count") 4.5 end 4.6 4.7 -initiatives_selector:add_order_by("initiative.id") 4.8 +if order == "id_desc" then 4.9 + initiatives_selector:add_order_by("initiative.id DESC") 4.10 +else 4.11 + initiatives_selector:add_order_by("initiative.id") 4.12 +end 4.13 4.14 if limit then 4.15 initiatives_selector:limit(limit)
5.1 --- a/app/main/draft/_action/add.lua Thu Jul 15 18:28:24 2010 +0200 5.2 +++ b/app/main/draft/_action/add.lua Sat Jul 24 17:22:05 2010 +0200 5.3 @@ -22,10 +22,8 @@ 5.4 error("access denied") 5.5 end 5.6 5.7 -local draft = Draft:new() 5.8 -draft.author_id = app.session.member.id 5.9 -draft.initiative_id = initiative.id 5.10 local formatting_engine = param.get("formatting_engine") 5.11 + 5.12 local formatting_engine_valid = false 5.13 for fe, dummy in pairs(config.formatting_engine_executeables) do 5.14 if formatting_engine == fe then 5.15 @@ -35,9 +33,16 @@ 5.16 if not formatting_engine_valid then 5.17 error("invalid formatting engine!") 5.18 end 5.19 + 5.20 + 5.21 +local draft = Draft:new() 5.22 +draft.author_id = app.session.member.id 5.23 +draft.initiative_id = initiative.id 5.24 draft.formatting_engine = formatting_engine 5.25 draft.content = param.get("content") 5.26 draft:save() 5.27 5.28 +draft:render_content() 5.29 + 5.30 slot.put_into("notice", _"New draft has been added to initiative") 5.31
6.1 --- a/app/main/draft/_show.lua Thu Jul 15 18:28:24 2010 +0200 6.2 +++ b/app/main/draft/_show.lua Sat Jul 24 17:22:05 2010 +0200 6.3 @@ -31,7 +31,7 @@ 6.4 ui.container{ 6.5 attr = { class = "draft_content wiki" }, 6.6 content = function() 6.7 - slot.put(format.wiki_text(draft.content, draft.formatting_engine)) 6.8 + slot.put(draft:get_content("html")) 6.9 end 6.10 } 6.11 end
7.1 --- a/app/main/initiative/_action/create.lua Thu Jul 15 18:28:24 2010 +0200 7.2 +++ b/app/main/initiative/_action/create.lua Sat Jul 24 17:22:05 2010 +0200 7.3 @@ -33,8 +33,6 @@ 7.4 end 7.5 end 7.6 7.7 - 7.8 - 7.9 local name = param.get("name") 7.10 7.11 local name = util.trim(name) 7.12 @@ -44,6 +42,20 @@ 7.13 return false 7.14 end 7.15 7.16 +local formatting_engine = param.get("formatting_engine") 7.17 + 7.18 +local formatting_engine_valid = false 7.19 +for fe, dummy in pairs(config.formatting_engine_executeables) do 7.20 + if formatting_engine == fe then 7.21 + formatting_engine_valid = true 7.22 + end 7.23 +end 7.24 +if not formatting_engine_valid then 7.25 + error("invalid formatting engine!") 7.26 +end 7.27 + 7.28 + 7.29 + 7.30 local initiative = Initiative:new() 7.31 7.32 if not issue then 7.33 @@ -77,16 +89,6 @@ 7.34 7.35 local draft = Draft:new() 7.36 draft.initiative_id = initiative.id 7.37 -local formatting_engine = param.get("formatting_engine") 7.38 -local formatting_engine_valid = false 7.39 -for fe, dummy in pairs(config.formatting_engine_executeables) do 7.40 - if formatting_engine == fe then 7.41 - formatting_engine_valid = true 7.42 - end 7.43 -end 7.44 -if not formatting_engine_valid then 7.45 - error("invalid formatting engine!") 7.46 -end 7.47 draft.formatting_engine = formatting_engine 7.48 draft.content = param.get("draft") 7.49 draft.author_id = app.session.member.id
8.1 --- a/config/default.lua Thu Jul 15 18:28:24 2010 +0200 8.2 +++ b/config/default.lua Sat Jul 24 17:22:05 2010 +0200 8.3 @@ -1,5 +1,5 @@ 8.4 config.app_name = "LiquidFeedback" 8.5 -config.app_version = "beta21" 8.6 +config.app_version = "beta22" 8.7 8.8 config.app_title = config.app_name .. " (" .. request.get_config_name() .. " environment)" 8.9
9.1 --- a/env/util/help.lua Thu Jul 15 18:28:24 2010 +0200 9.2 +++ b/env/util/help.lua Sat Jul 24 17:22:05 2010 +0200 9.3 @@ -37,7 +37,7 @@ 9.4 } 9.5 local lang = locale.get("lang") 9.6 local basepath = request.get_app_basepath() 9.7 - local file_name = basepath .. "/locale/help/" .. id .. "." .. lang .. ".txt" 9.8 + local file_name = basepath .. "/locale/help/" .. id .. "." .. lang .. ".txt.html" 9.9 local file = io.open(file_name) 9.10 if file ~= nil then 9.11 local help_text = file:read("*a") 9.12 @@ -45,7 +45,7 @@ 9.13 ui.container{ 9.14 attr = { class = "wiki" }, 9.15 content = function() 9.16 - slot.put(format.wiki_text(help_text)) 9.17 + slot.put(help_text) 9.18 end 9.19 } 9.20 else
10.1 --- a/model/draft.lua Thu Jul 15 18:28:24 2010 +0200 10.2 +++ b/model/draft.lua Sat Jul 24 17:22:05 2010 +0200 10.3 @@ -1,6 +1,7 @@ 10.4 Draft = mondelefant.new_class() 10.5 Draft.table = 'draft' 10.6 10.7 +-- Many drafts belonging to an initiative 10.8 Draft:add_reference{ 10.9 mode = 'm1', 10.10 to = "Initiative", 10.11 @@ -9,6 +10,7 @@ 10.12 ref = 'initiative', 10.13 } 10.14 10.15 +-- Many drafts are authored by a member 10.16 Draft:add_reference{ 10.17 mode = 'm1', 10.18 to = "Member", 10.19 @@ -17,8 +19,49 @@ 10.20 ref = 'author', 10.21 } 10.22 10.23 --- reference to supporter probably not needed 10.24 - 10.25 function Draft.object_get:author_name() 10.26 return self.author and self.author.name or _"Unknown author" 10.27 end 10.28 + 10.29 +-- render draft to html, save it as rendered_draft and return it 10.30 +function Draft.object:render_content() 10.31 + -- local draft for update 10.32 + local draft_lock = Draft:new_selector() 10.33 + :add_where{ "id = ?", self.id } 10.34 + :single_object_mode() 10.35 + :for_update() 10.36 + :exec() 10.37 + -- check if there is already a rendered draft 10.38 + local rendered_draft = RenderedDraft:new_selector() 10.39 + :add_where{ "draft_id = ?", self.id } 10.40 + :add_where{ "format = 'html'" } 10.41 + :optional_object_mode() 10.42 + :exec() 10.43 + if rendered_draft then 10.44 + return rendered_draft 10.45 + end 10.46 + -- create rendered_draft record 10.47 + local rendered_draft = RenderedDraft:new() 10.48 + rendered_draft.draft_id = self.id 10.49 + rendered_draft.format = "html" 10.50 + rendered_draft.content = format.wiki_text(self.content, self.formatting_engine) 10.51 + rendered_draft:save() 10.52 + -- and return it 10.53 + return rendered_draft 10.54 +end 10.55 + 10.56 +-- returns rendered version of draft for specific format 10.57 +function Draft.object:get_content(format) 10.58 + -- Fetch rendered_draft record for specified format 10.59 + local rendered_draft = RenderedDraft:new_selector() 10.60 + :add_where{ "draft_id = ?", self.id } 10.61 + :add_where{ "format = ?", format } 10.62 + :optional_object_mode() 10.63 + :exec() 10.64 + -- If this format isn't rendered yet, render it 10.65 + if not rendered_draft then 10.66 + rendered_draft = self:render_content() 10.67 + end 10.68 + -- return rendered content 10.69 + return rendered_draft.content 10.70 +end 10.71 \ No newline at end of file
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/model/rendered_draft.lua Sat Jul 24 17:22:05 2010 +0200 11.3 @@ -0,0 +1,11 @@ 11.4 +RenderedDraft = mondelefant.new_class() 11.5 +RenderedDraft.table = 'rendered_draft' 11.6 +RenderedDraft.primary_key = { "draft_id", "format" } 11.7 + 11.8 +RenderedDraft:add_reference{ 11.9 + mode = 'm1', 11.10 + to = "Draft", 11.11 + this_key = 'draft_id', 11.12 + that_key = 'id', 11.13 + ref = 'draft', 11.14 +}