Skip to content
Browse files

add slating functionality

  • Loading branch information...
1 parent e983625 commit c9aaf46c650532fd292af7fc8b5a2108e2a2e8c3 @leibovic committed Oct 15, 2011
View
47 static/css/style.css
@@ -161,7 +161,6 @@ h1, h2, h3, h4, h5, h6 { font-weight: bold; }
a, a:active, a:visited { color: #495c23; }
a:hover { color: #bc4956; }
-
/**
* Primary styles
*
@@ -424,12 +423,33 @@ img {
padding: 3px;
}
-.form-submit {
+.error {
+ color: #bc4956;
+}
+
+input[type="submit"] {
margin-top: 10px;
+ padding: 5px 10px;
+ background: #ECECEC;
+ border: 1px solid #D4D4D4;
+ border-radius: 3px;
+ font-size: 1em;
+ font-weight: bold;
+ color: #333;
+ text-shadow: 1px 1px 0 #fff;
+ cursor: pointer;
+}
+
+input[type="submit"]:hover {
+ background: #9ca275;
+ border-color: #9ca275;
+ box-shadow: inset 2px 2px 3px rgba(255,255,255,0.3);
+ color: #fff;
+ text-shadow: -1px -1px 0 rgba(0,0,0,0.3);
}
-.error {
- color: #bc4956;
+input[type="submit"]:hover:active {
+ box-shadow: inset -2px -2px 3px rgba(255,255,255,0.3);
}
/* sisters only */
@@ -504,6 +524,25 @@ img {
width: 120px;
}
+.slating-select-container {
+ margin-top: 10px;
+ padding: 10px 20px;
+ background-color: #9ca275;
+ border-radius: 4px;
+}
+
+.slating-select-container > p {
+ color: #fff;
+}
+
+.slating-select-container > select {
+ margin-right: 10px;
+}
+
+.slating-results-table td {
+ padding: 5px 10px 5px 0;
+}
+
/**
* Non-semantic helper classes: please define your styles before this section.
*/
View
1 urls.py
@@ -30,6 +30,7 @@
url(r'^sistersonly/elections/loi/$', 'website.views.sistersonly_elections_loi'),
url(r'^sistersonly/elections/loi/results/$', 'website.views.sistersonly_elections_loi_results'),
url(r'^sistersonly/elections/slating/$', 'website.views.sistersonly_elections_slating'),
+ url(r'^sistersonly/elections/slating/results/$', 'website.views.sistersonly_elections_slating_results'),
# Uncomment the admin/doc line below to enable admin documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
View
10 website/templates/sistersonly/base.html
@@ -5,7 +5,15 @@
<!-- location attribute is the path stripped of '/' (used to indicate current page)-->
<li location="sistersonlyevents"><a href="/sistersonly/events/">Events</a></li>
<li location="sistersonlydirectory"><a href="/sistersonly/directory/">Directory</a></li>
- <li location="sistersonlyelections"><a href="/sistersonly/elections/">Elections</a></li>
+ <li location="sistersonlyelections">
+ <a href="/sistersonly/elections/">Elections</a>
+ <ul class="dropdown">
+ <li><a href="/sistersonly/elections/ois/">OIS Submission</a></li>
+ <li><a href="/sistersonly/elections/loi/">LOI Submission</a></li>
+ <li><a href="/sistersonly/elections/loi/results/">Submitted LOIs</a></li>
+ <li><a href="/sistersonly/elections/slating/">Slating</a></li>
+ </ul>
+ </li>
<li location="sistersonlyfeedback"><a href="/sistersonly/feedback/">Feedback</a></li>
<li location="sistersonlyresources">
<a href="/sistersonly/resources/">AXΩ Resources</a>
View
2 website/templates/sistersonly/elections_loi.html
@@ -13,7 +13,7 @@ <h2 class="error">Sorry, there was a problem submitting your LOI. Please make su
{% endif %}
{% if success %}
- <h2 class="success">Your LOI was submitted sucessfully!</a></h2>
+ <p>Your LOI was submitted sucessfully!</p>
{% endif %}
<form method="post" action="">
View
16 website/templates/sistersonly/elections_loi_results.html
@@ -5,22 +5,22 @@
{% block main %}
-{% regroup candidates|dictsort:"sort_rank" by office as candidate_list %}
+{% regroup candidates|dictsort:"sort_rank" by office as office_list %}
<div class="content">
{% if loi_results_open %}
<p>For your reference, all the submitted LOIs are available below. <a href="/sistersonly/elections/slating">Slating</a> will happen in chapter on Sunday, October 16.</p>
- {% for candidate in candidate_list %}
- <h2 class="loi-results-office">{{ candidate.grouper }}</h2>
- <p class="loi-results-office-description">{{ candidate.grouper.description }}</h2>
+ {% for office in office_list %}
+ <h2 class="loi-results-office">{{ office.grouper }}</h2>
+ <p class="loi-results-office-description">{{ office.grouper.description }}</h2>
<table class="loi-results-table">
- {% for item in candidate.list %}
+ {% for candidate in office.list %}
<tr>
<td class="loi-results-sister">
- <a href="/sisters/{{ item.sister.id }}">{{ item.sister }}</a>
- <img class="loi-results-photo" src="http://axo.scripts.mit.edu/{{ item.sister.photo_url }}"/>
+ <a href="/sisters/{{ candidate.sister.id }}">{{ candidate.sister }}</a>
+ <img class="loi-results-photo" src="http://axo.scripts.mit.edu/{{ candidate.sister.photo_url }}"/>
</td>
- <td>{{ item.loi|linebreaksbr }}</td>
+ <td>{{ candidate.loi|linebreaksbr }}</td>
</tr>
{% endfor %}
</table>
View
57 website/templates/sistersonly/elections_slating.html
@@ -3,16 +3,63 @@
{% block title %}Slating &ndash; {% endblock %}
{% block main %}
+
<div class="content">
<h1>Slating</h1>
{% if loi_closed %}
<p>Sorry, slating is closed now!</p>
{% else %}
- <form method="post" action="">
- {% csrf_token %}
- <p>Slating coming soon!</p>
- <!--input class="form-submit" type="submit" value="Submit slate choices"/-->
- </form>
+ {% if success %}
+ <p>{{ debug }}</p>
+ <p>Thanks for slating! Your choices were submitted successfully.</p>
+ {% else %}
+ {% if already_voted %}
+ <p>It looks like you already voted, so there's nothing else you need to do here!</p>
+ {% else %}
+
+ {% regroup candidates|dictsort:"sort_rank" by office as office_list %}
+ <p>Choose your two favorite candidates for each office below. You can't change your choices once this page is submitted, so choose wisely!</p>
+ <form method="post" action="">
+ {% csrf_token %}
+
+ {% for office in office_list %}
+ <h2 class="loi-results-office">{{ office.grouper }}</h2>
+ <p class="loi-results-office-description">{{ office.grouper.description }}</h2>
+ <table class="loi-results-table">
+ {% for candidate in office.list %}
+ <tr>
+ <td class="loi-results-sister">
+ <a href="/sisters/{{ candidate.sister.id }}">{{ candidate.sister }}</a>
+ <img class="loi-results-photo" src="http://axo.scripts.mit.edu/{{ candidate.sister.photo_url }}"/>
+ </td>
+ <td>{{ candidate.loi|linebreaksbr }}</td>
+ </tr>
+ {% endfor %}
+ </table>
+
+ <div class="slating-select-container">
+ <p>Select your two favorite candidates for <strong>{{ office.grouper }}</strong>.</p>
+ <select name="{{ office.grouper.id }}-1">
+ <option value="">Abstain</option>
+ {% for candidate in office.list %}
+ <option value="{{ candidate.id }}">{{ candidate.sister }}</option>
+ {% endfor %}
+ </select>
+ <select name="{{ office.grouper.id }}-2">
+ <option value="">Abstain</option>
+ {% for candidate in office.list %}
+ <option value="{{ candidate.id }}">{{ candidate.sister }}</option>
+ {% endfor %}
+ </select>
+ <p style="font-style:italic;text-align:right;">A second vote for the same candidate will not be counted.</p>
+ </div>
+
+ {% endfor %}
+
+ <input id="slate-submit-button" type="submit" value="Submit slate choices"/>
+ </form>
+ {% endif %}
+ {% endif %}
{% endif %}
</div>
{% endblock %}
View
28 website/templates/sistersonly/elections_slating_results.html
@@ -0,0 +1,28 @@
+{% extends "sistersonly/base.html" %}
+{% load website_extras %}
+
+{% block title %}Slating Results &ndash; {% endblock %}
+
+{% block main %}
+<div class="content">
+ <h1>Slating Results</h1>
+ {% if can_view %}
+
+ {% for result in results %}
+ <h2 class="loi-results-office">{{ result.office }}</h2>
+ <table class="slating-results-table">
+ {% for vote in result.votes %}
+ <tr>
+ <td>{{ vote.candidate__count }}</td>
+ <td>{{ vote.candidate }}</td>
+ </tr>
+ {% endfor %}
+ </table>
+ {% endfor %}
+
+ </table>
+ {% else %}
+ <p>Sorry, you don't have permission to view this page.</p>
+ {% endif %}
+</div>
+{% endblock %}
View
54 website/views.py
@@ -6,6 +6,7 @@
from django.core.mail import send_mail
from django.template import RequestContext
from django.conf import settings
+from django.db.models import Count
def get_context(request):
context = {}
@@ -182,20 +183,61 @@ def sistersonly_elections_loi_results(request):
@login_required
def sistersonly_elections_slating(request):
context = get_context(request)
- try:
+ try: # Check to make sure slating is open
slating_open = settings.SLATING_OPEN
except:
pass
if not slating_open:
context['slating_closed'] = True
return render_to_response('sistersonly/elections_slating.html', RequestContext(request, context))
- candidates = Candidate.objects.all()
+ # Check to make sure the user hasn't already voted
+ voting_sister = context['sister']
+ existing_votes = Vote.objects.filter(sister=voting_sister)
+ if len(existing_votes) > 0:
+ context['already_voted'] = True
+ return render_to_response('sistersonly/elections_slating.html', RequestContext(request, context))
+
if request.method == 'POST':
- # TODO: submit voting form
+ offices = Office.objects.filter(is_exec=True)
+ for office in offices:
+ try: # Get the first candidate choice
+ candidate1 = Candidate.objects.get(id=request.POST[str(office.id)+"-1"])
+ vote1 = Vote(office=office, candidate=candidate1, sister=voting_sister)
+ vote1.save()
+ except:
+ pass
+
+ try: # Get the second candidate choice
+ candidate2 = Candidate.objects.get(id=request.POST[str(office.id)+"-2"])
+ if candidate1.id is not candidate2.id:
+ vote2 = Vote(office=office, candidate=candidate2, sister=voting_sister)
+ vote2.save()
+ except:
+ pass
+
context['success'] = True
else:
- # TODO: make voting form
- pass
+ context['candidates'] = Candidate.objects.all()
- return render_to_response('sistersonly/elections_slating.html', RequestContext(request, context))
+ return render_to_response('sistersonly/elections_slating.html', RequestContext(request, context))
+
+@login_required
+def sistersonly_elections_slating_results(request):
+ context = get_context(request)
+ # TODO: This should be done in the template, and with a more specific permission group
+ context['can_view'] = request.user.is_staff
+
+ results = []
+ offices = Office.objects.filter(is_exec=True).order_by('chain_of_command').order_by('title').reverse()
+ for office in offices:
+ # Count the number of votes for each candidate
+ # Example: votes = [{'candidate__count': 2, 'candidate': 1}, ... ]
+ votes = Vote.objects.filter(office=office).values('candidate').order_by().annotate(Count('candidate'))
+ for vote in votes:
+ vote['candidate'] = Candidate.objects.get(id=vote['candidate']).sister
+ results.append({ 'office': office, 'votes': votes })
+
+ context['results'] = results
+
+ return render_to_response('sistersonly/elections_slating_results.html', context)

0 comments on commit c9aaf46

Please sign in to comment.
Something went wrong with that request. Please try again.