# HG changeset patch # User ymh # Date 1338896500 -7200 # Node ID 7007c6deed048668b4f094902d26583e1964f576 # Parent bd620b3d49607387229a30825070399f6edd7552# Parent 97f5db87d71c295a9c48fa7d4af255e8c4251020 Merge with 97f5db87d71c295a9c48fa7d4af255e8c4251020 diff -r bd620b3d4960 -r 7007c6deed04 src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/partial/contentslist.html --- a/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/partial/contentslist.html Tue Jun 05 13:40:37 2012 +0200 +++ b/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/partial/contentslist.html Tue Jun 05 13:41:40 2012 +0200 @@ -1,5 +1,22 @@ {% load i18n %} {% load thumbnail %} +{% load front_tags %} + +{% if nb_ct_pages %} +

+ {% if 0 < current_content_page %}<<  {% endif %} + {% for i in nb_ct_pages|get_range %} + {% if i == current_content_page %} + {{i|add:'1'}} + {% else %} + {{i|add:'1'}} + {% endif %} +    + {% endfor %} + {% if current_content_page|add:'1' < nb_ct_pages %}>>{% endif %} + +

+{% endif %}
{% trans "name" %}
diff -r bd620b3d4960 -r 7007c6deed04 src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/partial/projectslist.html --- a/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/partial/projectslist.html Tue Jun 05 13:40:37 2012 +0200 +++ b/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/partial/projectslist.html Tue Jun 05 13:41:40 2012 +0200 @@ -1,5 +1,22 @@ {% load i18n %} {% load thumbnail %} +{% load front_tags %} + +{% if nb_pj_pages %} +

+ {% if 0 < current_project_page %}<<  {% endif %} + {% for i in nb_pj_pages|get_range %} + {% if i == current_project_page %} + {{i|add:'1'}} + {% else %} + {{i|add:'1'}} + {% endif %} +    + {% endfor %} + {% if current_project_page|add:'1' < nb_pj_pages %}>>{% endif %} + +

+{% endif %}
{% trans "name" %}
diff -r bd620b3d4960 -r 7007c6deed04 src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/partial/publishedprojectslist.html --- a/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/partial/publishedprojectslist.html Tue Jun 05 13:40:37 2012 +0200 +++ b/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/partial/publishedprojectslist.html Tue Jun 05 13:41:40 2012 +0200 @@ -1,5 +1,22 @@ {% load i18n %} {% load thumbnail %} +{% load front_tags %} + +{% if nb_pj_pages %} +

+ {% if 0 < current_project_page %}<<  {% endif %} + {% for i in nb_pj_pages|get_range %} + {% if i == current_project_page %} + {{i|add:'1'}} + {% else %} + {{i|add:'1'}} + {% endif %} +    + {% endfor %} + {% if current_project_page|add:'1' < nb_pj_pages %}>>{% endif %} + +

+{% endif %}
{% trans "name" %}
diff -r bd620b3d4960 -r 7007c6deed04 src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/workspace_base.html --- a/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/workspace_base.html Tue Jun 05 13:40:37 2012 +0200 +++ b/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/workspace_base.html Tue Jun 05 13:41:40 2012 +0200 @@ -17,9 +17,7 @@ var publish_project_url = "{% url ldt.ldt_utils.views.project.publish '__PROJECT_ID__' %}"; var unpublish_project_url = "{% url ldt.ldt_utils.views.project.unpublish '__PROJECT_ID__' %}"; - function init_events(base_node) { - init_events_all(base_node, "{% url ldt.ldt_utils.views.workspace.popup_embed %}", content_filter_url, project_filter_url, publish_project_url, unpublish_project_url); } @@ -34,7 +32,7 @@ ]; searchFieldInit(input_list_init); - + init_events(document); }); diff -r bd620b3d4960 -r 7007c6deed04 src/ldt/ldt/ldt_utils/urls.py diff -r bd620b3d4960 -r 7007c6deed04 src/ldt/ldt/ldt_utils/views/content.py --- a/src/ldt/ldt/ldt_utils/views/content.py Tue Jun 05 13:40:37 2012 +0200 +++ b/src/ldt/ldt/ldt_utils/views/content.py Tue Jun 05 13:41:40 2012 +0200 @@ -23,6 +23,7 @@ import subprocess import re import datetime +import math def write_content_base(request, iri_id=None): @@ -387,14 +388,31 @@ def contents_filter(request, filter): if filter and len(filter) > 0 and filter[0] == '_': filter = filter[1:] - + + num_page = 0 + if request.GET.has_key('num_page'): + num_page = int(request.GET["num_page"]) + + # We paginate the content list, in case of filter or not if filter: - content_list = Content.safe_objects.filter(title__icontains=filter) #@UndefinedVariable + content_nb = Content.safe_objects.filter(title__icontains=filter).count() + nb_ct_pages = int(math.ceil(content_nb / settings.LDT_MAX_CONTENTS_PER_PAGE)) + content_list = Content.safe_objects.filter(title__icontains=filter)[(num_page*settings.LDT_MAX_CONTENTS_PER_PAGE):((num_page+1)*settings.LDT_MAX_CONTENTS_PER_PAGE)] #@UndefinedVariable else: - content_list = Content.safe_objects.all() #@UndefinedVariable - + content_nb, nb_ct_pages, content_list = get_contents_page(num_page, request.user) + #Change attributes with object permissions content_list = add_change_attr(request.user, content_list) + is_gecko = ((request.META['HTTP_USER_AGENT'].lower().find("firefox")) > -1); return render_to_response("ldt/ldt_utils/partial/contentslist.html", - {'contents': content_list}, - context_instance=RequestContext(request)) \ No newline at end of file + {'contents': content_list, 'nb_ct_pages': nb_ct_pages, 'content_nb': content_nb, 'current_content_page':float(num_page), + 'is_gecko': is_gecko + }, + context_instance=RequestContext(request)) + + +def get_contents_page(num_page, user): + content_nb = float(Content.safe_objects.count()) #@UndefinedVariable + nb_ct_pages = int(math.ceil(content_nb / settings.LDT_MAX_CONTENTS_PER_PAGE)) + content_list = add_change_attr(user, Content.safe_objects.all()[(num_page*settings.LDT_MAX_CONTENTS_PER_PAGE):((num_page+1)*settings.LDT_MAX_CONTENTS_PER_PAGE)]) #@UndefinedVariable + return content_nb, nb_ct_pages, content_list diff -r bd620b3d4960 -r 7007c6deed04 src/ldt/ldt/ldt_utils/views/project.py --- a/src/ldt/ldt/ldt_utils/views/project.py Tue Jun 05 13:40:37 2012 +0200 +++ b/src/ldt/ldt/ldt_utils/views/project.py Tue Jun 05 13:41:40 2012 +0200 @@ -16,6 +16,7 @@ get_userlist_model) from ldt.user.forms import PictureForm import lxml.etree +import math @login_required def create_ldt_view(request): @@ -205,13 +206,26 @@ is_gecko = ((request.META['HTTP_USER_AGENT'].lower().find("firefox")) > -1); show_username = True + project_nb = None + nb_pj_pages = None + num_page = 0 + if request.GET.has_key('num_page'): + num_page = int(request.GET["num_page"]) + if id_group > 0: # Search inside a group grp = Group.objects.get(id=id_group) project_list = get_objects_for_group(grp, 'ldt_utils.view_project').filter(query) elif id_group == -1:# Search inside projects shared with a specific user project_list = get_objects_for_user(request.user, 'ldt_utils.view_project', use_groups=False).exclude(owner=request.user) else: - project_list = Project.safe_objects.filter(query) + # We paginate in these cases : user's project or published + if status==2: + project_list = Project.safe_objects.filter(query).exclude(title__startswith='front') + else: + project_list = Project.safe_objects.filter(query) + project_nb = float(project_list.count()) #@UndefinedVariable + nb_pj_pages = int(math.ceil(project_nb / settings.LDT_MAX_PROJECTS_PER_PAGE)) + project_list = project_list[(num_page*settings.LDT_MAX_PROJECTS_PER_PAGE):((num_page+1)*settings.LDT_MAX_PROJECTS_PER_PAGE)] #@UndefinedVariable show_username = False project_list = add_change_attr(request.user, project_list) @@ -220,10 +234,11 @@ url_templ = "ldt/ldt_utils/partial/publishedprojectslist.html" else: url_templ = "ldt/ldt_utils/partial/projectslist.html" - + return render_to_response(url_templ, - {'projects': project_list, 'show_username':show_username, - 'is_gecko': is_gecko, 'group_id':id_group}, + {'projects': project_list, 'nb_pj_pages': nb_pj_pages, 'project_nb': project_nb, 'current_project_page':float(num_page), + 'show_username':show_username, 'group_id':id_group, 'is_gecko': is_gecko + }, context_instance=RequestContext(request)) @login_required @@ -238,7 +253,20 @@ ldt.unpublish() return HttpResponse(simplejson.dumps({'res':True, 'ldt': {'id': ldt.id, 'state':ldt.state, 'ldt_id': ldt.ldt_id}}, ensure_ascii=False), mimetype='application/json') - def created_ldt(request): return render_to_response('ldt/ldt_utils/save_done.html', context_instance=RequestContext(request)) + + +def get_projects_page(num_page, user): + project_nb = float(Project.safe_objects.filter(owner=user).count()) #@UndefinedVariable + nb_pj_pages = int(math.ceil(project_nb / settings.LDT_MAX_PROJECTS_PER_PAGE)) + project_list = add_change_attr(user, Project.safe_objects.filter(owner=user)[(num_page*settings.LDT_MAX_PROJECTS_PER_PAGE):((num_page+1)*settings.LDT_MAX_PROJECTS_PER_PAGE)]) #@UndefinedVariable + return project_nb, nb_pj_pages, project_list + + +def get_published_projects_page(num_page): + project_nb = float(Project.safe_objects.filter(state=2).exclude(title__startswith='front').count()) #@UndefinedVariable + nb_pj_pages = int(math.ceil(project_nb / settings.LDT_MAX_PROJECTS_PER_PAGE)) + project_list = Project.safe_objects.filter(state=2).exclude(title__startswith='front')[(num_page*settings.LDT_MAX_PROJECTS_PER_PAGE):((num_page+1)*settings.LDT_MAX_PROJECTS_PER_PAGE)] #@UndefinedVariable + return project_nb, nb_pj_pages, project_list diff -r bd620b3d4960 -r 7007c6deed04 src/ldt/ldt/ldt_utils/views/workspace.py --- a/src/ldt/ldt/ldt_utils/views/workspace.py Tue Jun 05 13:40:37 2012 +0200 +++ b/src/ldt/ldt/ldt_utils/views/workspace.py Tue Jun 05 13:41:40 2012 +0200 @@ -13,9 +13,11 @@ from ldt.ldt_utils.forms import SearchForm from ldt.ldt_utils.models import Content, Project, Segment from ldt.ldt_utils.utils import boolean_convert +from ldt.ldt_utils.projectserializer import ProjectSerializer +from ldt.ldt_utils.views.content import get_contents_page +from ldt.ldt_utils.views.project import get_projects_page, get_published_projects_page from ldt.security.utils import add_change_attr, get_userlist from lxml.html import fragment_fromstring -from ldt.ldt_utils.projectserializer import ProjectSerializer from operator import itemgetter from itertools import groupby import base64 @@ -27,11 +29,12 @@ @login_required def home(request): - # list of contents - content_list = add_change_attr(request.user, Content.safe_objects.all()) #@UndefinedVariable - + num_page = 0 + # Prepare contents pagination + content_nb, nb_ct_pages, content_list = get_contents_page(num_page, request.user) # get list of projects owned by the current user - project_list = add_change_attr(request.user, Project.safe_objects.filter(owner=request.user)) #@UndefinedVariable + project_nb, nb_pj_pages, project_list = get_projects_page(num_page, request.user) + #project_list = add_change_attr(request.user, Project.safe_objects.filter(owner=request.user)[:settings.LDT_MAX_PROJECTS_PER_PAGE]) #@UndefinedVariable is_gecko = ((request.META['HTTP_USER_AGENT'].lower().find("firefox")) > -1); @@ -44,12 +47,15 @@ # render list return render_to_response("ldt/ldt_utils/workspace.html", - {'contents': content_list, 'projects': project_list, + {'contents': content_list, 'nb_ct_pages': nb_ct_pages, 'content_nb': content_nb, 'current_content_page':float(num_page), + 'projects': project_list, 'nb_pj_pages': nb_pj_pages, 'project_nb': project_nb, 'current_project_page':float(num_page), 'is_gecko': is_gecko, #'project_api_url':"match.url_name", #'project_api_view':match.url_name,'project_api_args':"project_api_args",'project_api_kwargs':"project_api_kwargs" }, context_instance=RequestContext(request)) + + @login_required def groups(request): @@ -73,7 +79,9 @@ def published_project(request): # get list of all published projects - project_list = Project.safe_objects.filter(state=2).exclude(title__startswith='front') #@UndefinedVariable + #project_list = Project.safe_objects.filter(state=2).exclude(title__startswith='front') #@UndefinedVariable + num_page = 0 + project_nb, nb_pj_pages, project_list = get_published_projects_page(num_page) # Search form form = SearchForm() @@ -81,8 +89,8 @@ # render list return render_to_response("ldt/ldt_utils/published_projects.html", - {'projects': project_list, 'form': form, - 'is_gecko': is_gecko}, + {'projects': project_list, 'nb_pj_pages': nb_pj_pages, 'project_nb': project_nb, 'current_project_page':float(num_page), + 'form': form, 'is_gecko': is_gecko}, context_instance=RequestContext(request)) @@ -245,5 +253,6 @@ def loading(request): return render_to_response('ldt/ldt_utils/loading.html', context_instance=RequestContext(request)) + diff -r bd620b3d4960 -r 7007c6deed04 src/ldt/ldt/settings.py --- a/src/ldt/ldt/settings.py Tue Jun 05 13:40:37 2012 +0200 +++ b/src/ldt/ldt/settings.py Tue Jun 05 13:41:40 2012 +0200 @@ -81,6 +81,8 @@ LDT_MAX_FRAGMENT_PER_SEARCH = 3 LDT_RESULTS_PER_PAGE = 1 LDT_JSON_DEFAULT_INDENT = 2 +LDT_MAX_CONTENTS_PER_PAGE = 10 +LDT_MAX_PROJECTS_PER_PAGE = 10 AUTO_INDEX_AFTER_SAVE = getattr(settings, 'AUTO_INDEX_AFTER_SAVE', True) diff -r bd620b3d4960 -r 7007c6deed04 src/ldt/ldt/static/ldt/css/style.css --- a/src/ldt/ldt/static/ldt/css/style.css Tue Jun 05 13:40:37 2012 +0200 +++ b/src/ldt/ldt/static/ldt/css/style.css Tue Jun 05 13:41:40 2012 +0200 @@ -168,7 +168,7 @@ #inner_content { min-height: 600px; - padding: 40px 0px 50px 0px; + padding: 30px 0px 50px 0px; } .projectscontentstitle { diff -r bd620b3d4960 -r 7007c6deed04 src/ldt/ldt/static/ldt/css/workspace.css --- a/src/ldt/ldt/static/ldt/css/workspace.css Tue Jun 05 13:40:37 2012 +0200 +++ b/src/ldt/ldt/static/ldt/css/workspace.css Tue Jun 05 13:41:40 2012 +0200 @@ -1,7 +1,7 @@ @charset "UTF-8"; .titlediv { - margin: 0px 0px 25px 0px; + margin: 0px 0px 5px 0px; min-height: 40px; vertical-align: middle; } @@ -230,3 +230,12 @@ .clickable { cursor: pointer; } + +.prev_next_cont_proj { + margin: 0 0 5px; + float: right; +} +.prev_next_cont_proj a, .prev_next_cont_proj a:visited{ + color: #0063DC; + text-decoration: none; +} \ No newline at end of file diff -r bd620b3d4960 -r 7007c6deed04 src/ldt/ldt/static/ldt/js/projectscontents.js --- a/src/ldt/ldt/static/ldt/js/projectscontents.js Tue Jun 05 13:40:37 2012 +0200 +++ b/src/ldt/ldt/static/ldt/js/projectscontents.js Tue Jun 05 13:41:40 2012 +0200 @@ -127,7 +127,7 @@ }; } -function searchCallback(target, container_selector, url, timeout) { +function searchCallback(target, container_selector, url, timeout, num_page) { timeout = typeof(timeout) !== 'undefined' ? timeout : 0; target = $(target); @@ -151,19 +151,43 @@ var filterVal = "_" + encodeURIComponent(target.realVal()); url = url.replace('__FILTER__',filterVal); url = url.replace('__ID_GROUP__',$('#id_group').val()); - $.ajax({ - url: url, - cache: false, - success: function(data, status, request) { - $(container_selector).html(data); - target.next(".searchajaxloader").hide(); - if(target.realVal().length > 0) { - target.nextAll(".searchclear").show(); - } - init_events($(container_selector)); - target.removeAttr('timer'); - } - }); + if(num_page){ + $.ajax({ + url: url, + cache: false, + type: 'GET', + data: {num_page:num_page + }, + success: function(data, status, request) { + $(container_selector).html(data); + target.next(".searchajaxloader").hide(); + if(target.realVal().length > 0) { + target.nextAll(".searchclear").show(); + } + init_events($(container_selector)); + target.removeAttr('timer'); + }, + error: function(jqXHR, textStatus, errorThrown) { + resp = $.parseJSON(jqXHR.responseText); + alert(resp.message); + } + }); + } + else{ + $.ajax({ + url: url, + cache: false, + success: function(data, status, request) { + $(container_selector).html(data); + target.next(".searchajaxloader").hide(); + if(target.realVal().length > 0) { + target.nextAll(".searchclear").show(); + } + init_events($(container_selector)); + target.removeAttr('timer'); + } + }); + } }, 300) ); @@ -173,6 +197,18 @@ init_events_base(base_node, embed_url); + // Content pagination in workspace home + $('.contents_page').click(function(e){ + num_page = $(this).attr('alt'); + if(num_page=="prev"){ + num_page = parseInt($('#current_content_page').val()) - 1; + } + else if(num_page=="next"){ + num_page = parseInt($('#current_content_page').val()) + 1; + } + searchCallback($("#searchcontentsinput"),"#contentslistcontainer",content_filter_url,0,num_page); + }); + $('.content_link_create').each(function(i){ $(this).attr("target","_blank"); }); @@ -292,12 +328,25 @@ init_modal_window ('.ldt_link_create_project', 760, 400, 750, 390, base_node, searchprojectfilterurl); init_modal_window ('.ldt_link_copy_project', 500, 150, 500, 150, base_node, searchprojectfilterurl); + // Project pagination in workspace home + $('.projects_page').click(function(e){ + num_page = $(this).attr('alt'); + if(num_page=="prev"){ + num_page = parseInt($('#current_project_page').val()) - 1; + } + else if(num_page=="next"){ + num_page = parseInt($('#current_project_page').val()) + 1; + } + searchCallback($('#searchprojectsinput'), "#projectslistcontainer", searchprojectfilterurl, 0, num_page); + }); + $('.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); + num_page = parseInt($('#current_project_page').val()); $.ajax({ url: url, type: 'POST', @@ -306,7 +355,7 @@ //dataType: 'json', success: function(json, textStatus, XMLHttpRequest) { if(json.res) { - searchCallback($('#searchprojectsinput'), "#projectslistcontainer", searchprojectfilterurl, 0); + searchCallback($('#searchprojectsinput'), "#projectslistcontainer", searchprojectfilterurl, 0, num_page); } } }); @@ -318,6 +367,7 @@ var target = $(e.target); var project_id = target.attr('id').replace('project_',''); var url = publishprojecturl.replace('__PROJECT_ID__', project_id); + num_page = parseInt($('#current_project_page').val()); $.ajax({ url: url, type: 'POST', @@ -326,7 +376,7 @@ //dataType: 'json', success: function(json, textStatus, XMLHttpRequest) { if(json.res) { - searchCallback($('#searchprojectsinput'), "#projectslistcontainer", searchprojectfilterurl, 0); + searchCallback($('#searchprojectsinput'), "#projectslistcontainer", searchprojectfilterurl, 0, num_page); } } }); diff -r bd620b3d4960 -r 7007c6deed04 web/ldtplatform/config.py.tmpl --- a/web/ldtplatform/config.py.tmpl Tue Jun 05 13:40:37 2012 +0200 +++ b/web/ldtplatform/config.py.tmpl Tue Jun 05 13:41:40 2012 +0200 @@ -87,6 +87,8 @@ LDT_MAX_FRAGMENT_PER_SEARCH = 3 LDT_RESULTS_PER_PAGE = 1 LDT_JSON_DEFAULT_INDENT = 0 +LDT_MAX_CONTENTS_PER_PAGE = 5 +LDT_MAX_PROJECTS_PER_PAGE = 5 EMPTY_MEDIA_EXTERNALID = None diff -r bd620b3d4960 -r 7007c6deed04 web/ldtplatform/settings.py --- a/web/ldtplatform/settings.py Tue Jun 05 13:40:37 2012 +0200 +++ b/web/ldtplatform/settings.py Tue Jun 05 13:41:40 2012 +0200 @@ -181,6 +181,8 @@ LDT_JSON_DEFAULT_INDENT = 0 LDT_MAX_FRAGMENT_PER_SEARCH = 3 LDT_RESULTS_PER_PAGE = 10 +LDT_MAX_CONTENTS_PER_PAGE = 10 +LDT_MAX_PROJECTS_PER_PAGE = 10 OAUTH_PROVIDER_KEY_SIZE = 32 OAUTH_PROVIDER_SECRET_SIZE = 32