liquid_feedback_frontend
view model/draft.lua @ 124:f740026b1518
add initiator support in delegation
if a delegation is issued from the initiative view, the initiators
from that one are added to the delegation target list. this makes it easier to delegate to the author without the need to add him to the contact list.
if a delegation is issued from the initiative view, the initiators
from that one are added to the delegation target list. this makes it easier to delegate to the author without the need to add him to the contact list.
| author | Daniel Poelzleithner <poelzi@poelzi.org> | 
|---|---|
| date | Mon Sep 20 20:32:04 2010 +0200 (2010-09-20) | 
| parents | 134fce4bede3 | 
| children | 23c98752e697 | 
 line source
     1 Draft = mondelefant.new_class()
     2 Draft.table = 'draft'
     4 -- Many drafts belonging to an initiative
     5 Draft:add_reference{
     6   mode          = 'm1',
     7   to            = "Initiative",
     8   this_key      = 'initiative_id',
     9   that_key      = 'id',
    10   ref           = 'initiative',
    11 }
    13 -- Many drafts are authored by a member
    14 Draft:add_reference{
    15   mode          = 'm1',
    16   to            = "Member",
    17   this_key      = 'author_id',
    18   that_key      = 'id',
    19   ref           = 'author',
    20 }
    22 function Draft.object_get:author_name()
    23   return self.author and self.author.name or _"Unknown author"
    24 end
    26 -- render draft to html, save it as rendered_draft and return it
    27 function Draft.object:render_content()
    28   -- local draft for update
    29   local draft_lock = Draft:new_selector()
    30     :add_where{ "id = ?", self.id }
    31     :single_object_mode()
    32     :for_update()
    33     :exec()
    34   -- check if there is already a rendered draft
    35   local rendered_draft = RenderedDraft:new_selector()
    36     :add_where{ "draft_id = ?", self.id }
    37     :add_where{ "format = 'html'" }
    38     :optional_object_mode()
    39     :exec()
    40   if rendered_draft then
    41     return rendered_draft
    42   end
    43   -- create rendered_draft record
    44   local rendered_draft = RenderedDraft:new()
    45   rendered_draft.draft_id = self.id
    46   rendered_draft.format = "html"
    47   rendered_draft.content = format.wiki_text(self.content, self.formatting_engine)
    48   rendered_draft:save()
    49   -- and return it
    50   return rendered_draft
    51 end
    53 -- returns rendered version of draft for specific format
    54 function Draft.object:get_content(format)
    55   -- Fetch rendered_draft record for specified format
    56   local rendered_draft = RenderedDraft:new_selector()
    57     :add_where{ "draft_id = ?", self.id }
    58     :add_where{ "format = ?", format }
    59     :optional_object_mode()
    60     :exec()
    61   -- If this format isn't rendered yet, render it
    62   if not rendered_draft then
    63     rendered_draft = self:render_content()
    64   end
    65   -- return rendered content
    66   return rendered_draft.content
    67 end
