mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-06 00:49:38 +00:00
870d0b9697
Works on #55
64 lines
1.6 KiB
Python
64 lines
1.6 KiB
Python
''' usin django model forms '''
|
|
from django.core.validators import MaxValueValidator, MinValueValidator
|
|
from django.forms import ModelForm, PasswordInput, IntegerField
|
|
|
|
from fedireads import models
|
|
|
|
|
|
class LoginForm(ModelForm):
|
|
class Meta:
|
|
model = models.User
|
|
fields = ['username', 'password']
|
|
help_texts = {f: None for f in fields}
|
|
widgets = {
|
|
'password': PasswordInput(),
|
|
}
|
|
|
|
|
|
class RegisterForm(ModelForm):
|
|
class Meta:
|
|
model = models.User
|
|
fields = ['username', 'email', 'password']
|
|
help_texts = {f: None for f in fields}
|
|
widgets = {
|
|
'password': PasswordInput(),
|
|
}
|
|
|
|
|
|
class ReviewForm(ModelForm):
|
|
class Meta:
|
|
model = models.Review
|
|
fields = ['name', 'content', 'rating']
|
|
help_texts = {f: None for f in fields}
|
|
review_content = IntegerField(validators=[
|
|
MinValueValidator(0), MaxValueValidator(5)
|
|
])
|
|
labels = {
|
|
'name': 'Title',
|
|
'review_content': 'Review',
|
|
'rating': 'Rating (out of 5)',
|
|
}
|
|
|
|
|
|
class CommentForm(ModelForm):
|
|
class Meta:
|
|
model = models.Status
|
|
fields = ['content']
|
|
help_texts = {f: None for f in fields}
|
|
labels = {'content': 'Comment'}
|
|
|
|
|
|
class EditUserForm(ModelForm):
|
|
class Meta:
|
|
model = models.User
|
|
fields = ['avatar', 'name', 'summary']
|
|
help_texts = {f: None for f in fields}
|
|
|
|
|
|
class TagForm(ModelForm):
|
|
class Meta:
|
|
model = models.Tag
|
|
fields = ['name']
|
|
help_texts = {f: None for f in fields}
|
|
labels = {'name': 'Add a tag'}
|
|
|