Esempio n. 1
0
class PageAdmin(CmsAdmin):
    '''Admin views for html pages
    '''
    icon = 'fa fa-sitemap'
    form = Layout(PageCRUD._model.form, Fieldset(all=True),
                  Submit('Add new page'))
    updateform = Layout(PageForm, Fieldset(all=True), Submit('Update page'))
Esempio n. 2
0
class ComingSoon(WebFormRouter):
    release = 'release'
    template = 'comingsoon.html'
    default_form = Layout(EmailForm,
                          Fieldset(all=True),
                          Submit('Get notified'),
                          showLabels=False)
Esempio n. 3
0
 def test_serialise(self):
     layout = Layout(EmailUserForm, Fieldset('body'), Inline('users'),
                     Submit('update'))
     self.assertEqual(len(layout.children), 3)
     form = layout()
     data = form.as_dict()
     children = data['children']
     self.assertEqual(len(children), 3)
     self.assertEqual(children[1]['name'], 'users')
Esempio n. 4
0
 def test_serialise_empty_fields(self):
     layout = Layout(EmptyFieldsForm, Fieldset(empty=True, name='foo'),
                     Inline('users'), Submit('update'))
     self.assertEqual(len(layout.children), 3)
     form = layout()
     data = form.as_dict()
     children = data['children']
     self.assertEqual(len(children), 3)
     self.assertEqual(children[0]['name'], 'foo')
     self.assertEqual(children[1]['name'], 'users')
Esempio n. 5
0
class SignUp(SignUpView):
    '''Handle sign up on Html pages
    '''
    default_form = Layout(CreateUserForm,
                          Fieldset('username', 'email', 'password',
                                   'password_repeat'),
                          Submit('Sign up',
                                 disabled="form.$invalid"),
                          showLabels=False,
                          directive='user-form')
Esempio n. 6
0
class ForgotPassword(WebFormRouter):
    '''Manage forget passwords routes
    '''
    default_form = Layout(EmailForm,
                          Fieldset(all=True),
                          Submit('Submit'),
                          showLabels=False,
                          resultHandler='passwordRecovery')

    reset_form = Layout(PasswordForm,
                        Fieldset(all=True),
                        Submit('Change Password'),
                        showLabels=False,
                        resultHandler='passwordChanged')

    template = 'forgot.html'
    reset_template = 'reset_password.html'

    @route('<key>')
    def get_reset_form(self, request):
        key = request.urlargs['key']
        try:
            user = request.cache.auth_backend.get_user(request, auth_key=key)
        except AuthenticationError as e:
            session = request.cache.session
            session.error('The link is no longer valid, %s' % e)
            return request.redirect('/')
        if not user:
            raise Http404
        form = self.reset_form(request)
        if self.form_action:
            action = self.form_action.copy()
            action['path'] = '%s/%s' % (action['path'], key)
        else:
            action = request.full_path()
        html = form.as_form(action=action,
                            enctype='multipart/form-data',
                            method='post')
        return self.html_response(request, html, self.reset_template)
Esempio n. 7
0
class Login(WebFormRouter):
    '''Adds login get ("text/html") and post handlers
    '''
    template = 'login.html'
    default_form = Layout(LoginForm,
                          Fieldset(all=True),
                          Submit('Login', disabled="form.$invalid"),
                          showLabels=False,
                          resultHandler='login')

    def get(self, request):
        if request.cache.user.is_authenticated():
            raise HttpRedirect('/')
        return super().get(request)

    def post(self, request):
        return login(request, self.default_form.form_class)
Esempio n. 8
0
from lux.utils import test
from lux import forms
from lux.forms import Layout, Fieldset, Submit


class TestAForm1(forms.Form):
    name = forms.CharField()


Layout1 = Layout(TestAForm1)

Layout2 = Layout(TestAForm1, Fieldset(all=True), Submit('done'))


class PageForm(forms.Form):
    url = forms.CharField()
    markup = forms.ChoiceField(options=('bla', 'foo'))
    body = forms.CharField(type='textarea', required=False)


PageForm1 = Layout(PageForm)


class FormAngularLayoutTests(test.TestCase):
    def test_layout_class(self):
        self.assertTrue(Layout1.form_class)
        self.assertEqual(Layout1.form_class, TestAForm1)
        self.assertEqual(len(Layout1.children), 1)

    def test_form_data(self):
        form = Layout1()
Esempio n. 9
0
 def on_loaded(self, app):
     app.forms['task'] = Layout(TaskForm, Fieldset(all=True),
                                Submit('submit'))
     app.forms['person'] = Layout(PersonForm, Fieldset(all=True),
                                  Submit('submit'))
Esempio n. 10
0
from lux import forms
from lux.forms import WebFormRouter, Layout, Fieldset, Submit, formreg


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)


formreg['contact'] = Layout(ContactForm,
                            Fieldset(all=True, showLabels=False),
                            Submit('Send', disabled="form.$invalid"),
                            labelSrOnly=True,
                            resultHandler='replace')


class ContactRouter(WebFormRouter):
    form = 'contact'

    async def post(self, request):
        form_class = self.get_form_class(request)
        if not form_class:
            raise MethodNotAllowed

        data, _ = await as_coroutine(request.data_and_files())
        form = form_class(request, data=data)
Esempio n. 11
0
from lux.utils import test
from lux import forms
from lux.forms import Layout, Fieldset, Submit


class TestAForm1(forms.Form):
    name = forms.CharField()


Layout1 = Layout(TestAForm1)

Layout2 = Layout(TestAForm1,
                 Fieldset(all=True),
                 Submit('done'))


class PageForm(forms.Form):
    url = forms.UrlField(lux_directive='foo')
    markup = forms.ChoiceField(options=('bla', 'foo'))
    body = forms.CharField(type='textarea', required=False)


PageForm1 = Layout(PageForm)


class LayoutMixin:

    def _field(self, data, idx, child=0, children_expected=1):
        self.assertEqual(len(data['children']), children_expected)
        data = data['children'][child]
        self.assertEqual(data['type'], 'fieldset')
Esempio n. 12
0
class CreateOrganisationForm(UpdateOrganisationForm):
    username = forms.SlugField(label='Organisation screen name',
                               validator=UniqueField(),
                               maxlength=30)


class OrgMemberForm(forms.Form):
    role = forms.ChoiceField(options=MemberRole,
                             default=MemberRole.member.name)
    private = forms.BooleanField(required=False)


# FORM REGISTRATION
formreg['create-organisation'] = Layout(
    CreateOrganisationForm,
    Row(Col('username', 6), Col('billing_email_address', 6)),
    Fieldset(all=True), Submit('Add new organisation'))

formreg['organisation'] = Layout(UpdateOrganisationForm,
                                 Fieldset('billing_email_address', all=True),
                                 Submit('Update organisation'))

formreg['user'] = Layout(UserForm, Fieldset(all=True), Submit('Update user'))

formreg['user-profile'] = Layout(
    ProfileForm, Row(Col('username', 6), Col('email', 6)),
    Row(Col('first_name', 6), Col('last_name', 6)),
    Row(Col('link', 6), Col('timezone', 6)), Fieldset(all=True),
    Submit('Update profile'))
Esempio n. 13
0
class TemplateAdmin(CmsAdmin):
    icon = 'fa fa-file-code-o'
    form = Layout(TemplateCRUD._model.form, Fieldset(all=True),
                  Submit('Add new template'))
    updateform = Layout(TemplateForm, Fieldset(all=True),
                        Submit('Update template'))
Esempio n. 14
0
from lux import forms
from lux.forms import Layout, Fieldset, Submit, formreg
from lux.extensions.rest import UniqueField


class ApplicationConfigForm(forms.Form):
    DOCKER_USER = forms.EmailField(required=False)
    DOCKER_EMAIL = forms.CharField(required=False)
    DOCKER_PASSWORD = forms.PasswordField(required=False)
    AWS_KEY = forms.CharField(required=False)
    AWS_SECRET = forms.CharField(required=False)


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'}))


# FORM REGISTRATION
formreg['create-application'] = Layout(ApplicationForm, Fieldset(all=True),
                                       Submit('Add new application'))

formreg['application-config'] = Layout(ApplicationConfigForm,
                                       Fieldset(all=True),
                                       Submit('Add new application'))
Esempio n. 15
0
from lux.forms import Layout, Fieldset, Submit, formreg

from . import forms


formreg['reset-password'] = Layout(
    forms.PasswordForm,
    Fieldset('password',
             'password_repeat'),
    Submit('Change password',
           classes='btn btn-success')
)


formreg['change-password'] = Layout(
    forms.ChangePasswordForm,
    Fieldset('old_password',
             'password',
             'password_repeat'),
    Submit('Change password',
           classes='btn btn-success')
)


formreg['new-token'] = Layout(
    forms.NewTokenForm,
    Fieldset(all=True),
    Submit('Create token', classes='btn btn-success'),
    resultHandler='responseHandler'
)
Esempio n. 16
0
            else:
                raise AuthenticationError('not authenticated')
        except AuthenticationError as exc:
            raise forms.ValidationError(str(exc))
        return value


class NewTokenForm(forms.Form):
    """Create a new Authorization ``Token`` for the authenticated ``User``.
    """
    description = forms.TextField(minlength=2, maxlength=256)


#
# HTML FORM REGISTRATION
formreg['user'] = Layout(UserForm, Fieldset(all=True), Submit('Update user'))

formreg['user-profile'] = formreg['user']

formreg['create-group'] = Layout(GroupForm, Fieldset(all=True),
                                 Submit('Create new group'))

formreg['group'] = Layout(GroupForm, Fieldset(all=True),
                          Submit('Update group'))

formreg['create-permission'] = Layout(PermissionForm, Fieldset(all=True),
                                      Submit('Create new permissions'))

formreg['permission'] = Layout(PermissionForm, Fieldset(all=True),
                               Submit('Update permissions'))