Module todo.forms
Expand source code
# MIT License
# Copyright © 2024 Akarsh Reddy Eathamukkala
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the “Software”), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to
# do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
class UpdateItemTextForm(forms.Form):
item_text = forms.Textarea()
# hidden_item_id = forms.CharField(label=)
class NewUserForm(UserCreationForm):
email = forms.EmailField(required=True)
class Meta:
model = User
fields = ("username", "email", "password1", "password2")
def save(self, commit=True):
user = super(NewUserForm, self).save(commit=False)
user.email = self.cleaned_data['email']
if commit:
user.save()
return user
Classes
class NewUserForm (*args, **kwargs)-
A form that creates a user, with no privileges, from the given username and password.
Expand source code
class NewUserForm(UserCreationForm): email = forms.EmailField(required=True) class Meta: model = User fields = ("username", "email", "password1", "password2") def save(self, commit=True): user = super(NewUserForm, self).save(commit=False) user.email = self.cleaned_data['email'] if commit: user.save() return userAncestors
- django.contrib.auth.forms.UserCreationForm
- django.forms.models.ModelForm
- django.forms.models.BaseModelForm
- django.forms.forms.BaseForm
- django.forms.utils.RenderableFormMixin
- django.forms.utils.RenderableMixin
Class variables
var Metavar base_fieldsvar declared_fields
Instance variables
var media-
Expand source code
def _media(self): # Get the media property of the superclass, if it exists sup_cls = super(cls, self) try: base = sup_cls.media except AttributeError: base = Media() # Get the media definition for this class definition = getattr(cls, "Media", None) if definition: extend = getattr(definition, "extend", True) if extend: if extend is True: m = base else: m = Media() for medium in extend: m = m + base[medium] return m + Media(definition) return Media(definition) return base
Methods
def save(self, commit=True)-
Save this form's self.instance object if commit=True. Otherwise, add a save_m2m() method to the form which can be called after the instance is saved manually at a later time. Return the model instance.
Expand source code
def save(self, commit=True): user = super(NewUserForm, self).save(commit=False) user.email = self.cleaned_data['email'] if commit: user.save() return user
class UpdateItemTextForm (data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=django.forms.utils.ErrorList, label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None)-
A collection of Fields, plus their associated data.
Expand source code
class UpdateItemTextForm(forms.Form): item_text = forms.Textarea() # hidden_item_id = forms.CharField(label=)Ancestors
- django.forms.forms.Form
- django.forms.forms.BaseForm
- django.forms.utils.RenderableFormMixin
- django.forms.utils.RenderableMixin
Class variables
var base_fieldsvar declared_fieldsvar item_text
Instance variables
var media-
Expand source code
def _media(self): # Get the media property of the superclass, if it exists sup_cls = super(cls, self) try: base = sup_cls.media except AttributeError: base = Media() # Get the media definition for this class definition = getattr(cls, "Media", None) if definition: extend = getattr(definition, "extend", True) if extend: if extend is True: m = base else: m = Media() for medium in extend: m = m + base[medium] return m + Media(definition) return Media(definition) return base