From: Date: Wed, 11 Oct 2006 05:34:23 +0000 (-0400) Subject: Added initial support fo QuickVotes. There is support for the creation X-Git-Url: https://projects.mako.cc/source/selectricity-live/commitdiff_plain/d207da8dfc3f315f7758d1f5307c700ce4c25156?ds=sidebyside;hp=fd484b33a3920e0031007c5c2f1dec61913cbab5 Added initial support fo QuickVotes. There is support for the creation of quickvotes in the database. There is not yet support for voting in quickvotes. --- diff --git a/app/controllers/election_controller.rb b/app/controllers/election_controller.rb index 46da56e..7e8273e 100644 --- a/app/controllers/election_controller.rb +++ b/app/controllers/election_controller.rb @@ -54,8 +54,6 @@ class ElectionController < ApplicationController @election.voters.each do |voter| email = VoterNotify.create_votestart(voter) render(:text => "
" + email.encoded + "
") - breakpoint - break end #@election.activate! diff --git a/app/controllers/site_controller.rb b/app/controllers/site_controller.rb index f2eb153..f4bae42 100644 --- a/app/controllers/site_controller.rb +++ b/app/controllers/site_controller.rb @@ -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 diff --git a/app/models/candidate.rb b/app/models/candidate.rb index 7b6e802..430b6ab 100644 --- a/app/models/candidate.rb +++ b/app/models/candidate.rb @@ -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 index 0000000..d6ab55b --- /dev/null +++ b/app/models/quick_vote.rb @@ -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 diff --git a/app/views/layouts/vb.rhtml b/app/views/layouts/vb.rhtml index a05ae54..3e4f8bd 100644 --- a/app/views/layouts/vb.rhtml +++ b/app/views/layouts/vb.rhtml @@ -1,7 +1,7 @@ <% %> - <%= @page_title || "VotingBooth" %> + <%= @page_title || "HyperChad" %> <%= stylesheet_link_tag "vb", :media => "all" %> <% #engine_stylesheet 'login_engine' %> @@ -12,8 +12,8 @@ <% if @page_title %>

<%= @page_title %>

<% else %> -

Voting Booth
- Preferential Voting on the Web

+

HyperChad
+ Voting Machinery for the Masses

<% end %>
-