Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/webapp
diff options
context:
space:
mode:
authorRogelio Mita <rogeliomita@activitycentral.com>2013-04-25 06:03:12 (GMT)
committer Rogelio Mita <rogeliomita@activitycentral.com>2013-04-25 06:03:12 (GMT)
commit97014e32fafbeafb2aef74b99a48db3469d6b21d (patch)
tree2828372f15ae493852cac6cc67b9e16c180eff30 /webapp
parentcfe0e9c3e7237332ab39a125257d74caa24905c0 (diff)
Adding remove option for a poll
Diffstat (limited to 'webapp')
-rw-r--r--webapp/polls/models.py17
-rw-r--r--webapp/polls/templates/poll-form.html12
-rw-r--r--webapp/sociologist/poll_urls.py2
-rw-r--r--webapp/sociologist/views.py15
4 files changed, 46 insertions, 0 deletions
diff --git a/webapp/polls/models.py b/webapp/polls/models.py
index 0dc65fd..9e96bf2 100644
--- a/webapp/polls/models.py
+++ b/webapp/polls/models.py
@@ -103,6 +103,23 @@ class Poll(Document, AbstracErrorObject):
return poll_clone
+ def delete(self):
+
+ structure = self.structure if self.structure else None
+ structure_id = structure.id if structure.id else None
+
+ if structure_id:
+ get_db().structures.remove(ObjectId(structure_id))
+
+ # removing image options files
+ if structure:
+ path = structure.get_image_options_path()
+ if os.path.exists(path):
+ shutil.rmtree(path)
+
+ if self.id:
+ get_db().polls.remove(ObjectId(self.id))
+
@staticmethod
def pollster_assignment(pollster_id, poll_ids):
dbref = DBRef(Pollster.collection_name, ObjectId(pollster_id))
diff --git a/webapp/polls/templates/poll-form.html b/webapp/polls/templates/poll-form.html
index 97e0093..890d022 100644
--- a/webapp/polls/templates/poll-form.html
+++ b/webapp/polls/templates/poll-form.html
@@ -5,6 +5,10 @@
{% block main_container %}
+ {% if user.is_superuser and poll.id %}
+ <a href="{% url sociologist:poll_delete id=poll.id %}" class="remove_button btn btn-danger"><i class="icon-trash">&nbsp;Eliminar</i></a>
+ {% endif %}
+
<div class="center">
<h2>{% trans 'Formulario de encuesta' %}</h2>
</div>
@@ -95,6 +99,14 @@
$(document).ready(function(){
+ $(".remove_button").on('click', function(event){
+
+ if(!confirm('¿Esta seguro que quiere eliminar definitivamente esta encuesta?')) {
+ event.preventDefault();
+ }
+
+ })
+
form = $('#poll_form');
$('#continue').click(function(){
diff --git a/webapp/sociologist/poll_urls.py b/webapp/sociologist/poll_urls.py
index 1fca75e..23ad046 100644
--- a/webapp/sociologist/poll_urls.py
+++ b/webapp/sociologist/poll_urls.py
@@ -14,6 +14,8 @@ urlpatterns = patterns(
PollFormView.as_view(), name="poll_edit"),
url(r'^clone/(?P<id>[0-9A-Fa-f]{24})/$',
'sociologist.views.poll_clone', name="poll_clone"),
+ url(r'^delete/(?P<id>[0-9A-Fa-f]{24})/$',
+ 'sociologist.views.poll_delete', name="poll_delete"),
# Poll structure CRUD
url(r'^structure/(?P<poll_id>[0-9A-Fa-f]{24})/$',
diff --git a/webapp/sociologist/views.py b/webapp/sociologist/views.py
index 3683073..083d6f9 100644
--- a/webapp/sociologist/views.py
+++ b/webapp/sociologist/views.py
@@ -270,3 +270,18 @@ def poll_clone(request, id):
messages.add_message(request, messages.ERROR, msg)
return HttpResponseRedirect(reverse('sociologist:poll_list'))
+
+
+def poll_delete(request, id):
+ try:
+ poll = Poll.get(id=id)
+ poll_name = poll.name
+ poll.delete()
+
+ msg = u'La encuesta %s fué eliminada.' % poll_name
+ messages.add_message(request, messages.SUCCESS, msg)
+ except:
+ msg = u'La encuesta no pudo ser eliminada.'
+ messages.add_message(request, messages.ERROR, msg)
+
+ return HttpResponseRedirect(reverse('sociologist:poll_list'))