]> projects.mako.cc - selectricity/commitdiff
Added initial support fo QuickVotes. There is support for the creation
author<mako@atdot.cc> <>
Wed, 11 Oct 2006 05:34:23 +0000 (01:34 -0400)
committer<mako@atdot.cc> <>
Wed, 11 Oct 2006 05:34:23 +0000 (01:34 -0400)
of quickvotes in the database. There is not yet support for voting in
quickvotes.

app/controllers/election_controller.rb
app/controllers/site_controller.rb
app/models/candidate.rb
app/models/quick_vote.rb [new file with mode: 0644]
app/views/layouts/vb.rhtml
app/views/site/create_quickvote.rhtml [new file with mode: 0644]
app/views/site/index.rhtml
app/views/site/success_quickvote.rhtml [new file with mode: 0644]
db/migrate/001_create_quick_votes.rb [new file with mode: 0644]
test/fixtures/quick_votes.yml [new file with mode: 0644]
test/unit/quick_vote_test.rb [new file with mode: 0644]

index 46da56ef784379d7fa87d0e7e59327e73f45ed01..7e8273efcf5048ed4874eef2b90edd41a1e50364 100644 (file)
@@ -54,8 +54,6 @@ class ElectionController < ApplicationController
     @election.voters.each do |voter|
       email = VoterNotify.create_votestart(voter)
       render(:text => "<pre>" + email.encoded + "</pre>")
-      breakpoint
-      break
     end
 
     #@election.activate!
index f2eb15343aa35cae5f29e85fde40e016b805f491..f4bae4287126e05488dbd76af1d11e2114ecdb33 100644 (file)
@@ -10,4 +10,15 @@ class SiteController < ApplicationController
       end
     end
   end
+
+  def create_quickvote
+    if params[:quickvote] 
+      @quickvote = QuickVote.new(params[:quickvote])
+      if @quickvote.reviewed? and @quickvote.save
+          @quickvote = @quickvote.reload
+         render :action => 'success_quickvote'
+      end 
+    end
+  end
+
 end
index 7b6e8024a52bb30bfa1dbb57f80167426cf51502..430b6ab22762223a728eaf6cc27bb3d51f7b8d2e 100644 (file)
@@ -1,8 +1,9 @@
 class Candidate < ActiveRecord::Base
   belongs_to :election
-  validates_uniqueness_of :name
   validates_presence_of :name
 
+  # validate uniqueness of a name *within a given election*
+
   def <=>(other)
     self.name <=> other.name 
   end
diff --git a/app/models/quick_vote.rb b/app/models/quick_vote.rb
new file mode 100644 (file)
index 0000000..d6ab55b
--- /dev/null
@@ -0,0 +1,51 @@
+class QuickVote < Election
+  after_validation :create_candidates
+  validates_uniqueness_of :name
+  attr_accessor :raw_candidates
+  attr_accessor :reviewed
+
+  def validate
+    if @raw_candidates.length < 2
+      errors.add("You must list at least two candidates.")
+    end
+
+    if name =~ /[^A-Za-z0-9]/
+      errors.add("The name must only include numbers and letters.")
+    end
+  end
+  
+  def initialize(params={})
+    super
+    self.enddate =  DateTime.now + 30
+    self.active = 1
+    self.anonymous = 1
+  end
+
+  def candidatelist=(candstring='')
+    @raw_candidates = candstring.split(';').collect {|cand| cand.strip }
+  end
+
+  def candidatelist
+    @raw_candidates.join("; ")
+  end
+
+  def name
+    read_attribute( :name ).downcase()
+  end
+
+  def reviewed?
+    if reviewed.to_i == 1
+      return true
+    else
+      false
+    end
+  end
+
+  def create_candidates
+    @raw_candidates.each do |name|
+      candidate = Candidate.new({:name => name})
+      candidate.save
+      self.candidates << candidate
+    end
+  end
+end
index a05ae54ae56ab732d20e0ebd9df331b8bc935841..3e4f8bdffcff360a0f2dd62e73379d982decfa6f 100644 (file)
@@ -1,7 +1,7 @@
 <% %>
 <html>
     <head>
-        <title><%= @page_title || "VotingBooth" %></title>
+        <title><%= @page_title || "HyperChad" %></title>
         <%= stylesheet_link_tag "vb", :media => "all" %>
         <% #engine_stylesheet 'login_engine' %>
  
@@ -12,8 +12,8 @@
            <% if @page_title %>
               <h3><%= @page_title %></h3>  
            <% else %>
-             <h3>Voting Booth<br />
-             <font size="-1">Preferential Voting on the Web</font></h3>
+             <h3>HyperChad<br />
+             <font size="-1">Voting Machinery for the Masses</font></h3>
           <% end %>
 
            <div id="links">
@@ -41,7 +41,7 @@
         </div>
 
        <hr />
-        <div id="footer">(C) 2006 |
+        <div id="footer">Copyleft 2006 |
          <%= link_to "MIT Media Lab", "http://www.media.mit.edu" %> and
          <a href="http://mako.cc">Benjamin Mako Hill</a>
        </div>
diff --git a/app/views/site/create_quickvote.rhtml b/app/views/site/create_quickvote.rhtml
new file mode 100644 (file)
index 0000000..78addaa
--- /dev/null
@@ -0,0 +1,46 @@
+<% -%>
+<h1>Create QuickVote</h1>
+
+<%= error_messages_for 'quickvote' %>
+
+<% if @quickvote %>
+<p>Please review the data you've entered and confirm. The candidates for
+the election submitted include:</p>
+
+<ul>
+<% for candidate in @quickvote.raw_candidates %>
+  <li><%= candidate %></li>
+<% end %>
+</ul>
+
+<% end %>
+
+<%= form_tag :action => 'create_quickvote' %>
+<!--[form:election]-->
+
+<p><label for="quickvote_name">Vote Name<br />
+
+<em><font size="-1">Required; 5-12 characters; only letters and numbers; no spaces</font></em></label><br/>
+
+<%= text_field 'quickvote', 'name'  %></p>
+
+<p><label for="quickvote_description">Description <em><font
+size="-1">Optional</font></em></label><br/>
+
+<%= text_area 'quickvote', 'description', :rows => 2 %></p>
+
+<p><label for="quickvote_candidatelist">Choices/Candidates<em><br />
+<font size="-1">Seperate choices with a ";". At least two are required.</font></em></label><br/>
+
+<%= text_area 'quickvote', 'candidatelist', :rows => 3 %></p>
+
+<p><% if @quickvote -%>
+     <%= submit_tag "Confirm" -%>
+     <%= hidden_field :quickvote, :reviewed, :value => 1 %>
+   <% else %>
+     <%= submit_tag "Create QuickVote" -%>
+   <%- end -%>
+</p>
+
+<%= end_form_tag %>
+
index 2e4240e2c3e80a3396336329f65d38e41515515d..5a68a6b77237ebe9c91a5eb687c7b935025c95e5 100644 (file)
@@ -3,6 +3,17 @@
 <table width="auto" padding="5px">
 <tr>
 <td width="47%" valign="top">
+
+<h2>QuickVotes</h2>
+
+<p><em>QuickVotes</em> are unstructured votes, more like polls, without
+the voter verifiability, anonymity, and other more complex features of
+HyperChad. They are the quickest way to make a decision using a variety
+of preferential and non-preficial election methods, or to compare
+between methods.</p>
+
+<p><%= link_to "Create QuickVote.", :action => 'create_quickvote' %></p>
+
 <h2>Voters</h2>
 
 <p>If you have received an email with a token inviting you to vote in an
diff --git a/app/views/site/success_quickvote.rhtml b/app/views/site/success_quickvote.rhtml
new file mode 100644 (file)
index 0000000..654e6d3
--- /dev/null
@@ -0,0 +1,15 @@
+<% %>
+
+<p>Vote Created</p>
+
+<p>You have successfully created a QuickVote.</p>
+
+<p>QuickVotes are open to the public but are not publicly listed on the
+HyperChad site. Voters do not need to log in or authenticate to
+participate in this election.</p>
+
+<p>Direct voters to:</p>
+<blockquote><strong><%= url_for :action => 'quickvote', :id => @quickvote.id, :only_path => false %></strong></blockquote>
+
+<p>This vote will expire on <em><%= @quickvote.enddate %></em></p>
+
diff --git a/db/migrate/001_create_quick_votes.rb b/db/migrate/001_create_quick_votes.rb
new file mode 100644 (file)
index 0000000..a96c110
--- /dev/null
@@ -0,0 +1,11 @@
+class CreateQuickVotes < ActiveRecord::Migration
+  def self.up
+    create_table :quick_votes do |t|
+      # t.column :name, :string
+    end
+  end
+
+  def self.down
+    drop_table :quick_votes
+  end
+end
diff --git a/test/fixtures/quick_votes.yml b/test/fixtures/quick_votes.yml
new file mode 100644 (file)
index 0000000..8794d28
--- /dev/null
@@ -0,0 +1,5 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+first:
+  id: 1
+another:
+  id: 2
diff --git a/test/unit/quick_vote_test.rb b/test/unit/quick_vote_test.rb
new file mode 100644 (file)
index 0000000..5846db2
--- /dev/null
@@ -0,0 +1,10 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class QuickVoteTest < Test::Unit::TestCase
+  fixtures :quick_votes
+
+  # Replace this with your real tests.
+  def test_truth
+    assert true
+  end
+end

Benjamin Mako Hill || Want to submit a patch?