Sith/core/views/forms.py

74 lines
2.3 KiB
Python
Raw Normal View History

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
2015-11-22 17:23:21 +00:00
fields = ('first_name', 'last_name', 'email', 'date_of_birth')
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-02-05 15:59:42 +00:00
fields = ['groups', 'edit_groups', 'view_groups']
2015-12-14 09:49:15 +00:00
labels = {
2016-02-05 15:59:42 +00:00
'edit_groups': "Edit profile group",
'view_groups': "View profile group",
2015-12-14 09:49:15 +00:00
}
help_texts = {
2016-02-05 15:59:42 +00:00
'edit_groups': "Groups that can edit this user's profile",
'view_groups': "Groups that can view this user's profile",
2015-12-14 09:49:15 +00:00
'groups': "Which groups this user belongs to",
}
2015-11-26 15:32:56 +00:00
widgets = {
'groups': CheckboxSelectMultiple,
'user_permissions': CheckboxSelectMultiple,
2016-02-05 15:59:42 +00:00
'edit_groups': CheckboxSelectMultiple,
'view_groups': CheckboxSelectMultiple,
2015-11-26 15:32:56 +00:00
}
2015-11-24 13:01:10 +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', ]
widgets = {
2016-02-05 15:59:42 +00:00
'edit_groups': CheckboxSelectMultiple,
'view_groups': CheckboxSelectMultiple,
}
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
class GroupEditForm(forms.ModelForm):
error_css_class = 'error'
required_css_class = 'required'
class Meta:
2016-03-29 10:45:10 +00:00
model = RealGroup
fields = ['name', 'permissions',]
widgets = {
'permissions': CheckboxSelectMultiple,
}