Bug correction on deletion content. Bug correction : forbidden_stream_url was saved in the xml of the project
authorrougeronj
Thu, 11 Oct 2012 18:09:32 +0200
changeset 843 77f740eaf247
parent 842 ca38abd140b3
child 844 1f69157772a1
Bug correction on deletion content. Bug correction : forbidden_stream_url was saved in the xml of the project
src/ldt/ldt/ldt_utils/views/content.py
src/ldt/ldt/ldt_utils/views/lignesdetemps.py
--- a/src/ldt/ldt/ldt_utils/views/content.py	Thu Oct 11 16:39:05 2012 +0200
+++ b/src/ldt/ldt/ldt_utils/views/content.py	Thu Oct 11 18:09:32 2012 +0200
@@ -314,26 +314,20 @@
     deleted = None
     
     if submit_action == "prepare_delete":
-        errors, titles, delete, message_temp = prepare_delete_content(request, iri_id)
-        #if there is only front_project, with no annotations, delete without confirmation
-        if delete:
-            deleted, errors_transaction = delete_content(request, iri_id)
-            content_form = ContentForm()
-            form_status="deleted"
+        errors, titles, message_temp = prepare_delete_content(request, iri_id)
+        if errors and len(errors) > 0:
+            message = ungettext("There is %(count)d error when deleting content", "There are %(count)d errors when deleting content", len(errors)) % { 'count': len(errors)}
+            title_msg = _('title error deleting content')
         else:
-            if errors and len(errors) > 0:
-                message = ungettext("There is %(count)d error when deleting content", "There are %(count)d errors when deleting content", len(errors)) % { 'count': len(errors)}
-                title_msg = _('title error deleting content')
-            else:
-                if len(message_temp)>0:
-                    message = message_temp
-                else:    
-                    message = _("Confirm delete content %(titles)s") % { 'titles' : ",".join(titles) }
-                title_msg = _("confirm delete content")
-            return render_to_response('ldt/ldt_utils/error_confirm.html', {'errors':errors, 'message':message, 'title': title_msg}, context_instance=RequestContext(request))  
+            if len(message_temp)>0:
+                message = message_temp
+            else:    
+                message = _("Confirm delete content %(titles)s") % { 'titles' : ",".join(titles) }
+            title_msg = _("confirm delete content")
+        return render_to_response('ldt/ldt_utils/error_confirm.html', {'errors':errors, 'message':message, 'title': title_msg}, context_instance=RequestContext(request))  
     elif submit_action == "delete":
         deleted, errors_transaction = delete_content(request, iri_id)
-        content_form = contentForm()
+        content_form = ContentForm()
         form_status = "deleted"
     elif submit_action == "prepare_reset":
         errors=[]
@@ -418,13 +412,9 @@
                 project_titles = map(lambda p: unicode(p.title), projects)
                 errors.append(ungettext("Content '%(title)s' is referenced by this project : %(project_titles)s. Please delete it beforehand.", "Content '%(title)s' is referenced by %(count)d projects: %(project_titles)s. Please delete them beforehand.", projects_nb) % {'title':unicode(content.title), 'count':projects_nb, 'project_titles': ",".join(project_titles)})
             elif projects_nb == 1:
-                if not projects[0].has_annotations():
-                    delete = True
-                else:
+                if projects[0].has_annotations():
                     message = _("The project '%(project_title)s' pointing on the content '%(title)s' has several annotations. Do you want to delete the content and the project anyway ?")% {'project_title':unicode(projects[0].title), 'title':unicode(content.title)}
-            elif project_nb == 0:
-                delete = True
-    return errors, titles, delete, message
+    return errors, titles, message
 
 
 @login_required
--- a/src/ldt/ldt/ldt_utils/views/lignesdetemps.py	Thu Oct 11 16:39:05 2012 +0200
+++ b/src/ldt/ldt/ldt_utils/views/lignesdetemps.py	Thu Oct 11 18:09:32 2012 +0200
@@ -4,7 +4,7 @@
 from django.http import HttpResponse, HttpResponseRedirect
 from django.shortcuts import render_to_response, get_object_or_404
 from django.template import RequestContext
-from ldt.ldt_utils.models import Content, Project
+from ldt.ldt_utils.models import Content, Project, Media
 from ldt.ldt_utils.utils import LdtUtils, clean_description
 from ldt.indexation import SimpleSearch
 from ldt.security.utils import set_forbidden_stream
@@ -247,7 +247,7 @@
 
         #save xml ldt
         ldtproject.ldt = ldt
-
+        
         doc = lxml.etree.fromstring(ldtproject.ldt_encoded)
         result = doc.xpath("/iri/project")
         
@@ -260,6 +260,12 @@
         for medianode in result:
             id = medianode.get("id")
             new_contents.append(id)
+            #Put back the video fied from "forbidden_stream_url" to the video url
+            if medianode.get("video") == settings.FORBIDDEN_STREAM_URL:
+                content = Content.objects.get(iri_id=id)
+                media = Media.objects.get(id=content.media_obj.id)
+                medianode.set('video', media.videopath)
+                ldtproject.ldt = lxml.etree.tostring(doc, pretty_print=True)
     
         check_icon_project = False