web_persist.ml 2.74 KB
Newer Older
Stephane Glondu's avatar
Stephane Glondu committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(**************************************************************************)
(*                                BELENIOS                                *)
(*                                                                        *)
(*  Copyright © 2012-2015 Inria                                           *)
(*                                                                        *)
(*  This program is free software: you can redistribute it and/or modify  *)
(*  it under the terms of the GNU Affero General Public License as        *)
(*  published by the Free Software Foundation, either version 3 of the    *)
(*  License, or (at your option) any later version, with the additional   *)
(*  exemption that compiling, linking, and/or using OpenSSL is allowed.   *)
(*                                                                        *)
(*  This program is distributed in the hope that it will be useful, but   *)
(*  WITHOUT ANY WARRANTY; without even the implied warranty of            *)
(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *)
(*  Affero General Public License for more details.                       *)
(*                                                                        *)
(*  You should have received a copy of the GNU Affero General Public      *)
(*  License along with this program.  If not, see                         *)
(*  <http://www.gnu.org/licenses/>.                                       *)
(**************************************************************************)

22
open Lwt
23
open Common
24
25
26
27
28
29
30
31
32

let election_states = Ocsipersist.open_table "election_states"

let get_election_state x =
  try_lwt Ocsipersist.find election_states x
  with Not_found -> return `Open

let set_election_state x s =
  Ocsipersist.add election_states x s
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

let store = Ocsipersist.open_store "site"

lwt main_election =
  Ocsipersist.make_persistent store "main_election" None

lwt featured =
  Ocsipersist.make_persistent store "featured_elections" []

let add_featured_election x =
  lwt the_featured = Ocsipersist.get featured in
  if List.mem x the_featured then (
    return ()
  ) else (
    Ocsipersist.set featured (x :: the_featured)
  )

let rec list_remove x = function
  | [] -> []
  | y :: ys -> if x = y then ys else y :: (list_remove x ys)

let remove_featured_election x =
  lwt the_featured = Ocsipersist.get featured in
  Ocsipersist.set featured (list_remove x the_featured)

let is_featured_election x =
  lwt the_featured = Ocsipersist.get featured in
  return (List.mem x the_featured)

let get_featured_elections () =
  Ocsipersist.get featured

let get_main_election () =
  Ocsipersist.get main_election

let set_main_election x =
  Ocsipersist.set main_election (Some x)

let unset_main_election () =
  Ocsipersist.set main_election None