# HG changeset patch # User hamidouk # Date 1326724926 -3600 # Node ID db8697ff4594d7b7df8ca03e073671591d4d5a5b # Parent bfea870f9eb9dad1c7f7c6536c9089c6f6427c64# Parent 47735d0bedb58f9773eecefd700afa2d27d059f7 Merge with upstream diff -r bfea870f9eb9 -r db8697ff4594 src/ldt/ldt/ldt_utils/admin.py --- a/src/ldt/ldt/ldt_utils/admin.py Mon Jan 16 15:41:26 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/admin.py Mon Jan 16 15:42:06 2012 +0100 @@ -5,13 +5,17 @@ from ldt.ldt_utils.contentindexer import ContentIndexer, ProjectIndexer from ldt.ldt_utils.fileimport import FileImport, FileImportError from ldt.ldt_utils.forms import LdtImportForm, ReindexForm, StatAnnotationForm -from ldt.ldt_utils.models import Content, Project, Media, Author -#from ldt.ldt_utils.stat import compute_stats_for +from ldt.ldt_utils.models import Content, Project, Media, Author, AnnotationStat import ldt.indexation from guardian.admin import GuardedModelAdmin + +class StatInlineAdmin(admin.TabularInline): + model = AnnotationStat + extra = 1 + class ProjectAdmin(GuardedModelAdmin): - pass + inlines = [StatInlineAdmin, ] class AuthorAdmin(GuardedModelAdmin): pass diff -r bfea870f9eb9 -r db8697ff4594 src/ldt/ldt/ldt_utils/models.py --- a/src/ldt/ldt/ldt_utils/models.py Mon Jan 16 15:41:26 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/models.py Mon Jan 16 15:42:06 2012 +0100 @@ -6,7 +6,7 @@ from ldt.core.models import Document from guardian.shortcuts import assign, remove_perm, get_perms import ldt.indexation -from ldt.security import get_current_user_or_admin +from ldt.security import get_current_user_or_admin, set_current_user from ldt.security.models import SafeModel from ldt.security.manager import SafeManager from sorl.thumbnail import ImageField @@ -225,11 +225,7 @@ if create_front_project: # We need a primary key for self in create_project, so # save() has to be called first - user = get_current_user_or_admin() - self.front_project = Project.create_project(user,'front_%s' % self.iri_id, [self], cuttings=['chapitrage', 'contribution'] ) - self.front_project.publish(allow_write=True) - assign('ldt_utils.change_content', user, self) - self.save() + self.create_front_project() def __unicode__(self): return str(self.id) + ": " + self.iri_id @@ -358,6 +354,22 @@ return locals() is_public = property(**is_public()) + + def create_front_project(self): + request_user = get_current_user_or_admin() + + if request_user.is_superuser: + admin = request_user + else: + admin = User.objects.filter(is_superuser=True)[0] + + set_current_user(admin) + self.front_project = Project.create_project(admin, 'front project : %s' % self.title, [self], cuttings=['chapitrage', 'contribution'] ) + self.front_project.publish(allow_write=True) + set_current_user(request_user) + + assign('ldt_utils.change_content', request_user, self) + self.save() diff -r bfea870f9eb9 -r db8697ff4594 src/ldt/ldt/ldt_utils/stat.py --- a/src/ldt/ldt/ldt_utils/stat.py Mon Jan 16 15:41:26 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/stat.py Mon Jan 16 15:42:06 2012 +0100 @@ -84,21 +84,23 @@ def delete_stat_project(sender, instance, **kwargs): - contents = instance.contents.all() + contents = list(instance.contents.all()) contributions = AnnotationStat.objects.filter(project=instance) for c in contributions: - content = contents.get(id=c.content.id) - - if c.nb_annotation: - content.nb_annotation -= c.nb_annotation - - if c.stat: - content_stat = get_buckets_from_string(content.stat_annotation) - proj_stat = get_buckets_from_string(c.stat) - content.stat_annotation = get_string_from_buckets([pair[0] - pair[1] for pair in zip(content_stat, proj_stat)]) - - content.save() + result = [x for x in contents if x.id == c.content.id ] + if result: + content = result[0] + + if c.nb_annotation: + content.nb_annotation -= c.nb_annotation + + if c.stat: + content_stat = get_buckets_from_string(content.stat_annotation) + proj_stat = get_buckets_from_string(c.stat) + content.stat_annotation = get_string_from_buckets([pair[0] - pair[1] for pair in zip(content_stat, proj_stat)]) + + content.save() pre_delete.connect(delete_stat_project, sender=Project) diff -r bfea870f9eb9 -r db8697ff4594 src/ldt/ldt/ldt_utils/utils.py --- a/src/ldt/ldt/ldt_utils/utils.py Mon Jan 16 15:41:26 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/utils.py Mon Jan 16 15:42:06 2012 +0100 @@ -364,14 +364,15 @@ content_node = lxml.etree.SubElement(annotations, 'content') content_node.set('id', content.iri_id) ensemble = lxml.etree.SubElement(content_node, 'ensemble') - ensemble.set('id', generate_uuid()) + ensemble.set('id', "g_%s" % generate_uuid()) ensemble.set('author', 'undefined') ensemble.set('abstract', '') + ensemble.set('idProject', project.ldt_id) for cutting in cuttings: cutting_node = lxml.etree.SubElement(ensemble, 'decoupage') cutting_node.set('author', 'perso') - cutting_node.set('id', generate_uuid()) + cutting_node.set('id', "c_%s" % generate_uuid()) title = lxml.etree.SubElement(cutting_node, 'title') title.text = cutting lxml.etree.SubElement(cutting_node, 'abstract') diff -r bfea870f9eb9 -r db8697ff4594 src/ldt/ldt/ldt_utils/views/json.py --- a/src/ldt/ldt/ldt_utils/views/json.py Mon Jan 16 15:41:26 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/views/json.py Mon Jan 16 15:42:06 2012 +0100 @@ -35,7 +35,7 @@ def project_json(request, project, serialize_contents=True, first_cutting=None): -# TODO : the following lines have been uncommented for tests only +# TODO : the following lines have been commented for tests only # they should not be commented for production # if not ldt_auth.check_access(request.user, project): # return HttpResponseForbidden(_("You can not access this project")) diff -r bfea870f9eb9 -r db8697ff4594 src/ldt/ldt/ldt_utils/views/project.py --- a/src/ldt/ldt/ldt_utils/views/project.py Mon Jan 16 15:41:26 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/views/project.py Mon Jan 16 15:42:06 2012 +0100 @@ -110,6 +110,10 @@ errors.append(_("the project %(title)s is published. please unpublish before deleting.") % {'title':project.title}) message = _("can not delete the project. Please correct the following error") title = _('title error deleting project') + elif project.content_set.count() != 0: + errors.append(_("the project %(title)s is the front project of %(content)s. please delete this content first.") % {'title':project.title, 'content':project.content_set.all()[0]}) + message = _("can not delete the project. Please correct the following error") + title = _('title error deleting project') else: message = _("please confirm deleting project %(title)s") % {'title':project.title} title = _("confirm deletion") @@ -198,9 +202,7 @@ if len(filter) > 0 and filter[0] == '_': filter = filter[1:] query &= Q(title__icontains=filter) - - query &= ~Q(title__startswith='front') - + is_gecko = ((request.META['HTTP_USER_AGENT'].lower().find("firefox")) > -1); show_username = True diff -r bfea870f9eb9 -r db8697ff4594 src/ldt/ldt/ldt_utils/views/workspace.py --- a/src/ldt/ldt/ldt_utils/views/workspace.py Mon Jan 16 15:41:26 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/views/workspace.py Mon Jan 16 15:42:06 2012 +0100 @@ -32,7 +32,7 @@ content_list = add_change_attr(request.user, Content.safe_objects.all()) #@UndefinedVariable # get list of projects owned by the current user - project_list = add_change_attr(request.user, Project.safe_objects.filter(owner=request.user).exclude(title__startswith='front')) #@UndefinedVariable + project_list = add_change_attr(request.user, Project.safe_objects.filter(owner=request.user)) #@UndefinedVariable is_gecko = ((request.META['HTTP_USER_AGENT'].lower().find("firefox")) > -1); diff -r bfea870f9eb9 -r db8697ff4594 src/ldt/ldt/static/ldt/js/projectscontents.js --- a/src/ldt/ldt/static/ldt/js/projectscontents.js Mon Jan 16 15:41:26 2012 +0100 +++ b/src/ldt/ldt/static/ldt/js/projectscontents.js Mon Jan 16 15:42:06 2012 +0100 @@ -169,7 +169,7 @@ ); } -function init_events_contents(base_node, embed_url, content_filter_url) { +function init_events_contents(base_node, embed_url, content_filter_url, project_filter_url) { init_events_base(base_node, embed_url); @@ -185,7 +185,11 @@ closeOnClick:false, callbacks: { afterClose: function(nm) { - searchCallback($('#searchprojectsinput'), "#contentslistcontainer", content_filter_url, 0); + searchCallback($('#searchcontentsinput'), "#contentslistcontainer", content_filter_url, 0); + if (project_filter_url != 'undefined') { + // Used when an admin creates a content, the list of project has to be refreshed for the front project + searchCallback($('#searchprojectsinput'), "#projectslistcontainer", project_filter_url, 0); + } }, afterShowCont: function(nm) { nm.store.iframe.load(function() { @@ -220,7 +224,7 @@ closeOnClick:false, callbacks: { afterClose: function(nm) { - searchCallback($("#searchcontentsinput"),"#contentslistcontainer",content_filter_url,0); + searchCallback($("#searchcontentsinput"),"#contentslistcontainer",content_filter_url,0); }, afterShowCont: function(nm) { nm.store.iframe.load(function() { @@ -270,6 +274,7 @@ // Can't do that because searchprojectfilterurl is not defined in init_events_base params searchCallback($('#searchprojectsinput'), "#projectslistcontainer", searchprojectfilterurl, 0); } + } }); @@ -413,7 +418,7 @@ } function init_events_all(base_node, embed_url, searchcontentfilterurl, searchprojectfilterurl, publishprojecturl, unpublishprojecturl) { - init_events_contents(base_node, embed_url, searchcontentfilterurl); + init_events_contents(base_node, embed_url, searchcontentfilterurl, searchprojectfilterurl); init_events_base_projects(base_node, embed_url, searchprojectfilterurl, publishprojecturl, unpublishprojecturl); } diff -r bfea870f9eb9 -r db8697ff4594 src/ldt/ldt/user/admin.py --- a/src/ldt/ldt/user/admin.py Mon Jan 16 15:41:26 2012 +0100 +++ b/src/ldt/ldt/user/admin.py Mon Jan 16 15:42:06 2012 +0100 @@ -5,10 +5,13 @@ from django.utils.translation import ugettext as _ from forms import LdtForm from guardian.admin import GuardedModelAdmin -from models import Ldt, UserProfile +from models import Ldt, UserProfile, GroupProfile + +class GroupProfileInline(admin.StackedInline): + model = GroupProfile class GroupAdmin(GuardedModelAdmin): - pass + inlines = [GroupProfileInline, ] class UserProfileInline(admin.StackedInline): model = UserProfile