def handle(self, *args, **options): apps = options.get('apps').split(',') if 'all' in apps: apps = self.all_apps if options.get('flush', False): self.stdout.write('Flush database..') call_command('flush', interactive=False) self.stdout.write('Flush finished.') self.generate_users_and_groups() if 'backoffice' in apps: self.generate_back_office() if 'datacenter' in apps: self.generate_data_center() if 'supports' in apps: self.generate_support() if 'licences' in apps: self.generate_licence() if 'transitions' in apps: self.generate_transitions() # Create super user root = UserFactory(username='******', is_superuser=True, is_staff=True) root.set_password('ralph') root.save() if options.get('flush', False): call_command('sitetree_resync_apps', interactive=False) self.stdout.write('done')
def add_user_and_group(username, password, group_name, permissions): group = GroupFactory(name=group_name) for codename in permissions: group.permissions.add( Permission.objects.get(codename=codename)) user = UserFactory(username=username, is_staff=True) user.regions.add(RegionFactory()) user.set_password(password) user.groups.add(group) user.save()
def add_user_and_group(username, password, group_name, permission_models): group = GroupFactory(name=group_name) for permision_model in permission_models: for perm in Permission.objects.filter( content_type=ContentType.objects.get_by_natural_key( *permision_model.split('.'))): group.permissions.add(perm) user = UserFactory(username=username, is_staff=True) user.regions.add(RegionFactory()) user.set_password(password) user.groups.add(group) user.save()