# HG changeset patch # User verrierj # Date 1326470221 -3600 # Node ID 0e410517b3113f873b711392e020bcc80bfee59a # Parent a99ea8eb8b9aa93907e0aedbcb51bbc813d3cc3e Front projects are hidden from user interface diff -r a99ea8eb8b9a -r 0e410517b311 src/ldt/ldt/ldt_utils/models.py --- a/src/ldt/ldt/ldt_utils/models.py Fri Jan 13 14:25:18 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/models.py Fri Jan 13 16:57:01 2012 +0100 @@ -2,11 +2,11 @@ from django.contrib.auth.models import User, Group from django.db import models from django.utils.translation import ugettext_lazy as _ -from django.db.models.signals import post_save #from ldt.core.models import Document, Owner 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.models import SafeModel from ldt.security.manager import SafeManager from sorl.thumbnail import ImageField @@ -208,16 +208,28 @@ #TODO: better manage the change in .iri name and error scenario (save in temp file + rename def save(self, *args, **kwargs): - self.sync_iri_file() - # update it + create_front_project = False + # update it + self.sync_iri_file() + + if not self.pk: + create_front_project = True + + if not self.nb_annotation: + self.nb_annotation = 0 + if not self.stat_annotation: + self.stat_annotation = '0,0' super(Content, self).save(*args, **kwargs) - def create_front_project(sender, instance, created, **kwargs):#@NoSelf - if created: - admin = User.objects.filter(is_superuser=True)[0] - instance.front_project = Project.create_project(admin ,'front_%s' % instance.iri_id, [instance], cuttings=['chapitrage', 'contribution'] ) - instance.save() + 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() def __unicode__(self): return str(self.id) + ": " + self.iri_id @@ -347,7 +359,6 @@ is_public = property(**is_public()) -post_save.connect(Content.create_front_project, sender=Content) class Project(Document, SafeModel): @@ -430,14 +441,15 @@ assign('change_project', user, project) for content in contents: - project.add_contents([content]) + project.add_contents([content]) if set_icon: project.set_icon() project.save() - + return create_ldt(project, user, cuttings) + def copy_project(self, user, title, description='', group=None): project = Project(title=title, owner=user, description=description) project = copy_ldt(self, project, user) @@ -449,12 +461,14 @@ project.add_contents([content]) return project - def publish(self): + def publish(self, allow_write=False): if not self.pk: self.save() self.state = 2 everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME) assign('ldt_utils.view_project', everyone, self) + if allow_write: + assign('ldt_utils.change_project', everyone, self) self.save() def unpublish(self): @@ -463,8 +477,10 @@ self.state = 1 everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME) remove_perm('ldt_utils.view_project', everyone, self) + remove_perm('ldt_utils.change_project', everyone, self) self.save() + def set_icon(self): default_image = os.path.basename(settings.DEFAULT_CONTENT_ICON) @@ -496,6 +512,9 @@ content = models.ForeignKey(Content) stat = models.CommaSeparatedIntegerField(max_length=1024, null=True, blank=True, verbose_name=_("content.stat_annotation")) nb_annotation = models.IntegerField(default=0, verbose_name=_("content.nb_annotation")) + + def __unicode__(self): + return "%s::%s" % (self.project.ldt_id, self.content.iri_id) class Segment(SafeModel): diff -r a99ea8eb8b9a -r 0e410517b311 src/ldt/ldt/ldt_utils/stat.py --- a/src/ldt/ldt/ldt_utils/stat.py Fri Jan 13 14:25:18 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/stat.py Fri Jan 13 16:57:01 2012 +0100 @@ -88,8 +88,10 @@ contributions = AnnotationStat.objects.filter(project=instance) for c in contributions: - content = contents.get(id=c.content.id) - content.nb_annotation -= c.nb_annotation + 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) diff -r a99ea8eb8b9a -r 0e410517b311 src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_content.html --- a/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_content.html Fri Jan 13 14:25:18 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_content.html Fri Jan 13 16:57:01 2012 +0100 @@ -56,6 +56,10 @@ }); public_checkbox($("#public input")); + + if ('{{form_status}}' == 'empty') { + resize_modal_window($("#add_content")); + } }); diff -r a99ea8eb8b9a -r 0e410517b311 src/ldt/ldt/ldt_utils/views/content.py --- a/src/ldt/ldt/ldt_utils/views/content.py Fri Jan 13 14:25:18 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/views/content.py Fri Jan 13 16:57:01 2012 +0100 @@ -10,8 +10,8 @@ from django.utils.translation import ugettext as _, ungettext from ldt.ldt_utils.forms import ContentForm, MediaForm from guardian.shortcuts import remove_perm -from ldt.ldt_utils.models import Content, Media, Project -from ldt.security.utils import assign_perm_to_obj, add_change_attr, get_userlist, get_userlist_model, get_userlist_group +from ldt.ldt_utils.models import Content, Media +from ldt.security.utils import assign_perm_to_obj, add_change_attr, get_userlist, get_userlist_model from ldt.security.cache import cached_assign from ldt.user.forms import PictureForm from urllib2 import urlparse diff -r a99ea8eb8b9a -r 0e410517b311 src/ldt/ldt/ldt_utils/views/group.py --- a/src/ldt/ldt/ldt_utils/views/group.py Fri Jan 13 14:25:18 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/views/group.py Fri Jan 13 16:57:01 2012 +0100 @@ -20,8 +20,7 @@ project_list = get_objects_for_user(request.user, 'ldt_utils.view_project', use_groups=False).exclude(owner=request.user) else: grp = Group.objects.get(id=grp_id) - everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME) - project_list = get_objects_for_group(grp, 'ldt_utils.view_project') | get_objects_for_group(everyone, 'ldt_utils.view_project').filter(owner__in=[grp]) + project_list = get_objects_for_group(grp, 'ldt_utils.view_project').exclude(title__startswith='front') project_list = add_change_attr(request.user, project_list) diff -r a99ea8eb8b9a -r 0e410517b311 src/ldt/ldt/ldt_utils/views/project.py --- a/src/ldt/ldt/ldt_utils/views/project.py Fri Jan 13 14:25:18 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/views/project.py Fri Jan 13 16:57:01 2012 +0100 @@ -198,6 +198,8 @@ 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 a99ea8eb8b9a -r 0e410517b311 src/ldt/ldt/ldt_utils/views/workspace.py --- a/src/ldt/ldt/ldt_utils/views/workspace.py Fri Jan 13 14:25:18 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/views/workspace.py Fri Jan 13 16:57:01 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)) #@UndefinedVariable + project_list = add_change_attr(request.user, Project.safe_objects.filter(owner=request.user).exclude(title__startswith='front')) #@UndefinedVariable is_gecko = ((request.META['HTTP_USER_AGENT'].lower().find("firefox")) > -1); @@ -74,7 +74,7 @@ def published_project(request): # get list of all published projects - project_list = Project.safe_objects.filter(state=2) #@UndefinedVariable + project_list = Project.safe_objects.filter(state=2).exclude(title__startswith='front') #@UndefinedVariable # Search form form = SearchForm() diff -r a99ea8eb8b9a -r 0e410517b311 src/ldt/ldt/security/__init__.py --- a/src/ldt/ldt/security/__init__.py Fri Jan 13 14:25:18 2012 +0100 +++ b/src/ldt/ldt/security/__init__.py Fri Jan 13 16:57:01 2012 +0100 @@ -36,6 +36,13 @@ get_anonymous_user.anonymous_user = User.objects.get(id=settings.ANONYMOUS_USER_ID) return get_anonymous_user.anonymous_user +def get_current_user_or_admin(): + current = get_current_user() + if current: + return current + admin = User.objects.filter(is_superuse=True)[0] + return admin + def protect_models(): cls_list = get_models_to_protect() if cls_list: @@ -62,27 +69,27 @@ return cls_list -def protect_model(cls): +def protect_model(cls): + if not hasattr(cls, 'unsafe_save'): + cls.unsafe_save = cls.save + cls.unsafe_delete = cls.delete + class_name = cls.__name__.lower() + cls.save = change_security(class_name)(cls.save) + cls.delete = change_security(class_name)(cls.delete) - cls.old_save = cls.save - cls.old_delete = cls.delete - class_name = cls.__name__.lower() - cls.save = change_security(class_name)(cls.save) - cls.delete = change_security(class_name)(cls.delete) - -def unprotect_model(cls): - if hasattr(cls, 'old_save'): - cls.save = cls.old_save - cls.delete = cls.old_delete - del cls.old_save - del cls.old_delete +def unprotect_model(cls): + if hasattr(cls, 'unsafe_save'): + cls.save = cls.unsafe_save + cls.delete = cls.unsafe_delete + del cls.unsafe_save + del cls.unsafe_delete cls.safe_objects.user = None cls.safe_objects.check_perm = False def change_security(cls_name): def wrapper(func): def wrapped(self, *args, **kwargs): - + if self.pk and not get_current_user().has_perm('change_%s' % cls_name, self): raise AttributeError('User %s is not allowed to change object %s' % (get_current_user(), self)) diff -r a99ea8eb8b9a -r 0e410517b311 src/ldt/ldt/static/ldt/js/projectscontents.js --- a/src/ldt/ldt/static/ldt/js/projectscontents.js Fri Jan 13 14:25:18 2012 +0100 +++ b/src/ldt/ldt/static/ldt/js/projectscontents.js Fri Jan 13 16:57:01 2012 +0100 @@ -180,7 +180,7 @@ filters: ['iframe'], sizes: { minW: 740, - minH: 550 + minH: 520 }, closeOnClick:false, callbacks: { @@ -196,7 +196,7 @@ }); nm.store.iframe.width(730); - nm.store.iframe.height(540); + nm.store.iframe.height(510); } } });