Ord TermIdentifier changed

This commit is contained in:
SJost 2017-10-06 23:43:12 +02:00
parent a71c7326a8
commit 1bca71b720
3 changed files with 9 additions and 2 deletions

View File

@ -267,6 +267,7 @@ isAuthenticated = do
Nothing -> Unauthorized "You must login to access this page" Nothing -> Unauthorized "You must login to access this page"
Just _ -> Authorized Just _ -> Authorized
instance YesodAuthPersist UniWorX instance YesodAuthPersist UniWorX
-- This instance is required to use forms. You can modify renderMessage to -- This instance is required to use forms. You can modify renderMessage to

View File

@ -22,6 +22,7 @@ getShowTermsR = do
setTitle "Freigeschaltete Semester" setTitle "Freigeschaltete Semester"
-- TODO: provide common utility function for formatting Times -- TODO: provide common utility function for formatting Times
-- TODO: turn into proper table -- TODO: turn into proper table
-- TODO Edit-Links only $if isAdmin, otherwise breadcrumb navigation
[whamlet| [whamlet|
<h2> <h2>
Liste der freigeschalteten Semester: Liste der freigeschalteten Semester:

View File

@ -56,7 +56,7 @@ seasonFromChar c
data TermIdentifier = TermIdentifier data TermIdentifier = TermIdentifier
{ year :: Integer -- ^ Using 'Integer' to model years is consistent with 'Data.Time.Calendar' { year :: Integer -- ^ Using 'Integer' to model years is consistent with 'Data.Time.Calendar'
, season :: Season , season :: Season
} deriving (Show, Read, Eq, Ord, Generic, Typeable) } deriving (Show, Read, Eq, Generic, Typeable)
--TODO: Enforce the number of digits within year, with parsing filling in the current leading digits? Goal: short urls --TODO: Enforce the number of digits within year, with parsing filling in the current leading digits? Goal: short urls
termToText :: TermIdentifier -> Text termToText :: TermIdentifier -> Text
@ -70,6 +70,11 @@ termFromText t
= Right TermIdentifier{..} = Right TermIdentifier{..}
| otherwise = Left $ "Invalid TermIdentifier: “" <> t <> "" | otherwise = Left $ "Invalid TermIdentifier: “" <> t <> ""
instance Ord TermIdentifier where
ti1 <= ti2 =
year ti1 <= year ti2 ||
(year ti1 == year ti2 || season ti1 <= season ti2)
instance PersistField TermIdentifier where instance PersistField TermIdentifier where
toPersistValue = PersistText . termToText toPersistValue = PersistText . termToText
fromPersistValue (PersistText t) = termFromText t fromPersistValue (PersistText t) = termFromText t