 
 (defn new-controller
   [entity-key uri-parameters]
-  (@layout (string/capitalize (dog-mission/translate :new-view-title (dog-mission/translate entity-key)))
-           (list [:p "new"]
-                 (form-to
-                  [:post (<< "/~(name entity-key)")]
-                  (hidden-field :index-params (get-in *request* [:params :index-params]))
-                  (submit-button "create"))
-                 (link-to-with-method-and-params {:class "btn btn-default"} (<< "/~(name entity-key)") :get (base64-decode (get-in *request* [:params :index-params])) (string/capitalize (dog-mission/translate :back))))))
+  (layout (string/capitalize (dog-mission/translate :new-view-title (dog-mission/translate entity-key)))
+          (list [:p "new"]
+                (form-to
+                 [:post (<< "/~(name entity-key)")]
+                 (hidden-field :index-params (get-in *request* [:params :index-params]))
+                 (submit-button "create"))
+                (link-to-with-method-and-params {:class "btn btn-default"} (<< "/~(name entity-key)") :get (base64-decode (get-in *request* [:params :index-params])) (string/capitalize (dog-mission/translate :back))))))
 
 (defn create-controller
   [entity-key uri-parameters]
-  (@layout (string/capitalize (dog-mission/translate :create-view-title (dog-mission/translate entity-key)))
-           (list [:p "create"]
-                 (link-to-with-method-and-params {:class "btn btn-default"} (<< "/~(name entity-key)") :get (base64-decode (get-in *request* [:params :index-params])) (string/capitalize (dog-mission/translate :back))))))
+  (layout (string/capitalize (dog-mission/translate :create-view-title (dog-mission/translate entity-key)))
+          (list [:p "create"]
+                (link-to-with-method-and-params {:class "btn btn-default"} (<< "/~(name entity-key)") :get (base64-decode (get-in *request* [:params :index-params])) (string/capitalize (dog-mission/translate :back))))))
 
 (defn edit-controller
   [entity-key uri-parameters]
-  (@layout (string/capitalize (dog-mission/translate :edit-view-title (dog-mission/translate entity-key)))
-           (list [:p "edit"]
-                 (form-to
-                  [:patch  (<< "/~(name entity-key)/~(:key uri-parameters)")]
-                  (hidden-field :index-params (get-in *request* [:params :index-params]))
-                  (submit-button "update"))
-                 (link-to-with-method-and-params {:class "btn btn-default"} (<< "/~(name entity-key)") :get (base64-decode (get-in *request* [:params :index-params])) (string/capitalize (dog-mission/translate :back))))))
+  (layout (string/capitalize (dog-mission/translate :edit-view-title (dog-mission/translate entity-key)))
+          (list [:p "edit"]
+                (form-to
+                 [:patch  (<< "/~(name entity-key)/~(:key uri-parameters)")]
+                 (hidden-field :index-params (get-in *request* [:params :index-params]))
+                 (submit-button "update"))
+                (link-to-with-method-and-params {:class "btn btn-default"} (<< "/~(name entity-key)") :get (base64-decode (get-in *request* [:params :index-params])) (string/capitalize (dog-mission/translate :back))))))
 
 (defn update-controller
   [entity-key uri-parameters]
-  (@layout (string/capitalize (dog-mission/translate :update-view-title (dog-mission/translate entity-key)))
-           (list [:p "update"]
-                 (link-to-with-method-and-params {:class "btn btn-default"} (<< "/~(name entity-key)") :get (base64-decode (get-in *request* [:params :index-params])) (string/capitalize (dog-mission/translate :back))))))
+  (layout (string/capitalize (dog-mission/translate :update-view-title (dog-mission/translate entity-key)))
+          (list [:p "update"]
+                (link-to-with-method-and-params {:class "btn btn-default"} (<< "/~(name entity-key)") :get (base64-decode (get-in *request* [:params :index-params])) (string/capitalize (dog-mission/translate :back))))))
 
 (defn destroy-controller
   [entity-key uri-parameters]
-  (@layout (string/capitalize (dog-mission/translate :destroy-view-title (dog-mission/translate entity-key)))
-           (list [:p "destroy"]
-                 (link-to-with-method-and-params {:class "btn btn-default"} (<< "/~(name entity-key)") :get (base64-decode (get-in *request* [:params :index-params])) (string/capitalize (dog-mission/translate :back))))))
+  (layout (string/capitalize (dog-mission/translate :destroy-view-title (dog-mission/translate entity-key)))
+          (list [:p "destroy"]
+                (link-to-with-method-and-params {:class "btn btn-default"} (<< "/~(name entity-key)") :get (base64-decode (get-in *request* [:params :index-params])) (string/capitalize (dog-mission/translate :back))))))
 
 ;; Rouring.
 

     (drop-down
      {:class "form-control"}
      param-key
      (cons "" (map (partial format-property-param entity-key property-key) [true false]))
      (format-property-param entity-key property-key (get-in *request* [:entity-params param-key])))]))

(defn- date-time-condition-control

(def ^:private brand-name
  (atom nil))

(def ^:private layout-fn
  (atom nil))

(defn initialize
  [database-schema database-spec brand-name layout-fn]
  (reset! sweet-crossplane.core/database-schema database-schema)
  (reset! sweet-crossplane.core/database-spec   database-spec)
  (reset! sweet-crossplane.core/brand-name      brand-name)
  (reset! sweet-crossplane.core/layout-fn       layout-fn))

;; Models.

(defn entity-keys
  []
  (keys @database-schema))

(defn entity-schema
  [entity-key]
  (get @database-schema entity-key))

(defn inputtable-property-keys
  [entity-key]
  (->> (entity-schema entity-key)
       ((juxt :columns :many-to-one-relationships))
       (map keys)
       (apply concat)))

(defn property-keys
  [entity-key]
  (concat (inputtable-property-keys entity-key)
          (keys (:one-to-many-relationships (entity-schema entity-key)))))

(defn search-condition-property-keys
  [entity-key]
  (or (get-in (entity-schema entity-key) [:search-condition :properties])
      (inputtable-property-keys entity-key)))

(defn list-property-keys
  [entity-key]
  (or (get-in (entity-schema entity-key) [:list :properties])
      (property-keys entity-key)))

(defn sort-keyfn-and-comp
  [entity-key]
  (let [[keyfn comp] (get-in (entity-schema entity-key) [:list :sort-by])]
    [(or keyfn (first (list-property-keys entity-key)))
     (or comp  compare)]))

(defn representative-property-key
  [entity-key]
  (or (:representative (entity-schema entity-key))
      :name))

(defn property-schema
  [entity-key property-key]
  (let [entity-schema (entity-schema entity-key)]
    (or (get-in entity-schema [:columns                   property-key])
        (get-in entity-schema [:many-to-one-relationships property-key])
        (get-in entity-schema [:one-to-many-relationships property-key]))))

(defn property-type
  [entity-key property-key]
  (let [entity-schema (entity-schema entity-key)]
    (or (get-in entity-schema [:columns property-key :type])
        (and (get-in entity-schema [:many-to-one-relationships property-key]) :many-to-one)
        (and (get-in entity-schema [:one-to-many-relationships property-key]) :one-to-many))))

(defmulti parse-property-param
  (fn [entity-key property-key param-value] (property-type entity-key property-key)))

(defmethod parse-property-param :integer
