Sith/core/views/forms.py

65 lines
2.0 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
from core.models import User, Page, Group
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-11-26 15:32:56 +00:00
class UserGroupsForm(forms.ModelForm):
2015-11-24 13:01:10 +00:00
error_css_class = 'error'
required_css_class = 'required'
class Meta:
model = User
fields = ['edit_group', 'view_group', 'groups', 'user_permissions',]
2015-11-26 15:32:56 +00:00
widgets = {
'groups': CheckboxSelectMultiple,
'user_permissions': CheckboxSelectMultiple,
'edit_group': CheckboxSelectMultiple,
'view_group': 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
fields = ['parent', 'name', 'owner_group', 'edit_group', 'view_group', ]
widgets = {
'edit_group': CheckboxSelectMultiple,
'view_group': CheckboxSelectMultiple,
}
2015-11-27 15:09:47 +00:00
def __init__(self, *arg, **kwargs):
super(PagePropForm, self).__init__(*arg, **kwargs)
self.fields['edit_group'].required = False
self.fields['view_group'].required = False
class GroupEditForm(forms.ModelForm):
error_css_class = 'error'
required_css_class = 'required'
class Meta:
model = Group
fields = ['name', 'permissions',]
widgets = {
'permissions': CheckboxSelectMultiple,
}