Dynastie/dynastie/forms.py

66 lines
2.2 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
"""
2014-01-04 13:55:30 +01:00
Copyright 2012-2014 Grégory Soutadé
This file is part of Dynastie.
Dynastie is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Dynastie is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Dynastie. If not, see <http://www.gnu.org/licenses/>.
"""
2012-07-08 16:23:39 +02:00
from django.forms import ModelForm
from django import forms
2012-07-08 16:23:39 +02:00
from dynastie.models import *
class BlogForm(ModelForm):
class Meta:
model = Blog
2015-09-21 19:05:25 +02:00
exclude = ()
2012-07-08 16:23:39 +02:00
2012-08-28 09:09:14 +02:00
class PostForm(ModelForm):
description = forms.CharField(widget=forms.Textarea(attrs={'rows':'5', 'cols':'50'}), required=False)
keywords = forms.CharField(widget=forms.Textarea(attrs={'rows':'2', 'cols':'50'}), required=False)
text_tags = forms.CharField(widget=forms.Textarea(attrs={'rows':'2', 'cols':'50'}), required=False)
2012-07-08 16:23:39 +02:00
class Meta:
2012-08-28 09:09:14 +02:00
model = Post
2014-01-04 13:43:38 +01:00
exclude = ('title_slug', 'creation_date', 'modification_date', 'author', 'blog', 'tags', 'content_format')
2012-07-08 16:23:39 +02:00
def __init__(self, *args, **kwargs):
2012-08-28 09:09:14 +02:00
super(PostForm, self).__init__(*args, **kwargs)
2012-07-08 16:23:39 +02:00
self.fields['category'].choices = [(cat.id, cat.name) for cat in Category.objects.all()]
2014-05-27 18:24:14 +02:00
class DraftForm(PostForm):
class Meta:
model = Draft
exclude = ('title_slug', 'creation_date', 'modification_date', 'author', 'blog', 'tags', 'content_format', 'published')
2012-07-08 16:23:39 +02:00
class CategoryForm(ModelForm):
class Meta:
model = Category
2012-10-09 20:47:12 +02:00
exclude = ('parent', 'name_slug', 'blog')
2012-07-08 16:23:39 +02:00
class UserForm(ModelForm):
class Meta:
model = User
2015-09-21 19:05:25 +02:00
exclude = ('groups', 'user_permissions', 'date_joined')
2012-10-04 21:49:33 +02:00
class CommentForm(ModelForm):
class Meta:
model = Comment
exclude = ('post', 'parent', 'date')
class TagForm(ModelForm):
class Meta:
model = Tag
exclude = ('blog', 'name_slug')