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)
def testColumnsFormtupleOfTuple(self): from djpcms import forms from djpcms.forms import layout as uni c = uni.Columns(('field1', 'field2'), 'field3') class Form(forms.Form): field1 = forms.CharField() field2 = forms.CharField() field3 = forms.CharField() form_html = forms.HtmlForm(Form, layout=uni.FormLayout(c)) self.assertEqual(len(c.children), 2)
def testNotField(self): from djpcms import forms from djpcms.html import Div from djpcms.forms import layout as uni from djpcms.apps.contentedit import PageForm htmlform = forms.HtmlForm(PageForm, layout=uni.FormLayout(Div(key='random'))) layout = htmlform['layout'] self.assertTrue('random' in layout) w = htmlform() text = w.render(context={'random': 'Hello'}) self.assertTrue('<div>Hello</div>' in text)
def testLegend(self): from djpcms import forms from djpcms.forms import layout as uni from djpcms.apps.contentedit import PageForm htmlform = forms.HtmlForm(PageForm, layout=uni.FormLayout( uni.Fieldset(legend='This is a legend'))) layout = htmlform['layout'] fs = layout[1] self.assertEqual(fs.legend_html, 'This is a legend') text = htmlform().render() self.assertTrue('This is a legend</div>' in text)
def form(self): '''Build the form and the form layout''' from djpcms import forms from djpcms.forms import layout as uni 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() return forms.HtmlForm( testForm, layout=uni.FormLayout( uni.TableFormElement( ('entry', 'color', 'size'), ('entry1', 'entry1__color', 'entry1__size'), ('entry2', 'entry2__color', 'entry2__size'), ('entry3', 'entry3__color', 'entry3__size'), key='table', legend='Leggenda')))
tag = 'div' default_class = "fileupload-buttonbar" _media = media.Media( js=[ media.jquerytemplate(), 'fileupload/jquery.fileupload.js', 'fileupload/jquery.fileupload-ui.js', 'fileupload/upload.js' ], css={'screen': ['fileupload/jquery.fileupload-ui.css']}) def stream(self, djp, widget, context): yield '<label class="fileinput-button">\ <span>Add files...</span>\ {0[inner]}\ </label>\ <button type="submit" class="start">Start upload</button>\ <button type="reset" class="cancel">Cancel upload</button>\ <button type="button" class="delete">Delete files</button>'.format(context) def media(self, djp=None): return self._media FileUploadForm = forms.HtmlForm(UploadForm, ajax=False, layout=layout.FormLayout( layout.FormLayoutElement( 'files', tag=None, field_widget_maker=FileInputHtml), form_messages_container_class=None), inputs=[])
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 ChatFormHtml = forms.HtmlForm(ChatForm, layout=uni.FormLayout(default_style=uni.nolabel), inputs=(('submit', 'submit'), )) class ChatApplication(views.Application): _media = media.Media(js=['djpsite/chat.js']) home = views.View() chat = views.View('chat', form=ChatFormHtml, has_plugins=True) def publish(self, channels, text): p = pubsub_server(self.settings) return p.publish(channels, text) def render(self, request, **kwargs): return html.Widget('div', cn='chatroom').render(request)
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) HtmlModelListForm = forms.HtmlForm( ModelItemListForm, layout=uni.FormLayout(uni.Fieldset('for_model', 'text_search', 'filter', 'exclude'), uni.Inlineset('order_by', 'descending', label='Ordering'), uni.Inlineset('max_display', 'display_if_empty', 'table_footer', label='Max display'), uni.Fieldset('headers'), tag='div', cn='model-filters'), ) class FormModelForm(ForModelForm): method = forms.ChoiceField(choices=(('get', 'get'), ('post', 'post')), initial='get') ajax = forms.BooleanField(initial=False) class ModelLinksForm(forms.Form):
HtmlLoginForm = forms.HtmlForm( LoginForm, success_message = lambda request, user:\ '%s successfully signed in' % user, inputs = (('Sign in','login_user'),) ) HtmlLogoutForm = forms.HtmlForm( LogoutForm, layout=uni.SimpleLayout(html.Div(key='logout')), inputs=(('logout', 'logout'),) ) HtmlAddUserForm = forms.HtmlForm( UserAddForm, layout = uni.FormLayout(uni.Fieldset('username','password','re_type')), success_message = lambda request, user:\ 'User "%s" successfully created.' % user, inputs = (('create','create'),) ) HtmlRegisterForm = forms.HtmlForm( RegisterForm, layout = uni.FormLayout(uni.Fieldset('username','password','re_type')), success_message = lambda request, user:\ 'User %s successfully registered.' % user, inputs = (('register','create'),) ) HtmlChangePassword = forms.HtmlForm( PasswordChangeForm,
from djpcms import forms, html, media from djpcms.forms import layout as uni from .forms import * __all__ = [ 'HtmlTemplateForm', 'HtmlPageForm', 'ContentBlockHtmlForm', 'HtmlEditContentForm' ] HtmlTemplateForm = forms.HtmlForm(TemplateForm) HtmlPageForm = forms.HtmlForm( PageForm, layout=uni.FormLayout( uni.Columns( ('doctype', 'layout', 'inner_template', 'grid_system', 'url'), ('title', 'link', 'in_navigation', 'soft_root', uni.SUBMITS))), inputs=(('save', forms.SAVE_AND_CONTINUE_KEY), )) ContentBlockHtmlForm = forms.HtmlForm( ContentBlockForm, inputs=(('save', forms.SAVE_KEY), ), layout=uni.FormLayout( uni.Fieldset('plugin_name', 'container_type', 'title'), uni.Inlineset('for_not_authenticated'), html.WidgetMaker(tag='div', key='plugin', cn='form-plugin-container')), media=media.Media(js=['djpcms/plugins/filters.js'])) HtmlEditContentForm = forms.HtmlForm( EditContentForm, layout=uni.FormLayout(
body = forms.FieldList( (theme_field(cssv.body.font_family), theme_field( cssv.body.font_size), theme_field( cssv.body.radius), theme_field(cssv.body.color, ColorField)), withprefix=False) class ThemeInputs(forms.Form): '''input form for theme variables''' body = forms.FieldList((('color', ColorField), ('background', ColorField))) AddThemeHtml = forms.HtmlForm( AddTheme, inputs=(('add new theme', 'add'), ), ) ThemeInputsHtml = forms.HtmlForm( ThemeInputs, layout=uni.FormLayout(default_style=uni.inlineLabels)) class DesignApplication(views.Application): pagination = html.Pagination(('id', 'timestamp')) home = views.SearchView() add = views.AddView(form=AddThemeHtml, has_plugins=True, name='Add theme') view = views.ViewView() forms_view = views.View('/forms') def render_instance_default(self, request, instance, **kwargs): return get_form(request, ThemeInputsHtml)