2015-11-24 13:01:10 +00:00
|
|
|
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm, UserChangeForm
|
2015-11-18 16:09:06 +00:00
|
|
|
from django import forms
|
|
|
|
from django.contrib.auth import logout, login, authenticate
|
2015-11-26 15:32:56 +00:00
|
|
|
from django.forms import CheckboxSelectMultiple
|
2015-11-18 16:09:06 +00:00
|
|
|
import logging
|
|
|
|
|
2016-03-29 10:45:10 +00:00
|
|
|
from core.models import User, Page, RealGroup
|
2015-11-18 08:44:06 +00:00
|
|
|
|
|
|
|
class RegisteringForm(UserCreationForm):
|
|
|
|
error_css_class = 'error'
|
|
|
|
required_css_class = 'required'
|
|
|
|
class Meta:
|
|
|
|
model = User
|
2016-07-17 22:47:56 +00:00
|
|
|
fields = ('first_name', 'last_name', 'email')
|
2015-11-18 16:09:06 +00:00
|
|
|
|
|
|
|
def save(self, commit=True):
|
|
|
|
user = super(RegisteringForm, self).save(commit=False)
|
|
|
|
user.set_password(self.cleaned_data["password1"])
|
|
|
|
user.generate_username()
|
|
|
|
if commit:
|
|
|
|
user.save()
|
|
|
|
return user
|
|
|
|
|
|
|
|
|
2015-12-09 10:01:11 +00:00
|
|
|
class UserPropForm(forms.ModelForm):
|
2015-11-24 13:01:10 +00:00
|
|
|
error_css_class = 'error'
|
|
|
|
required_css_class = 'required'
|
|
|
|
class Meta:
|
|
|
|
model = User
|
2016-07-17 22:47:56 +00:00
|
|
|
fields = ['groups']
|
2015-12-14 09:49:15 +00:00
|
|
|
help_texts = {
|
|
|
|
'groups': "Which groups this user belongs to",
|
|
|
|
}
|
2015-11-26 15:32:56 +00:00
|
|
|
widgets = {
|
|
|
|
'groups': CheckboxSelectMultiple,
|
|
|
|
}
|
2015-11-24 13:01:10 +00:00
|
|
|
|
2015-11-27 14:39:42 +00:00
|
|
|
class PagePropForm(forms.ModelForm):
|
|
|
|
error_css_class = 'error'
|
|
|
|
required_css_class = 'required'
|
|
|
|
class Meta:
|
|
|
|
model = Page
|
2016-02-05 15:59:42 +00:00
|
|
|
fields = ['parent', 'name', 'owner_group', 'edit_groups', 'view_groups', ]
|
2015-11-27 14:39:42 +00:00
|
|
|
widgets = {
|
2016-02-05 15:59:42 +00:00
|
|
|
'edit_groups': CheckboxSelectMultiple,
|
|
|
|
'view_groups': CheckboxSelectMultiple,
|
2015-11-27 14:39:42 +00:00
|
|
|
}
|
|
|
|
|
2015-11-27 15:09:47 +00:00
|
|
|
def __init__(self, *arg, **kwargs):
|
|
|
|
super(PagePropForm, self).__init__(*arg, **kwargs)
|
2016-02-05 15:59:42 +00:00
|
|
|
self.fields['edit_groups'].required = False
|
|
|
|
self.fields['view_groups'].required = False
|
2015-11-27 15:09:47 +00:00
|
|
|
|