Index: openacs-4/packages/oct-election/oct-election.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/oct-election/oct-election.info,v diff -u -r1.2 -r1.3 --- openacs-4/packages/oct-election/oct-election.info 14 May 2005 20:25:01 -0000 1.2 +++ openacs-4/packages/oct-election/oct-election.info 14 May 2005 23:16:28 -0000 1.3 @@ -8,7 +8,7 @@ <singleton-p>f</singleton-p> <auto-mount>oct-election</auto-mount> - <version name="0.2" url="http://openacs.org/repository/download/apm/oct-election-0.2.apm"> + <version name="1.0" url="http://openacs.org/repository/download/apm/oct-election-1.0.apm"> <owner url="mailto:joel@aufrecht.org">Joel Aufrecht</owner> <summary>Web app for voting in OCT elections.</summary> Index: openacs-4/packages/oct-election/www/candidate-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/oct-election/www/candidate-delete.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/oct-election/www/candidate-delete.tcl 14 May 2005 19:49:49 -0000 1.1 +++ openacs-4/packages/oct-election/www/candidate-delete.tcl 14 May 2005 23:16:28 -0000 1.2 @@ -6,7 +6,7 @@ } auth::require_login -permission::require_permission -object_id [ad_conn package_id] -privilege create +permission::require_permission -object_id [ad_conn package_id] -privilege admin db_dml candidate_delete { delete from oct_candidate Index: openacs-4/packages/oct-election/www/election-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/oct-election/www/election-edit.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/oct-election/www/election-edit.tcl 14 May 2005 19:49:49 -0000 1.1 +++ openacs-4/packages/oct-election/www/election-edit.tcl 14 May 2005 23:16:28 -0000 1.2 @@ -4,9 +4,11 @@ election_id:integer,optional } +permission::require_permission -object_id [ad_conn package_id] -privilege admin set page_title "Editing Election" set context [list $page_title] + ad_form -name election -form { {election_id:key} {label:text {label Election}} @@ -21,16 +23,17 @@ set context [list $page_title] } -edit_request { auth::require_login - permission::require_write_permission -object_id $election_id + # this permission check is a lazy workaround for not having elections as real objects + permission::require_write_permission -object_id [ad_conn package_id] db_1row get_election { select start_time, - end_time, - label, - vote_forum_cutoff, - number_of_candidates - from oct_election - where election_id = :election_id; + end_time, + label, + vote_forum_cutoff, + number_of_candidates + from oct_election + where election_id = :election_id; } set page_title "Edit $label" set context [list $page_title] Index: openacs-4/packages/oct-election/www/election.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/oct-election/www/election.adp,v diff -u -r1.1 -r1.2 --- openacs-4/packages/oct-election/www/election.adp 14 May 2005 19:49:49 -0000 1.1 +++ openacs-4/packages/oct-election/www/election.adp 14 May 2005 23:16:28 -0000 1.2 @@ -3,12 +3,17 @@ <property name="context">@context;noquote@</property> <p>Election: @label@ +<p>Number of winners possible: @number_of_candidates@ <p>Start time: @start_time@ <p>End time: @end_time@ -<p>Label: @label@ +<p>Forum cutoff date: @vote_forum_cutoff@ +<p>Ballots: @ballot_count@ +<if @admin_p@> +<p> <a href="election-edit?election_id=@election_id@">Edit</a></p> +</if> <h2>Candidates</h2> <listtemplate name="candidates"></listtemplate> -<if @admin_p@> +<if @admin_p@ and @past_start_p@ ne 1> <p> <form action="candidate-add"> <input type="hidden" name="election_id" value="@election_id@"/> Index: openacs-4/packages/oct-election/www/election.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/oct-election/www/election.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/oct-election/www/election.tcl 14 May 2005 20:25:01 -0000 1.2 +++ openacs-4/packages/oct-election/www/election.tcl 14 May 2005 23:16:28 -0000 1.3 @@ -5,7 +5,7 @@ } set user_id [auth::require_login] -set admin_p [acs_user::site_wide_admin_p] +set admin_p [permission::permission_p -object_id [ad_conn package_id] -privilege create] set valid_voter [oct-election::valid_voter_p -election_id $election_id -user_id $user_id] set valid_voter_p [lindex $valid_voter 0] set valid_voter_text [lindex $valid_voter 1] @@ -14,11 +14,20 @@ select start_time, end_time, vote_forum_cutoff, - label + number_of_candidates, + label, + (case when now() > start_time then 1 else 0 end) as past_start_p, + (case when now() > end_time then 1 else 0 end) as past_end_p from oct_election where election_id = :election_id } +set ballot_count [db_string get_ballot_count { + select count(*) + from oct_ballot + where election_id = :election_id; +}] + set page_title $label set context $page_title @@ -31,40 +40,51 @@ } delete { link_url_col delete_url - display_template { - <img src="/resources/acs-subsite/Delete16.gif" width="16" height="16" border="0"> - } + display_template " + <if $admin_p and $past_start_p ne 1> + <img src=\"/resources/acs-subsite/Delete16.gif\" width=\"16\" height=\"16\" border=\"0\"> + </if> + " sub_class narrow } count { - label "Count" + label "Votes" } } +if {$past_end_p} { + set order_clause "order by label" +} else { + set order_clause "order by cand_count desc" +} + db_multirow \ -extend { delete_url count - } candidates candidates_select { + } candidates candidates_select " select oc.candidate_id, oc.label as candidate_label, count(ov.candidate_id) as cand_count from oct_candidate oc left outer join oct_vote ov using (candidate_id) where oc.election = :election_id group by oc.candidate_id, oc.label - } { + $order_clause + " { set delete_url [export_vars -base "candidate-delete" {candidate_id election_id}] - if {} { + if {$past_end_p} { set count $cand_count } else { set count "Results pending" } } -#TODO: show vote total if election is over #TODO: hide delete button if not admin #TODO: sort candidates by vote total if election is over, or alpha if not +#DEBUG +db_1row get_now { + select now() as now + from dual; +} - - Index: openacs-4/packages/oct-election/www/index.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/oct-election/www/index.adp,v diff -u -r1.1 -r1.2 --- openacs-4/packages/oct-election/www/index.adp 14 May 2005 19:49:49 -0000 1.1 +++ openacs-4/packages/oct-election/www/index.adp 14 May 2005 23:16:28 -0000 1.2 @@ -1,6 +1,6 @@ <master> <property name="title">@page_title;noquote@</property> - <property name="context">@context;noquote@</property> + <property name="context">"@context;noquote@"</property> <listtemplate name="elections"></listtemplate> <if @admin_p@> Index: openacs-4/packages/oct-election/www/index.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/oct-election/www/index.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/oct-election/www/index.tcl 14 May 2005 19:49:49 -0000 1.1 +++ openacs-4/packages/oct-election/www/index.tcl 14 May 2005 23:16:28 -0000 1.2 @@ -5,7 +5,7 @@ set page_title "OCT Elections" set context $page_title -set admin_p [acs_user::site_wide_admin_p] +set admin_p [permission::permission_p -object_id [ad_conn package_id] -privilege create] template::list::create \ -name elections \