Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement per site restriction for users
- Loading branch information
Showing
11 changed files
with
326 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# -*- coding: utf-8 -*- | ||
from django.contrib import admin | ||
from django.contrib.auth.admin import UserAdmin | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
from .models import CustomUser | ||
|
||
|
||
class CustomUserAdmin(UserAdmin): | ||
model = CustomUser | ||
|
||
|
||
fieldsets = ( | ||
(None, {'fields': ('username', 'password')}), | ||
(_('Personal info'), {'fields': ('first_name', 'last_name', 'email')}), | ||
(_('Permissions'), {'fields': ('is_active', 'is_staff', 'is_superuser', | ||
'groups', 'user_permissions')}), | ||
(_('Important dates'), {'fields': ('last_login', 'date_joined')}), | ||
(_('Sites'), {'fields': ('sites',)}) | ||
) | ||
|
||
admin.site.register(CustomUser, CustomUserAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.core.validators | ||
import django.utils.timezone | ||
import django.contrib.auth.models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('auth', '0006_require_contenttypes_0002'), | ||
('sites', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='CustomUser', | ||
fields=[ | ||
('id', models.AutoField(serialize=False, auto_created=True, primary_key=True, verbose_name='ID')), | ||
('password', models.CharField(verbose_name='password', max_length=128)), | ||
('last_login', models.DateTimeField(verbose_name='last login', null=True, blank=True)), | ||
('is_superuser', models.BooleanField(verbose_name='superuser status', help_text='Designates that this user has all permissions without explicitly assigning them.', default=False)), | ||
('username', models.CharField(help_text='Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only.', unique=True, verbose_name='username', validators=[django.core.validators.RegexValidator('^[\\w.@+-]+$', 'Enter a valid username. This value may contain only letters, numbers and @/./+/-/_ characters.', 'invalid')], max_length=30, error_messages={'unique': 'A user with that username already exists.'})), | ||
('first_name', models.CharField(verbose_name='first name', max_length=30, blank=True)), | ||
('last_name', models.CharField(verbose_name='last name', max_length=30, blank=True)), | ||
('email', models.EmailField(verbose_name='email address', max_length=254, blank=True)), | ||
('is_staff', models.BooleanField(verbose_name='staff status', help_text='Designates whether the user can log into this admin site.', default=False)), | ||
('is_active', models.BooleanField(verbose_name='active', help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', default=True)), | ||
('date_joined', models.DateTimeField(verbose_name='date joined', default=django.utils.timezone.now)), | ||
('groups', models.ManyToManyField(help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_query_name='user', related_name='user_set', verbose_name='groups', blank=True, to='auth.Group')), | ||
('sites', models.ManyToManyField(to='sites.Site')), | ||
('user_permissions', models.ManyToManyField(help_text='Specific permissions for this user.', related_query_name='user', related_name='user_set', verbose_name='user permissions', blank=True, to='auth.Permission')), | ||
], | ||
options={ | ||
'verbose_name': 'user', | ||
'abstract': False, | ||
'verbose_name_plural': 'users', | ||
}, | ||
managers=[ | ||
('objects', django.contrib.auth.models.UserManager()), | ||
], | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,10 @@ | ||
# -*- coding: utf-8 -*- | ||
from django.contrib.auth.models import AbstractUser | ||
from django.db import models | ||
|
||
|
||
class CustomUser(AbstractUser): | ||
sites = models.ManyToManyField('sites.Site') | ||
|
||
def get_sites(self): | ||
return self.sites |
Oops, something went wrong.