Added loading bar #16 + groupped search results by project
authorverrierj
Tue, 20 Sep 2011 15:31:58 +0200
changeset 181 12e279e0253c
parent 180 6c1e1da5ce30
child 182 b7add86c2772
Added loading bar #16 + groupped search results by project
src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_content.html
src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_ldt.html
src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/partial/projectslist.html
src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/search_results.html
src/ldt/ldt/ldt_utils/views.py
src/ldt/ldt/static/ldt/img/ajax-loader-transp.gif
src/ldt/ldt/static/ldt/js/projectscontents.js
src/ldt/ldt/templates/ldt/ldt_base.html
--- a/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_content.html	Mon Sep 19 12:01:13 2011 +0200
+++ b/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_content.html	Tue Sep 20 15:31:58 2011 +0200
@@ -50,8 +50,8 @@
 {% endblock %}
 
 {% block body %}
-	{% if content_form.errors %}
-	<!-- <div id="content-form-error">
+	<!-- {% if content_form.errors %}
+	<div id="content-form-error">
 		<p>{% trans "The operation could not be performed because one or more error(s) occurred.<br />Please resubmit the content form after making the following changes:" %}</p>
 		<ul>
 		{% for field in content_form %}
@@ -59,8 +59,8 @@
 		{% endfor %}
 		</ul>
 	</div>
-	{% endif %}
- -->
+	{% endif %} -->
+
 	{% if media_form.errors %}
 	<div id="media-form-error">
 		<p>{% trans "The operation could not be performed because one or more error(s) occurred.<br />Please resubmit the media form after making the following changes:" %}</p>
--- a/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_ldt.html	Mon Sep 19 12:01:13 2011 +0200
+++ b/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_ldt.html	Tue Sep 20 15:31:58 2011 +0200
@@ -50,7 +50,19 @@
 		});
 				
 	});
+
 	</script>
+	<script type="text/javascript" src="{{LDT_MEDIA_PREFIX}}js/tiny_mce/tiny_mce.js"></script>
+    <script type="text/javascript">
+    tinyMCE.init({
+            theme : "simple",
+            mode : "textareas",
+            forced_root_block : false,
+            force_br_newlines : true,
+            force_p_newlines : false,
+            language : "fr"
+    });
+    </script>
 {% endblock %}
 
 {% block body %}
--- a/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/partial/projectslist.html	Mon Sep 19 12:01:13 2011 +0200
+++ b/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/partial/projectslist.html	Tue Sep 20 15:31:58 2011 +0200
@@ -9,7 +9,7 @@
     <tr class="imageline {% cycle 'projectscontentsoddline' 'projectscontentsevenline'%}" >
         {% url ldt.ldt_utils.views.project_json_id project.ldt_id as json_url_id %}
 
-        <td class="cellimg"><div class="cellimgdiv"><a  href="{% url index_project_full project.ldt_id %}"><img src="{{LDT_MEDIA_PREFIX}}img/page_edit.png" alt="{% trans 'open ldt' %}" title="{% trans 'open ldt' %}"/></a></div></td>
+		<td class="cellimg"><div class="cellimgdiv"><a class="ldt_link_open_ldt" href="{% url index_project project.ldt_id %}"><img src="{{LDT_MEDIA_PREFIX}}img/page_edit.png" alt="{% trans 'open ldt' %}" title="{% trans 'open ldt' %}" /></a></div></td>
         <td class="cellimg"><div class="cellimgdiv"><img src="{{LDT_MEDIA_PREFIX}}img/page_copy.png" href="{% url ldt.ldt_utils.views.copy_project project.ldt_id %}" class="ldt_link_copy_project" alt="{% trans 'copy project' %}" title="{% trans 'copy project' %}"/></div></td>
         <td class="cellimg"><div class="cellimgdiv"><img src="{{LDT_MEDIA_PREFIX}}img/plugin.png" href="{{WEB_URL}}{{json_url_id}}" id="player_project_{{project.ldt_id}}" class="ldt_link_embed" alt="{% trans 'link json by id' %}" title="{% trans 'link json by id' %}"/></div></td>
         <td class="cellimg">
--- a/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/search_results.html	Mon Sep 19 12:01:13 2011 +0200
+++ b/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/search_results.html	Tue Sep 20 15:31:58 2011 +0200
@@ -1,14 +1,31 @@
 {% extends "ldt/ldt_base.html" %}
 {% load i18n %}
 
+{% block js_import %}
+    {{ block.super }}    
+	<script type="text/javascript" src="{{LDT_MEDIA_PREFIX}}js/projectscontents.js" ></script>
+{% endblock %}
+
 {% block css_import %}
     {{ block.super }}
     <link rel="stylesheet" href="{{LDT_MEDIA_PREFIX}}css/workspace.css" />
 {% endblock %}
 
+{% block js_declaration %}
+	{{ block.super }}
+
+	<script type="text/javascript">   
+	$(document).ready(function(){
+		init_events_all(document, "/pf/ldtplatform/ldt/embedpopup", '', '', '', '');
+	});    
+    </script>
+{% endblock %}
+
 
 {% block content %}
 
+<div class="span-24 last" id="allcontentsdiv">
+
 {% if msg %}
 {{ msg }}
 {% else %}
@@ -18,9 +35,17 @@
 	{% autoescape off %}
 	<ul>
 	{% for res in results.object_list %}
-		<li>
-			<a href="{% url ldt.ldt_utils.views.display_highlighted_seg res.project_id res.iri_id res.ensemble_id res.decoupage_id res.element_id%}">{{ res.segment_title }}</a><br />
-			{{ res.context }}<br />	
+		<li>		
+			<span title="{% trans 'open ldt' %}"><a class="ldt_link_open_ldt" href="{% url index_project res.project_id%}" >Project : {{res.project_title}} </a></span><br />
+			Project description : {{ res.project_description }} <br />		
+			<ul>
+			{% for segment in res.list %}
+				<li><span title="{% trans 'open ldt' %}"><a class="ldt_link_open_ldt" href="{% url ldt.ldt_utils.views.display_highlighted_seg segment.project_id segment.iri_id segment.ensemble_id segment.decoupage_id segment.element_id %}">{{ segment.segment_title }}</a></span><br />
+				{{ segment.context }}<br />
+				<br />
+				</li>
+			{% endfor %}
+			</ul>	
 		</li>
 	{% endfor %}
 	</ul>
--- a/src/ldt/ldt/ldt_utils/views.py	Mon Sep 19 12:01:13 2011 +0200
+++ b/src/ldt/ldt/ldt_utils/views.py	Tue Sep 20 15:31:58 2011 +0200
@@ -24,6 +24,8 @@
 from models import Media, Project
 from projectserializer import ProjectSerializer
 from urllib2 import urlparse
+from operator import itemgetter
+from itertools import groupby
 import base64
 import django.core.urlresolvers
 import ldt.auth as ldt_auth
@@ -64,11 +66,11 @@
         else:
             dur = 3600000
         # Build platform media and platform content from "regarssignes" contents
-        media = Media.objects.create(external_id=row[8], creation_date=row[4], update_date=row[5], videopath=row[3], duration=dur, 
-                                     description=row[7], title=row[6], src=(row[1]+u".flv"), mimetype_field="('video/x-flv', None)")
+        media = Media.objects.create(external_id=row[8], creation_date=row[4], update_date=row[5], videopath=row[3], duration=dur,
+                                     description=row[7], title=row[6], src=(row[1] + u".flv"), mimetype_field="('video/x-flv', None)")
         media.save()
         
-        content = Content.objects.create(iri_id=row[1], iriurl=row[2], creation_date=row[4], update_date=row[5], title=row[6], description=row[7], 
+        content = Content.objects.create(iri_id=row[1], iriurl=row[2], creation_date=row[4], update_date=row[5], title=row[6], description=row[7],
                                      content_creation_date=row[4], duration=dur, media_obj=media)
         content.save()
     
@@ -104,7 +106,7 @@
     
     # render list
     return render_to_response("ldt/ldt_utils/groups.html",
-                              {'groups': group_list, 
+                              {'groups': group_list,
                                'is_gecko': is_gecko},
                               context_instance=RequestContext(request))
 
@@ -196,7 +198,7 @@
         grp = Group.objects.get(id=id_group)  #@UndefinedVariable
         users = User.objects.filter(groups__in=[grp]) #@UndefinedVariable
         query &= Q(owner__in=users) #@UndefinedVariable
-        project_list = Project.objects.filter(query).extra(select={'lower_title': 'lower(title)'}).order_by('owner__username','lower_title') #@UndefinedVariable
+        project_list = Project.objects.filter(query).extra(select={'lower_title': 'lower(title)'}).order_by('owner__username', 'lower_title') #@UndefinedVariable
         show_username = True
     else :
         project_list = Project.objects.filter(query) #@UndefinedVariable
@@ -232,6 +234,8 @@
     form = SearchForm()
     return render_to_response('ldt/ldt_utils/search_form.html', {'form': form} , context_instance=RequestContext(request))
 
+
+
 def search_index(request):
         
     sform = SearchForm(request.POST)
@@ -245,7 +249,15 @@
             url = settings.WEB_URL + django.core.urlresolvers.reverse("ldt.ldt_utils.views.search_init", args=[field, queryStr])
             return render_to_response('ldt/ldt_utils/init_ldt_full.html', {'LDT_MEDIA_PREFIX': settings.LDT_MEDIA_PREFIX, 'colorurl': settings.LDT_MEDIA_PREFIX + 'swf/ldt/pkg/color.xml', 'i18nurl': settings.LDT_MEDIA_PREFIX + 'swf/ldt/pkg/i18n', 'language': language_code, 'baseurl': settings.LDT_MEDIA_PREFIX + 'swf/ldt/', 'url': url}, context_instance=RequestContext(request))
         else:
-            complete_results = get_results_with_context(field, search)
+            results = get_results_with_context(field, search)                   
+            results.sort(key=lambda k : k['project_id'])
+            complete_results = []
+            
+            results.sort(key=lambda k: k['project_id'])
+            for project_id, item in groupby(results, itemgetter('project_id')):
+                project = Project.objects.get(ldt_id=project_id)               
+                complete_results.append({'list' : list(item), 'project_title' : project.title, 'project_id' : project.ldt_id, 'project_description' : project.get_description() })
+        
             request.session.__setitem__('complete_results', complete_results)
             request.session.__setitem__('search', search)
             paginator = Paginator (complete_results, settings.LDT_RESULTS_PER_PAGE)
@@ -263,12 +275,16 @@
         return render_to_response('ldt/ldt_utils/search_results.html', {'msg' : msg}, context_instance=RequestContext(request))
 
 
-def display_highlighted_seg(request, project_id, content_id, ensemble_id, cutting_id, segment_id):
+def display_highlighted_seg(request, project_id, content_id, ensemble_id, cutting_id, segment_id, full=False):
     
     url = settings.WEB_URL + reverse("ldt.ldt_utils.views.init_segment", args=[project_id, content_id, ensemble_id, cutting_id, segment_id])
     language_code = request.LANGUAGE_CODE[:2]
+    
+    if full:
+        return render_to_response('ldt/ldt_utils/init_ldt_full.html', {'LDT_MEDIA_PREFIX': settings.LDT_MEDIA_PREFIX, 'colorurl': settings.LDT_MEDIA_PREFIX + 'swf/ldt/pkg/color.xml', 'i18nurl': settings.LDT_MEDIA_PREFIX + 'swf/ldt/pkg/i18n', 'language': language_code, 'baseurl': settings.LDT_MEDIA_PREFIX + 'swf/ldt/', 'url': url}, context_instance=RequestContext(request))
+    else:
+        return render_to_response('ldt/ldt_utils/init_ldt.html', {'LDT_MEDIA_PREFIX': settings.LDT_MEDIA_PREFIX, 'colorurl': settings.LDT_MEDIA_PREFIX + 'swf/ldt/pkg/color.xml', 'i18nurl': settings.LDT_MEDIA_PREFIX + 'swf/ldt/pkg/i18n', 'language': language_code, 'baseurl': settings.LDT_MEDIA_PREFIX + 'swf/ldt/', 'url': url}, context_instance=RequestContext(request))
 
-    return render_to_response('ldt/ldt_utils/init_ldt_full.html', {'LDT_MEDIA_PREFIX': settings.LDT_MEDIA_PREFIX, 'colorurl': settings.LDT_MEDIA_PREFIX + 'swf/ldt/pkg/color.xml', 'i18nurl': settings.LDT_MEDIA_PREFIX + 'swf/ldt/pkg/i18n', 'language': language_code, 'baseurl': settings.LDT_MEDIA_PREFIX + 'swf/ldt/', 'url': url}, context_instance=RequestContext(request))
 
 
 def search_listing(request):
@@ -467,21 +483,21 @@
         ldtdoc = lxml.etree.fromstring(project.ldt.encode("utf-8"))
         displays_node = ldtdoc.find("displays")
         if not displays_node:
-            displays_node = lxml.etree.SubElement(ldtdoc,u"displays")        
+            displays_node = lxml.etree.SubElement(ldtdoc, u"displays")        
         res = displays_node.xpath("display")
         if len(res) > 0:
             display_node = res[0]
         else:
-            display_node  = lxml.etree.SubElement(displays_node, u"display", attrib={u'id':u'0', u'title': u'generated', u'idsel':unicode(content_id), u'tc':u'0'})
+            display_node = lxml.etree.SubElement(displays_node, u"display", attrib={u'id':u'0', u'title': u'generated', u'idsel':unicode(content_id), u'tc':u'0'})
         
         res = display_node.xpath("content[@id='%s']/decoupage[(@id='%s') and (@idens='%s')]" % (content_id, cutting_id, ensemble_id))
         if len(res) == 0:
             #create node
-            res = display_node.xpath("content[@id='%s']" %(content_id))
+            res = display_node.xpath("content[@id='%s']" % (content_id))
             if len(res) == 0:
-                content_node = lxml.etree.SubElement(display_node,u"content")
+                content_node = lxml.etree.SubElement(display_node, u"content")
             else:
-                content_node =  res[0]
+                content_node = res[0]
             lxml.etree.SubElement(content_node, u"decoupage", attrib={u'id':unicode(cutting_id), u'idens':unicode(ensemble_id)})
         active_segment_node = displays_node.find(u"activeSegment")
         if not active_segment_node:
@@ -508,15 +524,15 @@
             'idsegment' : segment_id
         }
         
-        doc = ldtgen.generate_ldt(content_list, "segment : ", author=username,  startSegment=start_segment)
+        doc = ldtgen.generate_ldt(content_list, "segment : ", author=username, startSegment=start_segment)
         
-        doc.write(resp, pretty_print = ('DEBUG' in dir(settings) and settings.DEBUG))
+        doc.write(resp, pretty_print=('DEBUG' in dir(settings) and settings.DEBUG))
         
     return resp
         
 #        ldtgen.
     
-def index_project(request, id, full= False):
+def index_project(request, id, full=False):
 
     urlStr = settings.WEB_URL + reverse("space_ldt_init", args=['ldt_project', id])
     posturl = settings.WEB_URL + reverse("ldt.ldt_utils.views.save_ldt_project")
@@ -1132,12 +1148,12 @@
     try:
         # The filename arrives with a GET var.
         file_path = os.path.join(settings.STREAM_PATH, "tmp/" + request.COOKIES[settings.SESSION_COOKIE_NAME] + "/", ldt_utils_path.sanitize_filename(request.GET["filename"]))
-        if hasattr(settings,'FFMPEG_PATH') and os.path.exists(file_path):
-            output = str(subprocess.Popen([settings.FFMPEG_PATH, "-i", file_path],stderr = subprocess.PIPE).communicate()[1])
+        if hasattr(settings, 'FFMPEG_PATH') and os.path.exists(file_path):
+            output = str(subprocess.Popen([settings.FFMPEG_PATH, "-i", file_path], stderr=subprocess.PIPE).communicate()[1])
             m = re.search("Duration:\s*?([\d.:]+)", output, re.M)
             dur_arr = m.group(1).split(":")
-            td = datetime.timedelta(hours=int(dur_arr[0]),minutes=int(dur_arr[1]),seconds=float(dur_arr[2]))
-            str_duration = str((td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**3)
+            td = datetime.timedelta(hours=int(dur_arr[0]), minutes=int(dur_arr[1]), seconds=float(dur_arr[2]))
+            str_duration = str((td.microseconds + (td.seconds + td.days * 24 * 3600) * 10 ** 6) / 10 ** 3)
             return HttpResponse(str_duration, mimetype="text/plain")
         else:
             return HttpResponse("", mimetype="text/plain")
@@ -1151,7 +1167,7 @@
     # Get group, user and project_list
     grp = Group.objects.get(id=request.POST["id_group"])  #@UndefinedVariable
     users = User.objects.filter(groups__in=[grp]) #@UndefinedVariable
-    project_list = Project.objects.filter(owner__in=users).extra(select={'lower_title': 'lower(title)'}).order_by('owner__username','lower_title')  #@UndefinedVariable
+    project_list = Project.objects.filter(owner__in=users).extra(select={'lower_title': 'lower(title)'}).order_by('owner__username', 'lower_title')  #@UndefinedVariable
 
     is_gecko = ((request.META['HTTP_USER_AGENT'].lower().find("firefox")) > -1);
     
@@ -1159,4 +1175,4 @@
     return render_to_response("ldt/ldt_utils/partial/projectslist.html",
                               {'projects': project_list, 'show_username':True,
                                'is_gecko': is_gecko},
-                              context_instance=RequestContext(request))
\ No newline at end of file
+                              context_instance=RequestContext(request))
Binary file src/ldt/ldt/static/ldt/img/ajax-loader-transp.gif has changed
--- a/src/ldt/ldt/static/ldt/js/projectscontents.js	Mon Sep 19 12:01:13 2011 +0200
+++ b/src/ldt/ldt/static/ldt/js/projectscontents.js	Tue Sep 20 15:31:58 2011 +0200
@@ -53,7 +53,7 @@
         });
     });
     
-    $('.cellimgdiv img').qtip({
+    $('.cellimgdiv img, .publishedproject, .unpublishedproject').qtip({
     	style: {
     		classes: 'ui-tooltip-dark ui-tooltip-rounded',
     	}    	
@@ -75,6 +75,10 @@
         		'width': 0,
         		'color': '#505050'
         	},
+        	position: {
+        		my: 'top left',
+        		at: 'bottom left', // at the bottom right of...
+        	}
         });
     });
 }
@@ -147,7 +151,7 @@
                 url: url,
                 cache: false,
                 success: function(data, status, request) {
-                    $(container_selector).html(data);
+                	$(container_selector).html(data);
                     target.next(".searchajaxloader").hide();
                     if(target.realVal().length > 0) {
                         target.nextAll(".searchclear").show();
@@ -155,7 +159,7 @@
                     init_events($(container_selector));
                     target.removeAttr('timer');
                 }
-            });    
+            });  
         },
         300)
     );
@@ -280,6 +284,7 @@
      
     $('.publishedproject', base_node).click(function(e) {
         e.preventDefault();
+        display_loading_icon($(this));
         var target = $(e.target);
         var project_id = target.attr('id').replace('project_','');
         var url = unpublishprojecturl.replace('__PROJECT_ID__', project_id);
@@ -299,6 +304,7 @@
     
     $('.unpublishedproject', base_node).click(function(e) {
         e.preventDefault();
+        display_loading_icon($(this));
         var target = $(e.target);
         var project_id = target.attr('id').replace('project_','');
         var url = publishprojecturl.replace('__PROJECT_ID__', project_id);
@@ -347,6 +353,10 @@
     
 }
 
+function display_loading_icon (project) {
+	project.attr('src', LDT_MEDIA_PREFIX + "img/ajax-loader-transp.gif");
+}
+
 function init_events_projects(base_node, embed_url, searchprojectfilterurl, publishprojecturl, unpublishprojecturl) {
     init_events_base(base_node, embed_url);
     init_events_base_projects(base_node, embed_url, searchprojectfilterurl, publishprojecturl, unpublishprojecturl);
--- a/src/ldt/ldt/templates/ldt/ldt_base.html	Mon Sep 19 12:01:13 2011 +0200
+++ b/src/ldt/ldt/templates/ldt/ldt_base.html	Tue Sep 20 15:31:58 2011 +0200
@@ -4,6 +4,10 @@
 {% load navigation %}
 
 {% block js_import %}
+	<script type="text/javascript">
+		var LDT_MEDIA_PREFIX = "{{LDT_MEDIA_PREFIX}}"; // Required for search bar icon in projectscontents.js
+	</script>
+	
     {{ block.super }}
     <script type="text/javascript" src="{{LDT_MEDIA_PREFIX}}js/jquery.nyroModal.min.js"></script>
     <!--[if IE 6]>
@@ -11,12 +15,11 @@
     <![endif]-->
     <script type="text/javascript" src="{{LDT_MEDIA_PREFIX}}js/jquery.qtip.min.js"></script>
     <script type="text/javascript" src="{{LDT_MEDIA_PREFIX}}js/jquery.validate.js" ></script>
-    
 {% endblock %}
 
 {% block js_declaration %}
     <script type="text/javascript">    
-    
+
     jQuery(function($, undefined) {
     $.nmFilters({iriIframe:{
         is: function(nm) {
@@ -120,7 +123,9 @@
 		            <form method="post" id="quick_search_form" action="{% url ldt.ldt_utils.views.search_index %}" title="{% trans "search"%}" accept-charset="utf-8">
 					<input type="text" name="search" id="id_search" size="16"/>
 					<input type='hidden' name='field' value='all' />
-					<input type="submit" class="quick_search_submit" value="" />{% csrf_token %}</form>
+					<input type="submit" class="quick_search_submit" value="" />{% csrf_token %}
+					
+					</form>
 		        </div>
 		        {% endif %}
             </div>