mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 07:09:16 +02:00
Initial commit that merge both the front end and the API in the same repository
This commit is contained in:
commit
76f98b74dd
285 changed files with 51318 additions and 0 deletions
38
api/funkwhale_api/users/admin.py
Normal file
38
api/funkwhale_api/users/admin.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django import forms
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.admin import UserAdmin as AuthUserAdmin
|
||||
from django.contrib.auth.forms import UserChangeForm, UserCreationForm
|
||||
|
||||
from .models import User
|
||||
|
||||
|
||||
class MyUserChangeForm(UserChangeForm):
|
||||
class Meta(UserChangeForm.Meta):
|
||||
model = User
|
||||
|
||||
|
||||
class MyUserCreationForm(UserCreationForm):
|
||||
|
||||
error_message = UserCreationForm.error_messages.update({
|
||||
'duplicate_username': 'This username has already been taken.'
|
||||
})
|
||||
|
||||
class Meta(UserCreationForm.Meta):
|
||||
model = User
|
||||
|
||||
def clean_username(self):
|
||||
username = self.cleaned_data["username"]
|
||||
try:
|
||||
User.objects.get(username=username)
|
||||
except User.DoesNotExist:
|
||||
return username
|
||||
raise forms.ValidationError(self.error_messages['duplicate_username'])
|
||||
|
||||
|
||||
@admin.register(User)
|
||||
class UserAdmin(AuthUserAdmin):
|
||||
form = MyUserChangeForm
|
||||
add_form = MyUserCreationForm
|
Loading…
Add table
Add a link
Reference in a new issue