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"
Just _ -> Authorized
instance YesodAuthPersist UniWorX
-- This instance is required to use forms. You can modify renderMessage to

View File

@ -22,6 +22,7 @@ getShowTermsR = do
setTitle "Freigeschaltete Semester"
-- TODO: provide common utility function for formatting Times
-- TODO: turn into proper table
-- TODO Edit-Links only $if isAdmin, otherwise breadcrumb navigation
[whamlet|
<h2>
Liste der freigeschalteten Semester:
@ -30,7 +31,7 @@ getShowTermsR = do
$else
<ul>
$forall Entity _ term <- terms
<li>
<li>
<a href=@{EditTermExistR $ termName term}>
#{termToText $ termName term}
von #{formatTimeGerWD $ termStart term}

View File

@ -56,7 +56,7 @@ seasonFromChar c
data TermIdentifier = TermIdentifier
{ year :: Integer -- ^ Using 'Integer' to model years is consistent with 'Data.Time.Calendar'
, 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
termToText :: TermIdentifier -> Text
@ -70,6 +70,11 @@ termFromText t
= Right TermIdentifier{..}
| 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
toPersistValue = PersistText . termToText
fromPersistValue (PersistText t) = termFromText t