Re: Admin debugging delete

2015-12-20 Thread Mike Dewhirst

On 20/12/2015 4:30 PM, James Schneider wrote:


 > Â  Â  for instance in instances:
 > Â  Â  Â  Â  if not instance in self.deleted_objects:
 > Â  Â  Â  Â  Â  Â  instance.modified_by = request.user
 > Â  Â  Â  Â  Â  Â  instance.save()
 >
 > ... but that didn't do anything.

Shouldn't that be:

if instance not in self.deleted_objects:

I haven't tested this, but I think that will end up looking for False
(the 'not' applying to 'instance' rather than the 'in' operation) in
self.deleted_objects, which means saving would be broken entirely.


It certainly looks nicer. But it didn't break saving so I assume it 
means something like "if not " which expression happens 
to be ""


Your way is easier to read so I'll adopt it.

Thanks James




-James

--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to django-users+unsubscr...@googlegroups.com
.
To post to this group, send email to django-users@googlegroups.com
.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciUabE3ZjXaYjZFi7fui6J7%2BXTNLsyoFomOBzVQeWqQvZw%40mail.gmail.com
.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/567667D3.8040700%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet when using django-role-permission package

2015-12-20 Thread karim bernardet
Using the branch "django19" fixed the problem.
Sorry or the noise

Karim

Le dimanche 20 décembre 2015 00:06:38 UTC+1, karim bernardet a écrit :
>
> Hi
>
> I am a new user with Django. I am trying to use the django-role-permission 
> package but I have the error below :
>
> [karim@localhost gfmt]$ python ./manage.py check
> Traceback (most recent call last):
>   File "./manage.py", line 10, in 
> execute_from_command_line(sys.argv)
>   File 
> "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 
> 350, in execute_from_command_line
> utility.execute()
>   File 
> "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 
> 324, in execute
> django.setup()
>   File "/usr/lib/python2.7/site-packages/django/__init__.py", line 18, in 
> setup
> apps.populate(settings.INSTALLED_APPS)
>   File "/usr/lib/python2.7/site-packages/django/apps/registry.py", line 
> 85, in populate
> app_config = AppConfig.create(entry)
>   File "/usr/lib/python2.7/site-packages/django/apps/config.py", line 90, 
> in create
> module = import_module(entry)
>   File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in 
> import_module
> __import__(name)
>   File "/usr/lib/python2.7/site-packages/rolepermissions/__init__.py", 
> line 5, in 
> load_roles_and_permissions()
>   File "/usr/lib/python2.7/site-packages/rolepermissions/loader.py", line 
> 9, in load_roles_and_permissions
> import_module(settings.ROLEPERMISSIONS_MODULE)
>   File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in 
> import_module
> __import__(name)
>   File "/home/karim/django/projets/gfmt/gfmt/roles.py", line 2, in 
> from rolepermissions.roles import AbstractUserRole
>   File "/usr/lib/python2.7/site-packages/rolepermissions/roles.py", line 
> 5, in 
> from django.contrib.auth.models import Group, Permission
>   File "/usr/lib/python2.7/site-packages/django/contrib/auth/models.py", 
> line 4, in 
> from django.contrib.auth.base_user import AbstractBaseUser, 
> BaseUserManager
>   File 
> "/usr/lib/python2.7/site-packages/django/contrib/auth/base_user.py", line 
> 49, in 
> class AbstractBaseUser(models.Model):
>   File "/usr/lib/python2.7/site-packages/django/db/models/base.py", line 
> 94, in __new__
> app_config = apps.get_containing_app_config(module)
>   File "/usr/lib/python2.7/site-packages/django/apps/registry.py", line 
> 239, in get_containing_app_config
> self.check_apps_ready()
>   File "/usr/lib/python2.7/site-packages/django/apps/registry.py", line 
> 124, in check_apps_ready
> raise AppRegistryNotReady("Apps aren't loaded yet.")
> django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
> [karim@localhost gfmt]$ 
>
> In the settings.py file I have :
>
> ROLEPERMISSIONS_MODULE = 'gfmt.roles'
>
> # Application definition
>
> INSTALLED_APPS = [
> 'django.contrib.admin',
> 'django.contrib.auth',
>  'rolepermissions',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
> 'controlPanel',
> ]
>
> If I comment   'rolepermissions', or ROLEPERMISSIONS_MODULE = 
> 'gfmt.roles', it runs (but these lines are required)
> I dont know what to check 
>
> Thanks for any hint
>
> Cheers
>
> Karim
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8b934bc9-8805-4388-b9a1-a0aa31689e6b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Question re django.forms.models.BaseModelFormSet.save_existing_objects()

2015-12-20 Thread Mike Dewhirst
I have just been digging into django.forms.models.py to debug my own 
code and found something which confuses me in both 1.8 and 1.9


django.forms.models.BaseModelFormSet.save_existing_objects() puts 
objects (child model instances) into the 
BaseModelFormSet.deleted_objects list whether they are deleted or not.


Here is the 1.9 code (no need to show 1.8 because they are both more or 
less the same)


741def save_existing_objects(self, commit=True):
742self.changed_objects = []
743self.deleted_objects = []
744if not self.initial_forms:
745return []
746
747saved_instances = []
748forms_to_delete = self.deleted_forms
749for form in self.initial_forms:
750obj = form.instance
751if form in forms_to_delete:
752# If the pk is None, it means that the object can't be
753# deleted again. Possible reason for this is that the
754# object was already deleted from the DB. Refs #14877.
755if obj.pk is None:
756continue
757self.deleted_objects.append(obj)
758self.delete_existing(obj, commit=commit)
759elif form.has_changed():
760self.changed_objects.append((obj, form.changed_data))
761saved_instances.append(self.save_existing(form, obj, 
commit=commit))

762if not commit:
763self.saved_forms.append(form)
764return saved_instances

Line 758 will fail and the object will not be deleted if commit == False 
but line 757 has already added the object to a list.


Is this intended?

Thanks

Mike


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5676A047.108%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Por que Django não é tão popular quanto Ruby on Rails?

2015-12-20 Thread Diego Matar
Por favor, alguém pode dar uma boa resposta para esta pergunta lá no Qanda:

>> Por que Django não é tão popular quanto Ruby on Rails? 


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/228a71ea-3d49-4078-ac91-22d5c709cd20%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Admin debugging delete

2015-12-20 Thread James Schneider
> I haven't tested this, but I think that will end up looking for False
>> (the 'not' applying to 'instance' rather than the 'in' operation) in
>> self.deleted_objects, which means saving would be broken entirely.
>>
>
> It certainly looks nicer. But it didn't break saving so I assume it means
> something like "if not " which expression happens to be
> ""
>

Agreed. And I did finally get a chance to test this in the interpreter with
the same result. There's gotta be some implicit action going on that counts
the 'in' as a whole expression, and not taking 'instance' as an individual
object, because my dusty algebra brain is kicking and saying that without
() to sort out the order, the 'not' should apply only to 'instance'. I even
looked it up in the docs and 'not x' has a higher operator precedence than
'in', only feeding my confusion.


> Your way is easier to read so I'll adopt it.
>

I've never seen it written out the way you had it, before.

I'll agree with that. ;-D

-James

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciXJVVTs8gpt1p978qpQNgduGDU582-99bXKo5y2BZVEUQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Question re django.forms.models.BaseModelFormSet.save_existing_objects()

2015-12-20 Thread James Schneider
>
> I have just been digging into django.forms.models.py to debug my own code
> and found something which confuses me in both 1.8 and 1.9
>
> django.forms.models.BaseModelFormSet.save_existing_objects() puts objects
> (child model instances) into the BaseModelFormSet.deleted_objects list
> whether they are deleted or not.
>
> Here is the 1.9 code (no need to show 1.8 because they are both more or
> less the same)
>
> 741def save_existing_objects(self, commit=True):
> 742self.changed_objects = []
> 743self.deleted_objects = []
> 744if not self.initial_forms:
> 745return []
> 746
> 747saved_instances = []
> 748forms_to_delete = self.deleted_forms
> 749for form in self.initial_forms:
> 750obj = form.instance
> 751if form in forms_to_delete:
> 752# If the pk is None, it means that the object can't be
> 753# deleted again. Possible reason for this is that the
> 754# object was already deleted from the DB. Refs #14877.
> 755if obj.pk is None:
> 756continue
> 757self.deleted_objects.append(obj)
> 758self.delete_existing(obj, commit=commit)
> 759elif form.has_changed():
> 760self.changed_objects.append((obj, form.changed_data))
> 761saved_instances.append(self.save_existing(form, obj,
> commit=commit))
> 762if not commit:
> 763self.saved_forms.append(form)
> 764return saved_instances
>
> Line 758 will fail and the object will not be deleted if commit == False
> but line 757 has already added the object to a list.
>
> Is this intended?
>

Wouldn't L757 only get executed if L751 has already determined that the
particular object/form is supposed to be deleted, meaning that
self.deleted_objects would only contain objects/forms that were supposed to
be deleted?

-James

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciWaSsBQ-5EvhpkT0MJmcGM1KTt2y%2Bnw2BQ6p%2BHEUd8Rqg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Question re django.forms.models.BaseModelFormSet.save_existing_objects()

2015-12-20 Thread Mike Dewhirst

On 21/12/2015 6:10 PM, James Schneider wrote:

I have just been digging into django.forms.models.py
 to debug my own code and found
something which confuses me in both 1.8 and 1.9

django.forms.models.BaseModelFormSet.save_existing_objects() puts
objects (child model instances) into the
BaseModelFormSet.deleted_objects list whether they are deleted or not.

Here is the 1.9 code (no need to show 1.8 because they are both more
or less the same)

741def save_existing_objects(self, commit=True):
742self.changed_objects = []
743self.deleted_objects = []
744if not self.initial_forms:
745return []
746
747saved_instances = []
748forms_to_delete = self.deleted_forms
749for form in self.initial_forms:
750obj = form.instance
751if form in forms_to_delete:
752# If the pk is None, it means that the
object can't be
753# deleted again. Possible reason for this
is that the
754# object was already deleted from the DB.
Refs #14877.
755if obj.pk  is None:
756continue
757self.deleted_objects.append(obj)
758self.delete_existing(obj, commit=commit)
759elif form.has_changed():
760self.changed_objects.append((obj,
form.changed_data))
761
saved_instances.append(self.save_existing(form, obj, commit=commit))
762if not commit:
763self.saved_forms.append(form)
764return saved_instances

Line 758 will fail and the object will not be deleted if commit ==
False but line 757 has already added the object to a list.

Is this intended?


Wouldn't L757 only get executed if L751 has already determined that the
particular object/form is supposed to be deleted, meaning that
self.deleted_objects would only contain objects/forms that were supposed
to be deleted?


That is true. However, if commit was False that object wouldn't be 
deleted but it would still appear in the self.deleted_objects list. My 
concern - or more accurately lack of understanding - is that the object 
would remain in existence AND appear in the deleted list. This was 
precisely what happened in my project and which I was trying to debug.


The symptom in the Admin was a checked box for deleting a child record 
which stubbornly stayed there despite the Admin reporting a successful 
save.


Mike



-James

--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to django-users+unsubscr...@googlegroups.com
.
To post to this group, send email to django-users@googlegroups.com
.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciWaSsBQ-5EvhpkT0MJmcGM1KTt2y%2Bnw2BQ6p%2BHEUd8Rqg%40mail.gmail.com
.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5677A9CD.6090303%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: Admin debugging delete

2015-12-20 Thread Mike Dewhirst

On 21/12/2015 6:03 PM, James Schneider wrote:


I haven't tested this, but I think that will end up looking for
False
(the 'not' applying to 'instance' rather than the 'in' operation) in
self.deleted_objects, which means saving would be broken entirely.


It certainly looks nicer. But it didn't break saving so I assume it
means something like "if not " which expression
happens to be ""


Agreed. And I did finally get a chance to test this in the interpreter
with the same result. There's gotta be some implicit action going on
that counts the 'in' as a whole expression, and not taking 'instance' as
an individual object, because my dusty algebra brain is kicking and
saying that without () to sort out the order, the 'not' should apply
only to 'instance'. I even looked it up in the docs and 'not x' has a
higher operator precedence than 'in', only feeding my confusion.Â
Â

Your way is easier to read so I'll adopt it.


I've never seen it written out the way you had it, before.

I'll agree with that. ;-D


Now I think about it, I suspect your way (and now my preferred way) 
might have been an innovation for Python 3?


M



-James

--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to django-users+unsubscr...@googlegroups.com
.
To post to this group, send email to django-users@googlegroups.com
.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciXJVVTs8gpt1p978qpQNgduGDU582-99bXKo5y2BZVEUQ%40mail.gmail.com
.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5677AA77.50702%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.