Index: /trunk/lib/Vote/Controller/Ballot.pm
===================================================================
--- /trunk/lib/Vote/Controller/Ballot.pm	(revision 206)
+++ /trunk/lib/Vote/Controller/Ballot.pm	(revision 207)
@@ -47,5 +47,5 @@
     my $password = $c->session->{password} || $c->req->param('password');
 
-    if (!$c->model('Vote')->auth_voting($id, $mail, $password)) {
+    if (!$c->model('Vote')->poll($id)->auth_voting($mail, $password)) {
         $c->stash->{page}{title} = $poll->info('label') . ': Login';
         $c->delete_session('invalid user/pass');
@@ -73,6 +73,6 @@
     my $vote = $c->model('Vote');
     my %choices;
-    foreach ($vote->vote_choices($id)) {
-        $choices{$vote->choice_info($_)->{key}} = $vote->choice_info($_)->{label};
+    foreach ($poll->choices_keys) {
+        $choices{$_} = $poll->choice($_)->info->{label};
     }
     $c->stash->{choices} = { %choices };
@@ -111,7 +111,6 @@
 
     if ($c->req->param('confirm')) {
-        $c->stash->{ballotid} = $vote->register_ballot(
+        $c->stash->{ballotid} = $poll->register_ballot(
             $mail,
-            $id,
             [ @sbalval ],
             [ @{ $c->stash->{fsbal} } ],
Index: /trunk/lib/Vote/Controller/Vote.pm
===================================================================
--- /trunk/lib/Vote/Controller/Vote.pm	(revision 206)
+++ /trunk/lib/Vote/Controller/Vote.pm	(revision 207)
@@ -38,5 +38,5 @@
 
     $c->stash->{voteid} = $id;
-    $c->stash->{page}{title} = 'Vote: ' . $c->model('Vote')->poll($id).info('label');
+    $c->stash->{page}{title} = 'Vote: ' . $c->model('Vote')->poll($id)->info('label');
 }
 
Index: /trunk/lib/Vote/DB.pm
===================================================================
--- /trunk/lib/Vote/DB.pm	(revision 206)
+++ /trunk/lib/Vote/DB.pm	(revision 207)
@@ -8,7 +8,4 @@
 use Vote::DB::Poll;
 use Vote::DB::Poll::Results;
-use Vote::DB::Ballot; # see ballot()
-use Vote::DB::Voting; # see delete_voting()
-use Vote::DB::Choice;
 
 our $VERSION = '1.90';
@@ -100,205 +97,45 @@
 }
 
-# TODO
-sub ballot {
-    my ($self, $ballotid) = @_;
-    die "# ballot" . join(' ',caller());
-    # TODO must die, ballot are attached to a poll
-    Vote::DB::Ballot->new($self->{dbstring}, $ballotid);
-}
-
-# TODO
-sub vote_param {
-    my ($self, $voteid, %attr) = @_;
-    die "# vote_param" . join(' ',caller());
-    $self->poll($voteid)->param(%attr);
-}
-
-# TODO kill this
-sub vote_status {
-    my ($self, $id) = @_;
-    die "# vote_status" . join(' ',caller());
-    $self->poll($id)->status;
-}
-
-# TODO
-sub vote_info {
-    my ($self, $id) = @_;
-    die "# vote_info" . join(' ',caller());
-    $self->poll($id)->info;
-}
-
-sub vote_set_settings {
-    my ($self, $poll, $var, $val) = @_;
-    $self->poll($poll)->set_settings($var, $val);
-}
-
-sub vote_signing {
-    my ($self, $id) = @_;
-    $self->poll($id)->signing;
-}
-
-sub vote_voting {
-    my ($self, $voteid) = @_;
-    $self->poll($voteid)->voting_keys;
-}
-
-sub voting_info {
-    my ($self, $id) = @_;
-    $self->poll($id)->voting_info;
-}
-
-sub vote_choices {
-    my ($self, $id) = @_;
-    $self->poll($id)->choices;
-}
-
-sub vote_add_choice {
-    my ($self, $voteid, $label) = @_;
-    $self->poll($voteid)->add_choice($label);
-}
-
-sub choice_info {
-    my ($self, $chid) = @_;
-    Vote::DB::Choice->new($self->{dbstring}, $chid)->info;
-}
-
-sub delete_choice {
-    my ($self, $chid) = @_;
-
-    my $sth = $self->db->prepare_cached(
-        q{delete from choice where key = ?}
-    );
-
-    $sth->execute($chid);
-}
-
-sub voting_info_id {
-    my ($self, $mail, $voteid) = @_;
-    $self->poll($voteid)->voting_from_mail($mail)->info;
-}
-
-sub register_ballot {
-    my ($self, $vid, $voteid, $choice, $fchoice, $referal) = @_;
-    $self->poll($voteid)->register_ballot($vid, $choice, $fchoice, $referal);
-}
-
-sub vote_voting_count {
-    my ($self, $id) = @_;
-    $self->poll($id)->voting_count;
-}
-
+# This part is keep to track error
+sub ballot {die "# ballot" . join(' ',caller());}
+sub vote_param { die "# vote_param" . join(' ',caller());}
+sub vote_status {die "# vote_status" . join(' ',caller());}
+sub vote_info {die "# vote_info" . join(' ',caller());}
+sub vote_set_settings {die "# old functions" . join(' ',caller());}
+sub vote_signing {die "# old functions" . join(' ',caller());}
+sub vote_voting {die "# old functions" . join(' ',caller());}
+sub voting_info {die "# old functions" . join(' ',caller());}
+sub vote_choices {die "# old functions" . join(' ',caller());}
+sub vote_add_choice {die "# old functions" . join(' ',caller());}
+sub choice_info {die "# old functions" . join(' ',caller());}
+sub delete_choice {die "# old functions" . join(' ',caller());}
+sub voting_info_id {die "# old functions" . join(' ',caller());}
+sub register_ballot {die "# old functions" . join(' ',caller());}
+sub vote_voting_count {die "# old functions" . join(' ',caller());}
 sub signing_count { vote_signing_count(@_) }
-
-sub vote_signing_count {
-    my ($self, $voteid) = @_;
-    $self->poll($voteid)->signing_count;
-}
-
+sub vote_signing_count {die "# old functions" . join(' ',caller());}
 sub ballot_count { vote_ballot_count(@_) }
-
-sub vote_ballot_count {
-    my ($self, $voteid) = @_;
-    $self->poll($voteid)->ballot_count;
-}
-
+sub vote_ballot_count {die "# old functions" . join(' ',caller());}
 sub ballot_count_nonull { vote_ballot_count_nonull(@_) }
-
-sub vote_ballot_count_nonull {
-    my ($self, $voteid) = @_;
-    $self->results($voteid)->ballot_count_nonull;
-}
-
-sub auth_voting {
-    my ($self, $poll, $mail, $password) = @_;
-    $self->poll($poll)->auth_voting($mail, $password);
-}
-
-sub auth_poll {
-    my ($self, $voteid, $passwd) = @_;
-    $self->poll($voteid)->auth_poll($passwd);
-}
-
-sub voting_has_sign {
-    my ($self, $poll, $user) = @_;
-    $self->poll($poll)->voting_has_sign($user);
-}
-
-# Requete de decompte des voix:
-
-sub vote_results_count {
-    my ($self, $voteid) = @_;
-    $self->results($voteid)->results_count;
-}
-
-sub vote_results_nonull {
-    my ($self, $voteid) = @_;
-    $self->results($voteid)->results_nonull;
-}
-
-sub list_vote_ballot {
-    my ($self, $voteid) = @_;
-    $self->poll($voteid)->list_ballot;
-}
-
-sub list_vote_ballot_needvalid {
-    my ($self, $voteid) = @_;
-    $self->poll($voteid)->list_ballot_needvalid;
-}
-
-sub ballot_info {
-    my ($self, $ballotid) = @_;
-    $self->ballot($ballotid)->info;
-}
-
-sub mark_ballot_invalid {
-    my ($self, $ballotid, $invalid) = @_;
-    $self->ballot($ballotid)->mark_invalid($invalid);
-}
-
-sub ballot_items {
-    my ($self, $ballotid) = @_;
-    $self->ballot($ballotid)->items;
-}
-
-sub vote_ballot_untrusted_values {
-    my ($self, $voteid) = @_;
-    $self->poll($voteid)->ballot_untrusted_values;
-}
-
-sub vote_ballot_values {
-    my ($self, $voteid) = @_;
-    $self->poll($voteid)->ballot_values;
-}
-
-sub vote_map_value {
-    my ($self, $voteid, $from, $to) = @_;
-    $self->poll($voteid)->map_value($from, $to);
-}
-
-sub addupd_voting {
-    my ($self, $voteid, $mail, $id) = @_;
-    $self->poll($voteid)->addupd_voting($mail, $id);
-}
-
-sub delete_voting {
-    my ($self, $key) = @_;
-    # must die, voting are attached to a poll
-    Vote::DB::Voting->new($self->{dbstring}, $key)->has_sign and return;
-    my $sth = $self->db->prepare_cached(
-        q{delete from voting where key = ?}
-    );
-
-    $sth->execute($key);
-}
-
-sub voting_from_file {
-    my ($self, $voteid, $fh, $delete) = @_;
-    $self->poll($voteid)->voting_from_file($fh, $delete);
-}
+sub vote_ballot_count_nonull {die "# old functions" . join(' ',caller());}
+sub auth_voting {die "# old functions" . join(' ',caller());}
+sub auth_poll {die "# old functions" . join(' ',caller());}
+sub voting_has_sign {die "# old functions" . join(' ',caller());}
+sub vote_results_count {die "# old functions" . join(' ',caller());}
+sub vote_results_nonull {die "# old functions" . join(' ',caller());}
+sub list_vote_ballot {die "# old functions" . join(' ',caller());}
+sub list_vote_ballot_needvalid {die "# old functions" . join(' ',caller());}
+sub ballot_info {die "# vote_status" . join(' ',caller());}
+sub mark_ballot_invalid {die "# old functions" . join(' ',caller());}
+sub ballot_items {die "# old functions" . join(' ',caller());}
+sub vote_ballot_untrusted_values {die "# old functions" . join(' ',caller());}
+sub vote_ballot_values {die "# old functions" . join(' ',caller());}
+sub vote_map_value {die "# old functions" . join(' ',caller());}
+sub addupd_voting {die "# old functions" . join(' ',caller());}
+sub delete_voting {die "# old functions" . join(' ',caller());}
+sub voting_from_file {die "# old functions" . join(' ',caller());}
 
 sub clean_old_poll_request {
     my ($self) = @_;
-
     $self->db->do(q{delete from poll_request where "create" < now() - '30 days'::interval});
 }
Index: /trunk/lib/Vote/DB/Poll.pm
===================================================================
--- /trunk/lib/Vote/DB/Poll.pm	(revision 206)
+++ /trunk/lib/Vote/DB/Poll.pm	(revision 207)
@@ -29,4 +29,6 @@
     my ($class, $dbstring, $voteid) = @_;
     
+    $voteid or return;
+
     bless {
         voteid => $voteid,
@@ -135,5 +137,5 @@
     if ($var) {
         if (grep { $var eq $_ } (_online_f(), qw(dstart hstart dend hend))) {
-            return $self->_info->{$var};
+            return ( $self->_info || {} )->{$var};
         } else {
             my $sth = $self->db->prepare_cached(
@@ -276,4 +278,22 @@
 }
 
+sub choices_keys {
+    my ($self) = @_;
+
+    my $sth = $self->db->prepare_cached(
+        q{
+        select key from choice where poll = ?
+        order by label
+        }
+    );
+    $sth->execute($self->voteid);
+    my @ch;
+    while (my $res = $sth->fetchrow_hashref) {
+        push(@ch, $res->{key});
+    }
+    @ch
+}
+
+# TODO: replaced, to kill
 sub choices {
     my ($self) = @_;
@@ -636,5 +656,10 @@
 }
 
+# TODO kill this:
 sub list_ballot {
+    ballot_keys(@_);
+}
+
+sub ballot_keys {
     my ($self) = @_;
 
@@ -796,4 +821,14 @@
     }
     1;
+}
+
+sub delete_voting {
+    my ($self, $key) = @_;
+    $self->voting($key)->has_sign and return;
+    my $sth = $self->db->prepare_cached(
+        q{delete from voting where key = ? and poll = ?}
+    );
+
+    $sth->execute($key, $self->voteid);
 }
 
Index: /trunk/root/latex/poll_report.tt
===================================================================
--- /trunk/root/latex/poll_report.tt	(revision 206)
+++ /trunk/root/latex/poll_report.tt	(revision 207)
@@ -94,6 +94,7 @@
 \subsection{Liste des bulletins}
 
-[% FOREACH id = poll.list_ballot %]
-[% invalid = '#' _ vote.ballot_info(id).invalid %]
+[% FOREACH id = poll.ballot_keys %]
+[%- ballot = poll.ballot(id) -%]
+[% invalid = '#' _ ballot.info.invalid %]
 [% IF loop.first %]
 \begin{enumerate}
@@ -101,5 +102,4 @@
 \item \verb+[% id %]+ [% "\textbf{invalidÃ©}" IF invalid == '#1' %] 
 
-[%- ballot = poll.ballot(id) -%]
 [%- FOREACH item = ballot.items -%]
 [% '\begin{enumerate}' IF loop.first %]
Index: /trunk/root/templates/admin/ballot.tt
===================================================================
--- /trunk/root/templates/admin/ballot.tt	(revision 206)
+++ /trunk/root/templates/admin/ballot.tt	(revision 207)
@@ -3,13 +3,12 @@
 [% vote = c.model('Vote') %]
 [% poll = c.model('Vote').poll(voteid) %]
-[% thisvote = poll.info %]
 
 <div style="float: left; width: 35%" class="box">
 <form action="[% c.uri_for(voteid, 'ballot') %]">
 Nombre de choix possible:
-<input type="text" name="choice_count" value="[% c.req.param('choice_count') || thisvote.choice_count | html %]">
+<input type="text" name="choice_count" value="[% c.req.param('choice_count') || poll.info('choice_count') | html %]">
 <br>
 Nombre de choix libres:
-<input type="text" name="free_choice" value="[% c.req.param('free_choice') || thisvote.free_choice || 0 | html %]">
+<input type="text" name="free_choice" value="[% c.req.param('free_choice') || poll.info('free_choice') || 0 | html %]">
 <br>
 <input type="submit" name="pollparam" value="Enregistrer">
@@ -18,11 +17,12 @@
 <hr>
 
-[% IF ! vote.vote_choices(voteid).size %]
+[% IF ! poll.choices_keys.size %]
 <p class="alert">Aucun choix configurÃ©</p>
 [% ELSE %]
-[% FOREACH choice = vote.vote_choices(voteid) %]
+[% FOREACH choicek = poll.choices_keys %]
+[% choice = poll.choice(choicek) %]
 <form action="[% c.uri_for(voteid, 'ballot') %]" method="POST">
-[% loop.count %] - [% vote.choice_info(choice).label | html %]
-<input type="hidden" name="delch" value="[% vote.choice_info(choice).key %]">
+[% loop.count %] - [% choice.info.label | html %]
+<input type="hidden" name="delch" value="[% choicek %]">
 <input type="submit" name="del" value="Effacer">
 </form>
Index: /trunk/root/templates/admin/includes/ballot_validation.tt
===================================================================
--- /trunk/root/templates/admin/includes/ballot_validation.tt	(revision 206)
+++ /trunk/root/templates/admin/includes/ballot_validation.tt	(revision 207)
@@ -3,5 +3,5 @@
 
 [% IF poll.status == 'AFTER' %]
-[% FOREACH untrusted = vote.vote_ballot_untrusted_values(voteid) %]
+[% FOREACH untrusted = poll.ballot_untrusted_values %]
 [% IF loop.first %]
 <div id="map_ballot">
@@ -16,5 +16,5 @@
     <input type="hidden" name="mapfrom" value="[% untrusted | html %]">
     <select name="mapto">
-    [% FOREACH v = vote.vote_ballot_values(voteid) %]
+    [% FOREACH v = poll.ballot_values %]
         [% NEXT IF v == untrusted %]
         <option>[% v | html %]</options>
@@ -31,5 +31,5 @@
 [% END %]
 
-[% FOREACH bid = vote.list_vote_ballot_needvalid(voteid) %]
+[% FOREACH bid = poll.list_ballot_needvalid(voteid) %]
     [% IF loop.first %]
     <div id="ballot_to_valid">
@@ -41,5 +41,5 @@
 <td>[% bid %]</td>
 <td>
-[% FOREACH item = vote.ballot_items(bid) %]
+[% FOREACH item = poll.ballot(bid).items %]
 [% loop.count %]- [% item.v %]<br>
 [% END %]
Index: /trunk/root/templates/admin/index.tt
===================================================================
--- /trunk/root/templates/admin/index.tt	(revision 206)
+++ /trunk/root/templates/admin/index.tt	(revision 207)
@@ -1,7 +1,7 @@
 [% vote = c.model('Vote') %]
-[% poll = c.model('Vote').poll('voteid') %]
+[% poll = c.model('Vote').poll(voteid) %]
 
 [% FOREACH voteid = c.model('Vote').list_comming_vote %]
-<a href="[% c.uri_for('/admin', voteid) %]">[% c.model('Vote').poll('voteid').info('label') | html %]</a>
+<a href="[% c.uri_for('/admin', voteid) %]">[% poll.info('label') | html %]</a>
 <br>
 [% END %]
Index: /trunk/root/templates/admin/voting.tt
===================================================================
--- /trunk/root/templates/admin/voting.tt	(revision 206)
+++ /trunk/root/templates/admin/voting.tt	(revision 207)
@@ -33,11 +33,10 @@
 <div class="box" style="float: right; width: 60%;">
 
-[% IF NOT vote.vote_voting_count(voteid) %]
+[% IF NOT poll.voting_count %]
 <p class="alert">Aucun votant inscrit</p>
 [% ELSE %]
 
-[% signing = vote.vote_voting(voteid) %]
-
-[% FOREACH thisvoting = signing %]
+[% FOREACH votingkey = poll.voting_keys %]
+[% voting = poll.voting(votingkey) %]
 
 [% IF loop.first %]
@@ -45,18 +44,17 @@
 [% END %]
 
-[% voting = vote.voting_info(thisvoting) %]
 <tr>
 
-[% IF NOT voting.date %]
+[% IF NOT voting.info.date %]
 [% IF poll.status != 'AFTER' %]
 <form action="[% c.uri_for(voteid, 'voting') %]" method="POST">
-<input type="hidden" name="delvoting" value="[% voting.vkey %]">
+<input type="hidden" name="delvoting" value="[% voting.votingkey %]">
 [% END %]
 [% END %]
 
-<td>[% voting.label | html %] [% voting.mail | html %]</td>
-<td>[% IF voting.passwd %]<i>(pass envoyÃ©)</i>[% END %]</td>
+<td>[% voting.label | html %] [% voting.info.mail | html %]</td>
+<td>[% IF voting.info.passwd %]<i>(pass envoyÃ©)</i>[% END %]</td>
 
-[% IF NOT voting.date %]
+[% IF NOT voting.info.date %]
 <td>
 [% IF poll.status != 'AFTER' %]
@@ -66,5 +64,5 @@
 </form>
 [% ELSE %]
-<td>[% voting.date %]</td>
+<td>[% voting.info.date %]</td>
 [% END %]
 
Index: /trunk/root/templates/default.tt
===================================================================
--- /trunk/root/templates/default.tt	(revision 206)
+++ /trunk/root/templates/default.tt	(revision 207)
@@ -47,5 +47,5 @@
 [% END %]
 <tr>
-<td><lu><li><a href="[% c.uri_for( 'vote', id ) %]">[% c.model('Vote').poll(id).info('label') | html %]</a></lu></td></td>
+<td><lu><li><a href="[% c.uri_for( 'vote', id ) %]">[% c.model('Vote').poll(id).info('label') | html %]</a></lu></td>
 </tr>
 [% IF loop.last %]
Index: /trunk/root/templates/includes/ballot_form.tt
===================================================================
--- /trunk/root/templates/includes/ballot_form.tt	(revision 206)
+++ /trunk/root/templates/includes/ballot_form.tt	(revision 207)
@@ -1,4 +1,3 @@
 [% poll = c.model('Vote').poll(voteid) %]
-[% thisvote = poll.info() %]
 
 <!-- $Id$ -->
@@ -10,5 +9,5 @@
 
 [% count = 0 %]
-[% WHILE count < thisvote.free_choice %]
+[% WHILE count < poll.info('free_choice') %]
 <input type="text" name="fsbal" value="[% fsbal.$count %]"><br>
 [% count = count + 1 %]
Index: /trunk/root/templates/includes/poll_results.tt
===================================================================
--- /trunk/root/templates/includes/poll_results.tt	(revision 206)
+++ /trunk/root/templates/includes/poll_results.tt	(revision 207)
@@ -1,4 +1,4 @@
 [% vote = c.model('Vote') %]
-[% poll = c.model('Vote').poll(voteid) %]
+[% poll = c.model('Vote').results(voteid) %]
 
 [% IF poll.can_show_result %]
@@ -8,5 +8,5 @@
 <a href="[% c.uri_for('/vote', voteid, 'report.pdf') %]">Rapport en PDF</a>
 </div>
-[% IF vote.list_vote_ballot_needvalid(voteid).size %]
+[% IF poll.list_ballot_needvalid.size %]
 <p>Resultats provisoires:</p>
 <p class="alert">Le gestionnaire doit vÃ©rifier la validitÃ© de certains bulletins</p>
@@ -15,16 +15,16 @@
 [% END %]
 <p>Nombre de choix Ã  retenir: [% poll.info('choice_count') %]</p>
-<p>Participations: [% vote.vote_signing_count(voteid) %] / [% vote.vote_voting_count(voteid) %]
-[% IF vote.vote_voting_count(voteid) %]
-([% vote.vote_signing_count(voteid) * 100 / vote.vote_voting_count(voteid) | format('%.2f') %])
+<p>Participations: [% poll.signing_count %] / [% poll.voting_count %]
+[% IF poll.voting_count %]
+([% poll.signing_count * 100 / poll.voting_count(voteid) | format('%.2f') %])
 [% END %]</p>
-<p>Nombre de vote(s) exprimÃ©(s): [% vote.vote_ballot_count_nonull(voteid) %]
-[% IF vote.vote_ballot_count(voteid) %]
-([% vote.vote_ballot_count_nonull(voteid) * 100 / vote.vote_ballot_count(voteid) | format('%.2f') %]%)
+<p>Nombre de vote(s) exprimÃ©(s): [% poll.ballot_count_nonull %]
+[% IF poll.ballot_count(voteid) %]
+([% poll.ballot_count_nonull * 100 / poll.ballot_count | format('%.2f') %]%)
 [% END %]
 </p>
 
-[% IF vote.vote_ballot_count_nonull(voteid) %]
-[% FOREACH res = vote.vote_results_nonull(voteid) %]
+[% IF poll.ballot_count_nonull %]
+[% FOREACH res = poll.results_nonull %]
 [% IF loop.first %]
 <p>Score:</p>
@@ -43,5 +43,5 @@
 [% mycount = loop.count %]
 [% IF loop.count <= poll.info('choice_count') %]
-[% IF res.count >= vote.absolute_majority %]
+[% IF res.count >= poll.absolute_majority %]
 [% class = 'majabs' %]
 [% ELSE %]
@@ -57,7 +57,7 @@
 <td>[% res.value | html %]</td>
 <td>[% res.count %]</td>
-<td>[% res.count * 100 / vote.ballot_count_nonull(voteid) | format('%.2f') %]</td>
+<td>[% res.count * 100 / poll.ballot_count_nonull | format('%.2f') %]</td>
 <td><img src="[% c.uri_for('/static', 'images', 'green-v.png') %]" 
-height="10px" width="[% res.count * 400 / vote.ballot_count_nonull(voteid) | format('%d') %]px"></td>
+height="10px" width="[% res.count * 400 / poll.ballot_count_nonull(voteid) | format('%d') %]px"></td>
 </tr>
 
@@ -71,5 +71,5 @@
 </div>
 
-[% FOREACH id = vote.list_vote_ballot(voteid) %]
+[% FOREACH id = poll.ballot_keys %]
 [% IF loop.first %]
 <div id="ballot_list" class="box">
@@ -87,5 +87,5 @@
 <td>[% id | html %]</td>
 <td>
-[% items = vote.ballot_items(id) %]
+[% items = poll.ballot(id).items %]
 [% IF items.size %]
 [% FOREACH item = items %]
@@ -101,5 +101,5 @@
 </td>
 <td>
-[% invalid = '#' _ vote.ballot_info(id).invalid %]
+[% invalid = '#' _ poll.ballot(id).info.invalid %]
 [% IF invalid == '#1' %]
 <span class="alert">InvalidÃ©</span>
