       (error "Db object deleted or not own. Refusing to update: " user params id))))
 
 (defn generate-publication-date [blog]
-  (assoc blog :published (local/local-now)))
+  (when blog
+    (assoc blog :published (local/local-now))))
 
 (defn publish [user params]
   (let [id (:id params)


(defn list-by [user params]
  (let [page (parse-int (params :page "1"))
        rules (merge (filter/make-query-from params) {:draft false})
        sort-order (filter/sort-results-by params)]
    (list-result user page rules sort-order)))

(defn list-drafts [user params]
  (let [page (parse-int (params :page "1"))
        rules {:user user :draft true}
        sort-order (filter/sort-results-by params)]
    (list-result user page rules sort-order)))
  (:use
        [s3 log mongodb parser formats utils])
  (:require [monger.collection :as mc]
            [s3.mongoquery :as querystr]
            [monger.result :as mr]
            [monger.query :as mq]
            [monger.conversion]
