<commit_before>{-# LANGUAGE QuasiQuotes, OverloadedStrings, TemplateHaskell #-}
module Handler.Job
    ( getJobsR
    , postJobsR
    , getJobR
    , getJobsFeedR
    ) where

import Foundation
import Control.Applicative
import Data.Maybe (fromMaybe)
import Data.Time
import Yesod.Form.Jquery
import Control.Monad (unless)
import Yesod.Feed
import Yesod.Auth

jobFormlet :: UserId -> UTCTime -> Maybe Job -> Html -> MForm Haskellers Haskellers (FormResult Job, Widget)
jobFormlet uid now mj = renderTable $ Job
    <$> pure (fromMaybe uid (fmap jobPostedBy mj))
    <*> pure (fromMaybe now (fmap jobPostedAt mj))
    <*> areq textField "Title"
            { fsId = Just "title"
            } (fmap jobTitle mj)
    <*> areq textField "Location"
            { fsTooltip = Just "If this is a telecommuting position, specify here"
            , fsId = Just "location"
            } (fmap jobLocation mj)
    <*> areq (jqueryDayField def) "Filling by" (fmap jobFillingBy mj)
    <*> areq boolField "Full time option?" (fmap jobFullTime mj)
    <*> areq boolField "Part time option?" (fmap jobPartTime mj)
    <*> areq textareaField "Description"
            { fsId = Just "desc"
            } (fmap jobDesc mj)

getJobsR :: Handler RepHtml
getJobsR = do
    mu <- maybeAuth
    now <- liftIO getCurrentTime
    let today = utctDay now
    jobs <- runDB $ selectList [JobFillingBy >. today] [Desc JobPostedAt]
    let isUnver = Just False == fmap (userReal . entityVal) mu
    mform <-
        case mu of
            Nothing -> return Nothing
            Just (Entity uid u) ->
                if userReal u
                    then do
                        ((_, form), _) <- runFormGet $ jobFormlet uid now Nothing
                        return $ Just form
                    else return Nothing
    defaultLayout $ do
        addCassius $(cassiusFile "jobs")
        addCassius $(cassiusFile "login-status")
        addWidget $(hamletFile "jobs")

postJobsR :: Handler RepHtml
postJobsR = do
    Entity uid u <- requireAuth
    unless (userReal u) $ permissionDenied "Only verified users can add job listings"
    now <- liftIO getCurrentTime
    ((res, form), _) <- runFormPostNoToken $ jobFormlet uid now Nothing
    let mform = Just form
    case res of
        FormSuccess job -> do
            jid <- runDB $ insert job
            setMessage "Job posted"
            redirect $ JobR jid
        _ -> return ()
    let jobs = []
    let isUnver = False
    defaultLayout $ do
        addCassius $(cassiusFile "jobs")
        $(hamletFile "jobs")

getJobR :: JobId -> Handler RepHtml
getJobR jid = do
    job <- runDB $ get404 jid
    poster <- runDB $ get404 $ jobPostedBy job
    defaultLayout $ do
        addCassius $(cassiusFile "job")
        $(hamletFile "job")

getJobsFeedR :: Handler RepAtomRss
getJobsFeedR = do
    cacheSeconds 7200
    now <- liftIO getCurrentTime
    let today = utctDay now
    jobs <- runDB $ selectList [JobFillingBy >. today] [Desc JobPostedAt, LimitTo 10]<commit_msg>Verified email for job posting<commit_after>{-# LANGUAGE QuasiQuotes, OverloadedStrings, TemplateHaskell #-}
module Handler.Job
    ( getJobsR
    , postJobsR
    , getJobR
    , getJobsFeedR
    ) where

import Foundation
import Control.Applicative
import Data.Maybe (fromMaybe)
import Data.Time
import Yesod.Form.Jquery
import Control.Monad (unless)
import Yesod.Feed
import Yesod.Auth

jobFormlet :: UserId -> UTCTime -> Maybe Job -> Html -> MForm Haskellers Haskellers (FormResult Job, Widget)
jobFormlet uid now mj = renderTable $ Job
    <$> pure (fromMaybe uid (fmap jobPostedBy mj))
    <*> pure (fromMaybe now (fmap jobPostedAt mj))
    <*> areq textField "Title"
            { fsId = Just "title"
            } (fmap jobTitle mj)
    <*> areq textField "Location"
            { fsTooltip = Just "If this is a telecommuting position, specify here"
            , fsId = Just "location"
            } (fmap jobLocation mj)
    <*> areq (jqueryDayField def) "Filling by" (fmap jobFillingBy mj)
    <*> areq boolField "Full time option?" (fmap jobFullTime mj)
    <*> areq boolField "Part time option?" (fmap jobPartTime mj)
    <*> areq textareaField "Description"
            { fsId = Just "desc"
            } (fmap jobDesc mj)

getJobsR :: Handler RepHtml
getJobsR = do
    mu <- maybeAuth
    now <- liftIO getCurrentTime
    let today = utctDay now
    jobs <- runDB $ selectList [JobFillingBy >. today] [Desc JobPostedAt]
    let isUnver = Just False == fmap (userReal . entityVal) mu
    mform <-
        case mu of
            Nothing -> return Nothing
            Just (Entity uid u) ->
                if userReal u
                    then do
                        ((_, form), _) <- runFormGet $ jobFormlet uid now Nothing
                        return $ Just form
                    else return Nothing
    defaultLayout $ do
        addCassius $(cassiusFile "jobs")
        addCassius $(cassiusFile "login-status")
        addWidget $(hamletFile "jobs")

postJobsR :: Handler RepHtml
postJobsR = do
    Entity uid u <- requireAuth
    unless (userVerifiedEmail u) $ permissionDenied "Only users with verified email addresses can add job listings"
    now <- liftIO getCurrentTime
    ((res, form), _) <- runFormPostNoToken $ jobFormlet uid now Nothing
    let mform = Just form
    case res of
        FormSuccess job -> do
            jid <- runDB $ insert job
            setMessage "Job posted"
            redirect $ JobR jid
        _ -> return ()
    let jobs = []
    let isUnver = False
    defaultLayout $ do
        addCassius $(cassiusFile "jobs")
        $(hamletFile "jobs")

getJobR :: JobId -> Handler RepHtml
getJobR jid = do
    job <- runDB $ get404 jid
    poster <- runDB $ get404 $ jobPostedBy job
    defaultLayout $ do
        addCassius $(cassiusFile "job")
        $(hamletFile "job")

getJobsFeedR :: Handler RepAtomRss
getJobsFeedR = do
    cacheSeconds 7200
    now <- liftIO getCurrentTime
    let today = utctDay now
    jobs <- runDB $ selectList [JobFillingBy >. today] [Desc JobPostedAt, LimitTo 10]
{'fraction_non_alphanumeric': 0.08906481939633845, 'fraction_numerical': 0.0039584364176150424, 'mean_word_length': 2.353982300884956, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5849720', 'n_tokens_mistral': 1924, 'n_tokens_neox': 1827, 'n_words': 602}