liquid_feedback_frontend
view app/main/initiative/_action/create.lua @ 81:134fce4bede3
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 | 3ec1dea6eefb | 
| children | 6a12fb7e4963 | 
 line source
     1 local tmp = db:query({ "SELECT text_entries_left, initiatives_left FROM member_contingent_left WHERE member_id = ?", app.session.member.id }, "opt_object")
     2 if tmp then
     3   if tmp.initiatives_left and tmp.initiatives_left < 1 then
     4     slot.put_into("error", _"Sorry, your contingent for creating initiatives has been used up. Please try again later.")
     5     return false
     6   end
     7   if tmp.text_entries_left and tmp.text_entries_left < 1 then
     8     slot.put_into("error", _"Sorry, you have reached your personal flood limit. Please be slower...")
     9     return false
    10   end
    11 end
    13 local issue
    14 local area
    16 local issue_id = param.get("issue_id", atom.integer)
    17 if issue_id then
    18   issue = Issue:new_selector():add_where{"id=?",issue_id}:single_object_mode():exec()
    19   if issue.closed then
    20     slot.put_into("error", _"This issue is already closed.")
    21     return false
    22   elseif issue.fully_frozen then 
    23     slot.put_into("error", _"Voting for this issue has already begun.")
    24     return false
    25   end
    26   area = issue.area
    27 else
    28   local area_id = param.get("area_id", atom.integer)
    29   area = Area:new_selector():add_where{"id=?",area_id}:single_object_mode():exec()
    30   if not area.active then
    31     slot.put_into("error", "Invalid area.")
    32     return false
    33   end
    34 end
    36 local name = param.get("name")
    38 local name = util.trim(name)
    40 if #name < 3 then
    41   slot.put_into("error", _"This name is really too short!")
    42   return false
    43 end
    45 local formatting_engine = param.get("formatting_engine")
    47 local formatting_engine_valid = false
    48 for fe, dummy in pairs(config.formatting_engine_executeables) do
    49   if formatting_engine == fe then
    50     formatting_engine_valid = true
    51   end
    52 end
    53 if not formatting_engine_valid then
    54   error("invalid formatting engine!")
    55 end
    59 local initiative = Initiative:new()
    61 if not issue then
    62   local policy_id = param.get("policy_id", atom.integer)
    63   if policy_id == -1 then
    64     slot.put_into("error", _"Please choose a policy")
    65     return false
    66   end
    67   local policy = Policy:by_id(policy_id)
    68   if not policy.active then
    69     slot.put_into("error", "Invalid policy.")
    70     return false
    71   end
    72   if not area:get_reference_selector("allowed_policies")
    73     :add_where{ "policy.id = ?", policy_id }
    74     :optional_object_mode()
    75     :exec()
    76   then
    77     error("policy not allowed")
    78   end
    79   issue = Issue:new()
    80   issue.area_id = area.id
    81   issue.policy_id = policy_id
    82   issue:save()
    83 end
    85 initiative.issue_id = issue.id
    86 initiative.name = name
    87 param.update(initiative, "discussion_url")
    88 initiative:save()
    90 local draft = Draft:new()
    91 draft.initiative_id = initiative.id
    92 draft.formatting_engine = formatting_engine
    93 draft.content = param.get("draft")
    94 draft.author_id = app.session.member.id
    95 draft:save()
    97 local initiator = Initiator:new()
    98 initiator.initiative_id = initiative.id
    99 initiator.member_id = app.session.member.id
   100 initiator.accepted = true
   101 initiator:save()
   103 local supporter = Supporter:new()
   104 supporter.initiative_id = initiative.id
   105 supporter.member_id = app.session.member.id
   106 supporter.draft_id = draft.id
   107 supporter:save()
   109 slot.put_into("notice", _"Initiative successfully created")
   111 request.redirect{
   112   module = "initiative",
   113   view = "show",
   114   id = initiative.id
   115 }
