--- a/src/ldt/ldt/ldt_utils/models.py Fri Jan 13 17:28:40 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/models.py Mon Jan 16 14:23:04 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_%s' % self.iri_id, [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()
--- a/src/ldt/ldt/ldt_utils/utils.py Fri Jan 13 17:28:40 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/utils.py Mon Jan 16 14:23:04 2012 +0100
@@ -363,14 +363,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')
--- a/src/ldt/ldt/ldt_utils/views/json.py Fri Jan 13 17:28:40 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/views/json.py Mon Jan 16 14:23:04 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"))
--- a/src/ldt/ldt/ldt_utils/views/project.py Fri Jan 13 17:28:40 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/views/project.py Mon Jan 16 14:23:04 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
--- a/src/ldt/ldt/ldt_utils/views/workspace.py Fri Jan 13 17:28:40 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/views/workspace.py Mon Jan 16 14:23:04 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);
--- a/src/ldt/ldt/static/ldt/js/projectscontents.js Fri Jan 13 17:28:40 2012 +0100
+++ b/src/ldt/ldt/static/ldt/js/projectscontents.js Mon Jan 16 14:23:04 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);
}