Change the way the autoadmin singleton is cleared up after the admin password change

This commit is contained in:
Roberto Rosario
2014-07-19 00:19:45 -04:00
parent 5c5885573b
commit a263a4640a

View File

@@ -5,7 +5,6 @@ import tempfile
from django.contrib.auth import models as auth_models from django.contrib.auth import models as auth_models
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.db import transaction, DatabaseError
from django.db.models.signals import post_save from django.db.models.signals import post_save
from django.dispatch import receiver from django.dispatch import receiver
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
@@ -66,14 +65,13 @@ def create_superuser_and_anonymous_user(sender, **kwargs):
@receiver(post_save, dispatch_uid='auto_admin_account_passwd_change', sender=User) @receiver(post_save, dispatch_uid='auto_admin_account_passwd_change', sender=User)
def auto_admin_account_passwd_change(sender, instance, **kwargs): def auto_admin_account_passwd_change(sender, instance, **kwargs):
try: auto_admin_properties = AutoAdminSingleton.objects.get()
with transaction.atomic(): if instance == auto_admin_properties.account and instance.password != auto_admin_properties.password_hash:
auto_admin_properties, created = AutoAdminSingleton.objects.get_or_create() # Only delete the auto admin properties when the password has been changed
if instance == auto_admin_properties.account and instance.password != auto_admin_properties.password_hash: auto_admin_properties.account = None
# Only delete the auto admin properties when the password has been changed auto_admin_properties.password = None
auto_admin_properties.delete(force=True) auto_admin_properties.password_hash = None
except DatabaseError: auto_admin_properties.save()
pass
if (not validate_path(TEMPORARY_DIRECTORY)) or (not TEMPORARY_DIRECTORY): if (not validate_path(TEMPORARY_DIRECTORY)) or (not TEMPORARY_DIRECTORY):