Skip to main content

Authentication provider for Solarlux Auth Service.

Project description

Consult the django-project-template on how to use it.

Upgrade from 1.7 to 1.8

In 1.8 there is a new username column introduced which removes unique identification responsibility from the email column. To migrate existing users and populate the DB sucessfully add the following script to your migrations. Fix the model name as needed and update the dependency to the last previous migration.

Afterwards run makemigrations as usual to update other fields.

populate username migration:

import django.contrib.auth.validators
from django.db import migrations, models
from django.db.models import Count


def populate_usernames(apps, schema_editor):
        User = apps.get_model('app', 'User')

        for grp in User.objects.exclude(um_id__isnull=True).values('um_id').annotate(ct=Count('um_id')):
                if grp['ct'] > 1:
                        User.objects.filter(um_id=grp['um_id']).update(um_id=None)

        for u in User.objects.all():
                if u.um_id:
                        u.username = 'um_%s' % u.um_id
                else:
                        u.username = 'user_%s' % u.id
                u.save()


class Migration(migrations.Migration):

        dependencies = [
                ('app', '0009_auto_20180208_1339'),
        ]

        operations = [
                migrations.AddField(
                        model_name='user',
                        name='username',
                        field=models.CharField(null=True,
                                                                   help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.',
                                                                   max_length=150, unique=False,
                                                                   validators=[django.contrib.auth.validators.UnicodeUsernameValidator()],
                                                                   verbose_name='username'),
                ),
                migrations.RunPython(populate_usernames),
                migrations.AlterField(
                        model_name='user',
                        name='username',
                        field=models.CharField(error_messages={'unique': 'A user with that username already exists.'},
                                                                   help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.',
                                                                   max_length=150, unique=True,
                                                                   validators=[django.contrib.auth.validators.UnicodeUsernameValidator()],
                                                                   verbose_name='username'),
                )
        ]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-slxauth-1.16.2.tar.gz (15.4 kB view details)

Uploaded Source

File details

Details for the file django-slxauth-1.16.2.tar.gz.

File metadata

  • Download URL: django-slxauth-1.16.2.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.15

File hashes

Hashes for django-slxauth-1.16.2.tar.gz
Algorithm Hash digest
SHA256 fda33e318ef21291c925faf0a6d34e2bf0d3c2856734ee1f3670911c2b28961b
MD5 f06532508cad301edbad8ad9c6d7b980
BLAKE2b-256 b89e12e491d07973b584a4217e99c1709e140420fa317cdfb9fcd18cd728a4ac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page