diff --git a/core/static/core/js/shorten.min.js b/core/static/core/js/shorten.min.js new file mode 100644 index 00000000..5e79d040 --- /dev/null +++ b/core/static/core/js/shorten.min.js @@ -0,0 +1,22 @@ +// Copyright 2013 Viral Patel and other contributors +// http://viralpatel.net + +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: + +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +!function(e){e.fn.shorten=function(s){"use strict";var t={showChars:100,minHideChars:10,ellipsesText:"...",moreText:"more",lessText:"less",onLess:function(){},onMore:function(){},errMsg:null,force:!1};return s&&e.extend(t,s),e(this).data("jquery.shorten")&&!t.force?!1:(e(this).data("jquery.shorten",!0),e(document).off("click",".morelink"),e(document).on({click:function(){var s=e(this);return s.hasClass("less")?(s.removeClass("less"),s.html(t.moreText),s.parent().prev().animate({height:"0%"},function(){s.parent().prev().prev().show()}).hide("fast",function(){t.onLess()})):(s.addClass("less"),s.html(t.lessText),s.parent().prev().animate({height:"100%"},function(){s.parent().prev().prev().hide()}).show("fast",function(){t.onMore()})),!1}},".morelink"),this.each(function(){var s=e(this),n=s.html(),r=s.text().length;if(r>t.showChars+t.minHideChars){var o=n.substr(0,t.showChars);if(o.indexOf("<")>=0){for(var a=!1,i="",h=0,l=[],c=null,f=0,u=0;u<=t.showChars;f++)if("<"!=n[f]||a||(a=!0,c=n.substring(f+1,n.indexOf(">",f)),"/"==c[0]?c!="/"+l[0]?t.errMsg="ERROR en HTML: the top of the stack should be the tag that closes":l.shift():"br"!=c.toLowerCase()&&l.unshift(c)),a&&">"==n[f]&&(a=!1),a)i+=n.charAt(f);else if(u++,h<=t.showChars)i+=n.charAt(f),h++;else if(l.length>0){for(j=0;j";break}o=e("
").html(i+''+t.ellipsesText+"").html()}else o+=t.ellipsesText;var m='
'+o+'
'+n+'
'+t.moreText+"";s.html(m),s.find(".allcontent").hide(),e(".shortcontent p:last",s).css("margin-bottom",0)}}))}}(jQuery); diff --git a/election/migrations/0003_auto_20171202_1819.py b/election/migrations/0003_auto_20171202_1819.py new file mode 100644 index 00000000..ef7868d6 --- /dev/null +++ b/election/migrations/0003_auto_20171202_1819.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('election', '0002_election_archived'), + ] + + operations = [ + migrations.AlterModelOptions( + name='role', + options={'ordering': ('order',)}, + ), + migrations.AddField( + model_name='role', + name='order', + field=models.PositiveIntegerField(editable=False, default=0, db_index=True), + preserve_default=False, + ), + ] diff --git a/election/models.py b/election/models.py index 57363125..937bca74 100644 --- a/election/models.py +++ b/election/models.py @@ -1,4 +1,5 @@ from django.db import models +from ordered_model.models import OrderedModel from django.utils.translation import ugettext_lazy as _ from django.utils import timezone @@ -81,10 +82,15 @@ class Election(models.Model): results[role.title] = role.results(total_vote) return results + def delete(self): + for election_list in self.election_lists.all(): + election_list.delete() + super(Election, self).delete() + # Permissions -class Role(models.Model): +class Role(OrderedModel): """ This class allows to create a new role avaliable for a candidature """ @@ -128,6 +134,14 @@ class ElectionList(models.Model): title = models.CharField(_('title'), max_length=255) election = models.ForeignKey(Election, related_name='election_lists', verbose_name=_("election")) + def can_be_edited_by(self, user): + return user.can_edit(self.election) + + def delete(self): + for candidature in self.candidatures.all(): + candidature.delete() + super(ElectionList, self).delete() + def __str__(self): return self.title @@ -141,6 +155,10 @@ class Candidature(models.Model): program = models.TextField(_('description'), null=True, blank=True) election_list = models.ForeignKey(ElectionList, related_name='candidatures', verbose_name=_('election list')) + def delete(self): + for vote in self.votes.all(): + vote.delete() + def can_be_edited_by(self, user): return (user == self.user) or user.can_edit(self.role.election) diff --git a/election/templates/election/election_detail.jinja b/election/templates/election/election_detail.jinja index 78cc5040..26be2e3d 100644 --- a/election/templates/election/election_detail.jinja +++ b/election/templates/election/election_detail.jinja @@ -265,10 +265,16 @@ th { {% trans %}Blank vote{% endtrans %} {%- for election_list in election_lists %} - {{ election_list.title }} + + {{ election_list.title }} + {% if user.can_edit(election_list) and election.is_vote_editable -%} + - {% trans %}Delete{% endtrans %} + {% endif %} + {%- endfor %} - {%- for role in election.roles.all() %} + {%- set role_list = election.roles.order_by('order').all() %} + {%- for role in role_list %} {%- set count = [0] %} {%- set role_data = election_form.data.getlist(role.title) if role.title in election_form.data else [] %} @@ -278,9 +284,26 @@ th { {% if user.can_edit(role) and election.is_vote_editable -%} {% trans %}Edit{% endtrans %} {% trans %}Delete{% endtrans %} + + {%- if role == role_list.last() %} + + + {%- else %} + + + {%- endif %} + {% if role == role_list.first() %} + + + {% else %} + + + {% endif %} + {%- endif -%} -
{{ role.description }} +

{{ role.description }}

{%- if role.max_choice > 1 and not election.has_voted(user) and election.can_vote(user) %} +
{% trans %}You may choose up to{% endtrans %} {{ role.max_choice }} {% trans %}people.{% endtrans %} {%- endif %} {%- if election_form.errors[role.title] is defined %} @@ -319,9 +342,6 @@ th {
{{ candidature.user.first_name }} {{candidature.user.nick_name or ''}} {{ candidature.user.last_name }} - {%- if not election.is_vote_finished %} - {{ candidature.program or '' }} - {%- endif %} {%- if user.can_edit(candidature) -%} {% if election.is_vote_editable %} {% trans %}Edit{% endtrans %} @@ -330,6 +350,9 @@ th { {% trans %}Delete{% endtrans %} {%- endif -%} {%- endif -%} + {%- if not election.is_vote_finished %} + {{ candidature.program | markdown or '' }} + {%- endif %}
{%- if election.can_vote(user) %} @@ -382,6 +405,18 @@ th { {% block script %} {{ super() }} + +