Exemple #1
0
class PasswordChange(forms.Form):
    password = forms.CharField(max_length=32,
                               widget=html.PasswordInput())
    re_type = forms.CharField(max_length=32,
                              widget=html.PasswordInput(),
                              label="Re-enter password")

    def clean(self):
        if not self.user:
            raise forms.ValidationError('Not logged in')
        return self.double_check_password()

    def double_check_password(self):
        data     = self.cleaned_data
        password = data.get("password")
        re_type  = data.get("re_type")
        if password != re_type:
            errors = self.errors
            err = "Password didn't match. Please try again."
            if 're_type' in errors:
                errors["re_type"].append(err)
            else:
                errors["re_type"] = [err]
            try:
                del data["re_type"]
            except:
                pass
        return data
Exemple #2
0
 class testForm(forms.Form):
     entry1__color = forms.CharField()
     entry1__size = forms.IntegerField()
     entry2__color = forms.CharField()
     entry2__size = forms.IntegerField()
     entry3__color = forms.CharField()
     entry3__size = forms.IntegerField()
Exemple #3
0
class PageForm(forms.Form):
    '''Inline Editing Page form'''
    url = forms.CharField(initial='/')
    title = forms.CharField(label='Page title', required=False)
    link = forms.CharField(help_text='Text to display in links',
                           required=False)
    in_navigation = forms.IntegerField(
                        initial=0,
                        required=False,
                        label='position',
                        help_text="An integer greater or equal 0 used for "\
                                  " link ordering in menus. If zero the page "\
                                  "won't appear in naviagtions")
    layout = forms.ChoiceField(choices=get_layout_templates,
                               label='Page layout')
    inner_template = forms.ChoiceField(label='content grid',
                                       choices=grid_choices)
    grid_system = forms.ChoiceField(choices=grid_systems)
    soft_root = forms.BooleanField()
    doctype = forms.ChoiceField(choices=html_choices, initial=htmldefaultdoc)

    def clean_url(self, value):
        if self.mapper:
            try:
                page = self.mapper.get(url=value)
            except self.mapper.DoesNotExist:
                page = None
            if page and self.instance != page:
                raise forms.ValidationError('A page with url "{0}"\
 is already available'.format(value))
        else:
            raise forms.ValidationError('No page model defined.')
        return value
Exemple #4
0
class EditContentForm(forms.Form):
    '''Form used to edit and add Content'''
    title = forms.CharField()
    body = forms.CharField(widget=html.TextArea(cn=classes.taboverride,
                                                rows=30),
                           required=False)
    javascript = forms.CharField(widget=html.TextArea(cn=classes.taboverride,
                                                      rows=30),
                                 required=False)
    markup = forms.ChoiceField(choices=lambda bf: tuple(markups.choices()),
                               initial=lambda form: markups.default(),
                               required=False)
Exemple #5
0
class ModelLinksForm(forms.Form):
    size = forms.ChoiceField(choices=(('', 'standard'), (classes.button_large,
                                                         'large'),
                                      (classes.button_small, 'small')),
                             required=False)
    for_instance = forms.BooleanField()
    layout = forms.ChoiceField(choices=(('group left', 'group left'),
                                        ('group right', 'group right'),
                                        ('horizontal', 'horizontal'),
                                        ('vertical', 'vertical')))
    for_instance = forms.BooleanField()
    exclude = forms.CharField(max_length=600, required=False)
    include = forms.CharField(max_length=600, required=False)
Exemple #6
0
class ModelItemListForm(ForModelForm):
    max_display = forms.IntegerField(initial=10,
                                     widget=html.TextInput(cn='span1'))
    text_search = forms.CharField(required=False)
    filter = forms.CharField(required=False)
    exclude = forms.CharField(required=False)
    order_by = forms.ChoiceField(required=False,
                                 widget=html.Select(cn='model-fields'),
                                 choices=FieldChoices())
    descending = forms.BooleanField(initial=False)
    headers = forms.ChoiceField(required=False,
                                widget=html.Select(cn='model-fields'),
                                choices=FieldChoices(multiple=True))
    table_footer = forms.BooleanField(initial=False, label='footer')
    display_if_empty = forms.BooleanField(initial=False)
Exemple #7
0
class UserChangeForm(forms.Form):
    '''A form for editing the user details. This assume that the user
model has the fields in this form.'''
    first_name = forms.CharField(required=False)
    last_name = forms.CharField(required=False)
    email_address = forms.CharField(required=False)
    is_superuser = forms.BooleanField()
    is_active = forms.BooleanField(initial=True)

    def __init__(self, **kwargs):
        super(UserChangeForm, self).__init__(**kwargs)
        if not self.is_bound:
            user = self.user
            if not user or not user.is_superuser:
                self.dfields['is_superuser'].widget.addClass('hidden')
                self.dfields['is_active'].widget.addClass('hidden')
Exemple #8
0
class SimpleForm(forms.Form):
    name = forms.CharField(max_length=64)
    age = forms.IntegerField(default=lambda b: randint(10, 100))
    profession = forms.ChoiceField(choices=((1, 'student'),
                                            (2, 'professional'), (3,
                                                                  'artist')),
                                   required=False)
Exemple #9
0
class RegisterForm(PasswordChange):
    '''use this form for a simple user registration with *username*,
*password* and *password confirmation*.'''
    username = forms.CharField(max_length=32)
    #email_address = forms.CharField(
    #                    help_text="This will be used for confirmation only.")

    def clean_username(self, value):
        '''Username must be unique and without spaces'''
        value = value.replace(' ','').lower()
        if not value:
            raise forms.ValidationError('Please provide a username')
        elif self.mapper.filter(username=value):
            raise forms.ValidationError('Username "{0}" is not available.\
 Choose a different one.'.format(value))
        return value

    def clean(self):
        return self.double_check_password()

    def on_submit(self, commit):
        '''Create the new user.'''
        cd = self.cleaned_data
        pe = self.request.view.permissions
        return pe.create_user(username=cd['username'],
                              password=cd['password'])
Exemple #10
0
class ChatForm(forms.Form):
    text = forms.CharField(required=False, widget=html.TextArea())

    def on_submit(self, commit):
        if commit:
            text = self.cleaned_data.get('text')
            if text:
                user = self.request.user
                msg = json.dumps({'user': to_string(user), 'message': text})
                self.request.appmodel.publish('chat', msg)
        return True
Exemple #11
0
class LoginForm(forms.Form):
    '''The Standard login form
    '''
    username = forms.CharField(max_length=30,
                    widget=html.TextInput(cn='autocomplete-off'))
    password = forms.CharField(max_length=60, widget=html.PasswordInput())

    def clean(self):
        '''process login'''
        data = self.cleaned_data
        try:
            user = self.request.view.permissions.authenticate_and_login(
                                self.request.environ, **data)
            if user:
                data['user'] = user
                return
        except ValueError as e:
            raise forms.ValidationError(str(e))

        raise ValueError('No authentication backend available.')

    def on_submit(self, commit):
        return self.cleaned_data['user']
Exemple #12
0
def search_form(name='SearchForm',
                placeholder='search',
                input_name=None,
                submit=None,
                cn=None,
                choices=None,
                label='search text',
                deafult_style=uni.nolabel,
                on_submit=None,
                required=False,
                **kwargs):
    '''Create a new :class:`djpcms.forms.HtmlForm` for searching.

:parameter name: name of the :class:`Form`
:parameter placeholder: text for the ``placeholder`` input attribute.
:parameter submit: submit text. If not provided, the form will submit on enter
    key-stroke.
:parameter cn: additional class names for the input element in the form.
'''
    submit = submit or ()
    input_name = input_name or forms.SEARCH_STRING
    widget = html.TextInput(placeholder=placeholder, cn=cn)
    if not submit:
        widget.addData('options', {'submit': True})
        layout = uni.FormLayout(default_style=deafult_style)
    else:
        submit = ((submit, 'search'), )
        layout = uni.FormLayout(uni.Inlineset(input_name, uni.SUBMITS),
                                default_style=deafult_style)
    if choices:
        field = forms.ChoiceField(attrname=input_name,
                                  label=label,
                                  required=required,
                                  choices=choices,
                                  widget=widget)
    else:
        field = forms.CharField(attrname=input_name,
                                label=label,
                                required=required,
                                widget=widget)
    form_cls = forms.MakeForm(name, (field, ), on_submit=on_submit)

    return forms.HtmlForm(form_cls, inputs=submit, layout=layout, **kwargs)
Exemple #13
0
class ContentBlockForm(forms.Form):
    '''Form for editing a content block within a page.'''
    url = forms.HiddenField(required=False)
    title = forms.CharField(required=False)
    plugin_name = PluginChoice(label='Plugin', choices=plugins.plugingenerator)
    container_type = forms.ChoiceField(
        label='Container',
        widget=html.Select(cn='ajax'),
        choices=plugins.wrappergenerator,
        help_text='A HTML element which wraps the plugin\
 before it is rendered in the page.')
    for_not_authenticated = forms.BooleanField(default=False)

    def on_submit(self, commit):
        data = self.cleaned_data
        pt = data.pop('plugin_name')
        instance = self.instance
        instance.plugin_name = pt.name if pt else ''
        if 'container_type' in data:
            instance.container_type = data['container_type']
Exemple #14
0
class PortfolioApplicationForm(forms.Form):
    api_url = forms.CharField()
    height = forms.IntegerField(initial=0, required=False)
Exemple #15
0
class DataForm(forms.Form):
    city = forms.CharField(max_length=64)
    date_of_birth = forms.DateField()

    simple = SimpleForm
Exemple #16
0
class EcoForm(forms.Form):
    path = forms.CharField()
    default_show = forms.BooleanField(initial=True, required=False)
    height = forms.IntegerField()
Exemple #17
0
class ContactForm(forms.Form):
    name = forms.CharField(max_length=100)
    email = forms.CharField(max_length=200, label='E-mail')
    subj = forms.CharField(max_length=100, required=False, label='Subject')
    body = forms.CharField(widget=html.TextArea(), label='Message')

    def __init__(self, *args, **kwargs):
        self.send_message = kwargs.pop('send_message', None)
        if self.send_message is None:
            raise TypeError("Keyword argument 'send_message' must be supplied")
        super(ContactForm, self).__init__(*args, **kwargs)

    _context = None

    template_name = ('bits/contact_form_message.txt',
                     'djpcms/bits/contact_form_message.txt')

    subject_template_name = ('bits/contact_form_subject.txt',
                             'djpcms/bits/contact_form_subject.txt')

    def message(self):
        """
        Renders the body of the message to a string.

        """
        if callable(self.template_name):
            template_name = self.template_name()
        else:
            template_name = self.template_name
        return loader.render_to_string(template_name, self.get_context())

    def subject(self):
        """
        Renders the subject of the message to a string.

        """
        subject = loader.render_to_string(self.subject_template_name,
                                          self.get_context())
        return ''.join(subject.splitlines())

    def get_context(self):
        if self._context is None:
            self._context = RequestContext(
                self.request,
                dict(self.cleaned_data, site=Site.objects.get_current()))
        return self._context

    def get_message_dict(self):
        if not self.is_valid():
            raise ValueError(
                "Message cannot be sent from invalid contact form")
        message_dict = {}
        for message_part in ('from_email', 'message', 'recipient_list',
                             'subject'):
            attr = getattr(self, message_part)
            message_dict[message_part] = callable(attr) and attr() or attr
        return message_dict

    def on_submit(self, commit):
        """Builds and sends the email message."""
        return send_mail(fail_silently=self.fail_silently,
                         **self.get_message_dict())
Exemple #18
0
 class Form(forms.Form):
     field1 = forms.CharField()
     field2 = forms.CharField()
     field3 = forms.CharField()
Exemple #19
0
class TemplateForm(forms.Form):
    name = forms.CharField()
    template = forms.CharField(widget=html.TextArea())
Exemple #20
0
class EcoForm(forms.Form):
    height = forms.IntegerField()
    service_url = forms.CharField(required=False)
    method = forms.ChoiceField(choices=(('get', 'get'), ('post', 'post')),
                               default='get')
Exemple #21
0
class SearchModelForm(FormModelForm):
    autocomplete = forms.BooleanField()
    multiple = forms.BooleanField(initial=True)
    tooltip = forms.CharField(required=False, max_length=50)