liquid_feedback_frontend
view config/init.lua @ 732:3a61d21618f6
Made database configurable
| author | bsw | 
|---|---|
| date | Thu Jun 28 17:23:38 2012 +0200 (2012-06-28) | 
| parents | 0015fa6eb637 | 
| children | 9d104952554a | 
 line source
     1 config.app_version = "2.beta12"
     3 if not config.instance_name then
     4   config.instance_name = request.get_config_name()
     5 end
     7 if
     8   not config.app_service_provider or
     9   not config.use_terms or
    10   not config.use_terms_checkboxes
    11 then
    12   error("Missing mandatory config option")
    13 end
    15 if config.enabled_languages == nil then
    16   config.enabled_languages = { 'en', 'de', 'eo', 'el', 'hu' }
    17 end
    19 if config.default_lang == nil then
    20   config.default_lang = "en"
    21 end
    23 if config.mail_subject_prefix == nil then
    24   config.mail_subject_prefix = "[LiquidFeedback] "
    25 end
    27 if config.absolute_base_url == nil then
    28   config.absolute_base_url = request.get_relative_baseurl()
    29 end
    31 if config.member_image_content_type == nil then
    32   config.member_image_content_type = "image/jpeg"
    33 end
    35 if config.member_image_convert_func == nil then
    36   config.member_image_convert_func = {
    37     avatar = function(data) return extos.pfilter(data, "convert", "jpeg:-", "-thumbnail",   "48x48", "jpeg:-") end,
    38     photo =  function(data) return extos.pfilter(data, "convert", "jpeg:-", "-thumbnail", "240x240", "jpeg:-") end
    39   }
    40 end
    42 if not config.database then
    43   config.database = { engine='postgresql', dbname='liquid_feedback' }
    44 end
    46 request.set_404_route{ module = 'index', view = '404' }
    48 -- open and set default database handle
    49 db = assert(mondelefant.connect(config.database)
    50 at_exit(function() 
    51   db:close()
    52 end)
    53 function mondelefant.class_prototype:get_db_conn() return db end
    55 -- enable output of SQL commands in trace system
    56 function db:sql_tracer(command)
    57   return function(error_info)
    58     local error_info = error_info or {}
    59     trace.sql{ command = command, error_position = error_info.position }
    60   end
    61 end
    63 request.set_absolute_baseurl(config.absolute_base_url)
    67 -- TODO abstraction
    68 -- get record by id
    69 function mondelefant.class_prototype:by_id(id)
    70   local selector = self:new_selector()
    71   selector:add_where{ 'id = ?', id }
    72   selector:optional_object_mode()
    73   return selector:exec()
    74 end
