Exemplo n.º 1
0
class SimpleForm(Mixin1, Mixin):
    name = forms.CharField(minlength=2, maxlength=30)
    email = forms.CharField(required=False)
    rank = forms.IntegerField(required=False)
    dt = forms.DateField(required=False)
    timestamp = forms.DateTimeField(required=False)
    enum_field = forms.ChoiceField(required=False, options=TestEnum)
Exemplo n.º 2
0
class SimpleForm(forms.Form):
    name = forms.CharField()
    email = forms.CharField(required=False)
    rank = forms.IntegerField(required=False)
    dt = forms.DateField(required=False)
    timestamp = forms.DateTimeField(required=False)
    enum_field = forms.EnumField(required=False, enum_class=TestEnum)
Exemplo n.º 3
0
class TaskForm(forms.Form):
    model = 'tasks'
    subject = forms.CharField()
    done = forms.BooleanField(default=False)
    assigned = RelationshipField('people', required=False)
    enum_field = forms.ChoiceField(options=TestEnum, default='opt1')
    desc = forms.CharField(required=False)
Exemplo n.º 4
0
class UserForm(forms.Form):
    username = forms.CharField()
    email = forms.EmailField()
    first_name = forms.CharField(required=False)
    last_name = forms.CharField(required=False)
    superuser = forms.BooleanField()
    active = forms.BooleanField()
Exemplo n.º 5
0
class ProfileForm(EntityMixin):
    """Form for editing user profile on main website
    """
    username = forms.EmailField(readonly=True)
    email = forms.EmailField(required=False)
    first_name = forms.CharField(required=False)
    last_name = forms.CharField(required=False)
Exemplo n.º 6
0
class TextForm(forms.Form):
    title = forms.CharField()
    slug = forms.CharField(required=False,
                           max_length=SLUG_LENGTH)
    author = forms.CharField(required=False)
    body = forms.TextField(text_edit=json.dumps({'mode': 'markdown'}))
    tags = forms.CharField(required=False)
    published = forms.DateTimeField(required=False)
Exemplo n.º 7
0
class ApplicationForm(forms.Form):
    id = forms.CharField(readonly=True, required=False)
    name = forms.SlugField(minlength=2, maxlength=32, validator=UniqueField)
    domain = forms.CharField(minlength=2,
                             maxlength=120,
                             required=False,
                             validator=UniqueField)
    config = forms.JsonField(required=False, ace=json.dumps({'mode': 'json'}))
Exemplo n.º 8
0
class UserForm(forms.Form):
    username = forms.SlugField()
    email = forms.EmailField(required=False)
    first_name = forms.CharField(required=False)
    last_name = forms.CharField(required=False)
    superuser = forms.BooleanField()
    active = forms.BooleanField()
    joined = forms.DateTimeField(readonly=True, required=False)
    groups = RelationshipField('groups', multiple=True, required=False)
Exemplo n.º 9
0
class TestAForm1(forms.Form):
    name = forms.CharField()

    angular = forms.AngularLayout()

    angular2 = forms.AngularLayout(forms.AngularFieldset(all=True),
                                   forms.AngularSubmit('done'))
Exemplo n.º 10
0
class MailingListForm(forms.Form):
    email = forms.EmailField(label='Your email address', required=False)
    topic = forms.CharField(default=default_topic)

    def clean_email(self, email):
        user = self.request.cache.user
        if not email or user.email:
            raise forms.ValidationError('required')
        return email

    def clean(self):
        user = self.request.cache.user
        model = self.request.app.models['mailinglist']
        topic = self.cleaned_data['topic']
        with model.session(self.request) as session:
            query = model.get_query(session)
            if user.is_anonymous():
                if not user.is_authenticated():
                    raise Http401('Token')
                query.filter(email=self.cleaned_data['email'], topic=topic)
            else:
                self.cleaned_data['user'] = user
                query.filter(user=user, topic=topic)
            try:
                query.one()
            except Http404:
                pass
            else:
                raise forms.ValidationError('Already subscribed')
Exemplo n.º 11
0
class TaskForm(forms.Form):
    subject = forms.CharField(required=True)
    done = forms.BooleanField(default=False)
    assigned = odm.RelationshipField('person',
                                     label='assigned',
                                     required=False)
    enum_field = forms.EnumField(enum_class=TestEnum, default=TestEnum.opt1)
Exemplo n.º 12
0
class ContactForm(forms.Form):
    """
    The base contact form class from which all contact form classes
    should inherit.
    """
    name = forms.CharField(max_length=100, label='Your name')
    email = forms.EmailField(max_length=200, label='Your email address')
    body = forms.TextField(label='Your message', rows=10)
Exemplo n.º 13
0
class UpdateOrganisationForm(EntityMixin, forms.Form):
    model = 'organisations'
    full_name = forms.CharField(required=False)
    email_address = forms.EmailField(label='public email address',
                                     required=False)
    billing_email_address = forms.EmailField(
        label='Billing email',
        help_text='Receipts will be sent here',
        required=False)
Exemplo n.º 14
0
class PermissionForm(forms.Form):
    model = 'permission'
    id = forms.HiddenField(required=False)
    name = forms.CharField()
    description = forms.TextField()
    policy = forms.JsonField(text_edit=json.dumps({'mode': 'json'}))

    def clean(self):
        policy = self.cleaned_data['policy']
        self.cleaned_data['policy'] = validate_policy(policy)
Exemplo n.º 15
0
class PermissionForm(forms.Form):
    model = 'permissions'
    name = forms.CharField()
    description = forms.TextField(required=False, rows=2)
    policy = forms.JsonField(lux_ace=json.dumps({'mode': 'json'}))

    def clean(self):
        if 'policy' in self.cleaned_data:
            policy = self.cleaned_data['policy']
            self.cleaned_data['policy'] = validate_policy(policy)
Exemplo n.º 16
0
Arquivo: forms.py Projeto: tourist/lux
class CreateUserForm(PasswordForm):
    username = forms.CharField(required=True, minlength=6, maxlength=30)
    email = forms.EmailField(required=True)

    layout = forms.Layout(forms.Fieldset('username', 'email', 'password',
                                         'password_repeat'),
                          forms.Submit('Sign up',
                                       classes='btn btn-primary btn-block',
                                       disabled="form.$invalid"),
                          showLabels=False,
                          directive='user-form')
Exemplo n.º 17
0
Arquivo: forms.py Projeto: tourist/lux
class LoginForm(forms.Form):
    '''The Standard login form'''
    error_message = 'Incorrect username or password'
    username = forms.CharField(required=True, minlength=6, maxlength=30)
    password = forms.PasswordField(required=True, minlength=6, maxlength=128)

    layout = forms.Layout(forms.Fieldset(all=True),
                          forms.Submit('Login',
                                       classes='btn btn-primary btn-block',
                                       disabled="form.$invalid"),
                          showLabels=False)
Exemplo n.º 18
0
class ContentForm(forms.Form):
    content_type = forms.CharField()
    title = forms.CharField(required=True)
    slug = forms.HiddenField(required=False)


    layout = forms.Layout(forms.Fieldset('title', show_label=False),
                          forms.Fieldset('body', show_label=False))

    def value_from_instance(self, instance, name, value):
        if name == 'body':
            return instance.data.get('body', '')
        else:
            return getattr(instance, name, value)

    def clean(self):
        data = self.cleaned_data
        slug = data.get('slug')
        if not slug:
            self.cleaned_data['slug'] = slugify(data['title'].lower())
        data['data'] = {'body': data.pop('body', '')}
Exemplo n.º 19
0
class PageForm(forms.Form):
    path = forms.CharField(required=False)
    title = forms.CharField()
    description = forms.TextField(required=False)
    template = odm.RelationshipField(template_model, label='template')
    published = forms.BooleanField(required=False)
    layout = forms.JsonField(text_edit=json.dumps({'mode': 'json'}))

    def clean_layout(self, value):
        if not isinstance(value, dict):
            raise forms.ValidationError('Layout must be a dictionary')
        layout = {}
        if 'components' in value:
            components = value['components']
            if not isinstance(components, list):
                raise forms.ValidationError('componets must be a list')
            layout['components'] = components
        if 'rows' in value:
            rows = value['rows']
            if not isinstance(rows, list):
                raise forms.ValidationError('rows must be a list')
            layout['rows'] = rows
        return layout
Exemplo n.º 20
0
class LoginForm(forms.Form):
    '''The Standard login form'''
    error_message = 'Incorrect username or password'
    username = forms.CharField(max_length=30)
    password = forms.PasswordField(max_length=60)

    def clean(self):
        '''Process login'''
        request = self.request
        permissions = request.app.permissions
        username = self.cleaned_data['username']
        user = yield permissions.get_user(request, username=username)
        if not user:
            raise forms.ValidationError(self.error_message)
        password = self.cleaned_data['password']
        try:
            user = yield permissions.authenticate_and_login(request,
                                                            user,
                                                            password=password)
        except AuthenticationError:
            raise forms.ValidationError(self.error_message)
        except LoginError as e:
            raise forms.ValidationError(str(e))
        coroutine_return(user)
Exemplo n.º 21
0
class CreateProject(forms.Form):
    name = forms.SlugField(min_length=2,
                           max_length=32,
                           validator=ownership.UniqueField('projects'))
    subject = forms.CharField(max_length=250, required=False)
    private = forms.BooleanField()
Exemplo n.º 22
0
class PageForm(forms.Form):
    '''The form for editing and adding a new page to the CMS.'''
    url = forms.CharField(widget_attrs={'readonly': 'readonly'})
    title = forms.CharField(required=False)
    body_class = forms.CharField(required=False)
    template = forms.ChoiceField(choices=template_choice)
Exemplo n.º 23
0
class TestAForm1(forms.Form):
    name = forms.CharField()
Exemplo n.º 24
0
class PageForm(forms.Form):
    url = forms.CharField()
    markup = forms.ChoiceField(options=('bla', 'foo'))
    body = forms.CharField(type='textarea', required=False)
Exemplo n.º 25
0
class PersonForm(forms.Form):
    model = 'people'
    username = forms.CharField(validator=UniqueField())
    name = forms.CharField(required=True)
Exemplo n.º 26
0
class CreateUserForm(forms.Form):
    username = forms.CharField(max_length=30)
    email = forms.EmailField(required=False)
    password = forms.PasswordField(max_length=60)
Exemplo n.º 27
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 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())
Exemplo n.º 28
0
 class TestForm(forms.Form):
     name = forms.CharField()
Exemplo n.º 29
0
class SecretForm(forms.Form):
    value = forms.CharField(required=False)
Exemplo n.º 30
0
class ObjectiveForm(forms.Form):
    subject = forms.CharField(required=False)
    deadline = forms.CharField(required=False)
    outcome = forms.CharField(required=False)
    done = forms.BooleanField(default=False)