Commits

u...@localhost  committed b270088

Initial map delete option

  • Participants
  • Parent commits 258af1b

Comments (0)

Files changed (4)

File maps/models.py

             return self.schedule_date.strftime("%A %d %B %Y")
         return u""
 
+    def delete_map_stories(self):
+        # TODO just mark as deleted
+        stories = self.stories.all()
+        for story in stories:
+            story.delete_story_and_its_content()
+
+
+    def delete_map_and_its_contents(self):
+        self.delete_map_stories()
+        # TODO just mark as deleted
+        self.delete()
+
+
 
 class OpinionType(models.Model):
     name = models.CharField(_("name"), max_length=255, null=True, blank=True)
             return (datetime.now() - self.schedule_date).days >= 1
         return False
 
+    def delete_story_answers(self):
+        self.answers.all().delete()
+
+    def delete_story_approvals(self):
+        self.approvals.all().delete()
+
+    def delete_story_and_its_content(self):
+        self.delete_story_answers()
+        self.delete_story_approvals()
+        self.delete()
+
 ANSWER_TYPE_TEXT = 1
 ANSWER_TYPE_POS_OPINION = 2
 ANSWER_TYPE_NEG_OPINION = 3

File maps/views.py

                 answer.save()
                 map_updated = True
                 ret_dict = answer.to_dict()
+        elif entity_type == "map":
+
+            if method == "delete":
+
+                map = get_object_or_404(Map, id=json_model["id"])
+                if request.user == map.initiator:
+                    logging.info("Marking map %s as deleted, together with all of its content" % map.title)
+                    # invoke delete_map
+                    map.delete_map_and_its_contents()
+                    # prepare json to return with delete notification
 
         ret_dict["entity_type"] = entity_type
         ret_dict["method"] = method
         for user_channel in user_channels:
             logging.info("Sending message to user: " + user_channel.client_id)
             channel.send_message(user_channel.client_id, json)
-            # REPLY TO THE USER REQUEST
+    # REPLY TO THE USER REQUEST
     return HttpResponse('success')
 
 

File templates/admin/base.html

             {% block nav-global %}{% endblock %}
         </div>
         <!-- END Header -->
-        {% block breadcrumbs %}<div class="breadcrumbs"><a href="/">{% trans 'Home' %}</a>{% if title %} &rsaquo; <span style="font-size: 15pt">{{ title }}</span>{% endif %} <div class="toolbar" style="float: right;">{% if is_initiator %}<a href="#">{% trans "Delete map" %}</a>{% endif %}</div></div>{% endblock %}
+        {% block breadcrumbs %}<div class="breadcrumbs"><a href="/">{% trans 'Home' %}</a>{% if title %} &rsaquo; <span style="font-size: 15pt">{{ title }}</span>{% endif %} <div class="toolbar" style="float: right;">{% if is_initiator %}<a id="delete_map_link" href="#">{% trans "Delete map" %}</a>{% endif %}</div></div>{% endblock %}
     {% endif %}
 
     {% if messages %}

File templates/map.html

             var entity = JSON.parse(m.data);
 
             switch (entity["entity_type"]) {
+                case "map":
+                    if (entity["method"] == "delete") {
+                    {% if not is_initiator %}
+                        alert("The map creator has decided to delete this map, sorry. You'll be now redirected to the dashboard.");
+                    {% endif %}
+                        document.location = "/";
+                    }
+                    break;
                 case "story":
                     try {
                         var story = window.stories.get(entity.id);
     init(options);
     window.user_id = {{ request.user.id }};
 
+    $("#delete_map_link").click(delete_map);
 });
 
 var svg_zoom_in_func,
         })
     }
 }
+
+function delete_map() {
+    if (confirm("{% trans "Are you sure you want to delete this map?" %}")) {
+        window.map.destroy();
+    }
+}
+
+
 function extract_story_data_from_dialog() {
     var new_story_data = {title:"Untitled"};
     if ($("#id_title").val()) new_story_data["title"] = $("#id_title").val();