Fix bugs in content creation form
authorverrierj
Thu, 02 Feb 2012 15:16:24 +0100
changeset 505 a345016af821
parent 504 32a878a71a80
child 506 8dc3043a7470
Fix bugs in content creation form
src/ldt/ldt/ldt_utils/models.py
src/ldt/ldt/ldt_utils/views/content.py
--- a/src/ldt/ldt/ldt_utils/models.py	Thu Feb 02 14:14:06 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/models.py	Thu Feb 02 15:16:24 2012 +0100
@@ -224,9 +224,7 @@
             create_front_project = True
             
             if not self.nb_annotation:
-                self.nb_annotation = 0
-            if not self.stat_annotation:
-                self.stat_annotation = ('0,' * settings.DIVISIONS_FOR_STAT_ANNOTATION)[:-1]     
+                self.nb_annotation = 0    
 
         super(Content, self).save(*args, **kwargs)
         
@@ -403,12 +401,16 @@
 
     def __make_getter(self, i):
         def inner_getter(self):
+            if not self.stat_annotation:
+                self.stat_annotation =  self.__list2str([0] * (settings.DIVISIONS_FOR_STAT_ANNOTATION + len(settings.SYNTAX.keys())))
             l = self.__str2list(self.stat_annotation)
             return l[Content.__pol_indices[i]]
         return inner_getter
     
     def __make_setter(self, i):
         def inner_setter(self, value):
+            if not self.stat_annotation:
+                self.stat_annotation =  self.__list2str([0] * (settings.DIVISIONS_FOR_STAT_ANNOTATION + len(settings.SYNTAX.keys())))
             l = self.__str2list(self.stat_annotation)
             l[Content.__pol_indices[i]] = value
             self.stat_annotation = self.__list2str(l)
--- a/src/ldt/ldt/ldt_utils/views/content.py	Thu Feb 02 14:14:06 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/views/content.py	Thu Feb 02 15:16:24 2012 +0100
@@ -211,15 +211,19 @@
                 
                 if not created:
                     content.save() # Check if user is allowed to change object before assigning permissions.
+
                 cached_assign('change_content', request.user, content)
                 cached_assign('view_content', request.user, content)
                 everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME)
+                print content_form.cleaned_data
+                
                 if content_form.cleaned_data['is_public']:
                     cached_assign('view_content', everyone, content)
                     if media:
                         cached_assign('view_media', everyone, media)
-                elif content_form.cleaned_data["share"]:
+                else:
                     remove_perm('view_content', everyone, content)
+                    remove_perm('view_media', everyone, media)
                     assign_perm_to_obj(content, content_form.cleaned_data['read_list'], content_form.cleaned_data['write_list'], request.user)
                     if media:
                         assign_perm_to_obj(media, content_form.cleaned_data['read_list'], content_form.cleaned_data['write_list'], request.user)
@@ -230,7 +234,6 @@
                     if request.user.is_staff and content_defaults.has_key('front_project'):
                         content.front_project = content_defaults['front_project']
                 content.save()
-               
                 picture_form.model = content
                 picture_form.save()