Commits

Luke Plant  committed 5b2e07d

Removed pointless conversion between list of errors and Map of errors

This also means we preserve order of validation errors, which is helpful.

  • Participants
  • Parent commits 49a0a85

Comments (0)

Files changed (2)

File src/Blog/Forms.hs

                     , hidden = False
                     , response = ""
                     }
-             , Map.fromList errors
+             , errors
              , if test_ts > 0 then test_ts else ts
              )
 
        then do
          passwordCheck <- checkPassword cn username password
          if passwordCheck
-            then return (loginData, Map.empty)
-            else return (loginData, Map.fromList [("password", "Password not correct.")])
+            then return (loginData, [])
+            else return (loginData, [("password", "Password not correct.")])
        else do
-         return (loginData, Map.fromList errors)
+         return (loginData, errors)
 
 emptyPost = P.Post { uid = undefined
                    , title = ""

File src/Blog/Views.hs

                         ("commentAccepted", commentStage == CommentAccepted)
                         ("commentInvalid", commentStage == CommentInvalid)
                         ("newComment", commentTemplateInfo commentData)
-                        ("commentErrors", Map.toList $ commentErrors)
+                        ("commentErrors", commentErrors)
                         ("categories", map categoryTemplateInfo cats)
                         ("comments", map commentTemplateInfo comments)
                         ("hasComments", not $ null comments)
           "POST" -> do
             creds <- getCredentials req
             (commentData, commentErrors, commentExtra) <- validateComment creds (getPOST req) post
-            if Map.null commentErrors
+            if null commentErrors
                then if isJust (getPOST req "submit")
-                    then
-                        do
-                          addComment cn commentData
-                          return (CommentAccepted, emptyComment, Map.empty, commentExtra)
-                          -- Just assume 'preview' if not 'submit'
+                    then do
+                      addComment cn commentData
+                      return (CommentAccepted, emptyComment, [], commentExtra)
+                    -- Just assume 'preview' if not 'submit'
                     else return (CommentPreview, commentData, commentErrors, commentExtra)
                else
-                   return (CommentInvalid, commentData, commentErrors, commentExtra)
+                 return (CommentInvalid, commentData, commentErrors, commentExtra)
 
           _ -> do commentExtra <- initialCommentExtra req
-                  return (NoComment, emptyComment, Map.empty, commentExtra)
+                  return (NoComment, emptyComment, [], commentExtra)
 
 
 -- | View that shows a post as a static information page -- no comments etc.
   case requestMethod req of
     "POST" -> do
       (loginData, loginErrors) <- validateLogin (getPOST req) cn
-      if Map.null loginErrors
+      if null loginErrors
          then do
            ts <- getTimestamp
            let loginCookies = createLoginCookies loginData ts
            return $ Just $ standardResponseTT req $ loginPage t loginData loginErrors
     _ -> do
       t <- loginTemplate
-      return $ Just $ standardResponseTT req $ loginPage t emptyLoginData (Map.empty :: Map.Map String String)
+      return $ Just $ standardResponseTT req $ loginPage t emptyLoginData ([] :: [(String,String)])
 
   where loginPage t loginData loginErrors =
             (renderf t
-             ("loginInvalid", not $ Map.null loginErrors)
-             ("loginErrors", Map.toList loginErrors)
+             ("loginInvalid", not $ null loginErrors)
+             ("loginErrors", loginErrors)
              ("loginData", loginData)
             )