mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
* 12795 users.User migration * 12795 users.User migration * 12795 review changes * 12795 fix user model registration * 12795 fix user model registration * 12795 update migration * 12795 update migration * 12795 update migration * 12795 add comment to migration db_table * Tweak import to avoid class name collision * 12795 add comment for _register_features requirement --------- Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
49 lines
1.1 KiB
Python
49 lines
1.1 KiB
Python
from django import forms
|
|
from django.utils.translation import gettext as _
|
|
from users.models import *
|
|
from utilities.forms import CSVModelForm
|
|
|
|
|
|
__all__ = (
|
|
'GroupImportForm',
|
|
'UserImportForm',
|
|
'TokenImportForm',
|
|
)
|
|
|
|
|
|
class GroupImportForm(CSVModelForm):
|
|
|
|
class Meta:
|
|
model = NetBoxGroup
|
|
fields = (
|
|
'name',
|
|
)
|
|
|
|
|
|
class UserImportForm(CSVModelForm):
|
|
|
|
class Meta:
|
|
model = User
|
|
fields = (
|
|
'username', 'first_name', 'last_name', 'email', 'password', 'is_staff',
|
|
'is_active', 'is_superuser'
|
|
)
|
|
|
|
def save(self, *args, **kwargs):
|
|
# Set the hashed password
|
|
self.instance.set_password(self.cleaned_data.get('password'))
|
|
|
|
return super().save(*args, **kwargs)
|
|
|
|
|
|
class TokenImportForm(CSVModelForm):
|
|
key = forms.CharField(
|
|
label=_('Key'),
|
|
required=False,
|
|
help_text=_("If no key is provided, one will be generated automatically.")
|
|
)
|
|
|
|
class Meta:
|
|
model = Token
|
|
fields = ('user', 'key', 'write_enabled', 'expires', 'description',)
|