Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Oct 6, 2011
1 parent bf4f49b commit e4fef22
Show file tree
Hide file tree
Showing 15 changed files with 228 additions and 80 deletions.
6 changes: 3 additions & 3 deletions memphis/form/__init__.py
Expand Up @@ -37,13 +37,13 @@
from memphis.form.fields import TextField
from memphis.form.fields import IntegerField
from memphis.form.fields import FloatField
from memphis.form.fields import Decimal
from memphis.form.fields import DecimalField
from memphis.form.fields import TextAreaField
from memphis.form.fields import FileField
from memphis.form.fields import LinesField
from memphis.form.fields import PasswordField
from memphis.form.fields import CheckBoxField
from memphis.form.fields import SingleCheckBoxField
from memphis.form.fields import CheckboxField
from memphis.form.fields import CheckboxsField
from memphis.form.fields import DateField
from memphis.form.fields import DateTimeField
from memphis.form.fields import JSDateField
Expand Down
6 changes: 3 additions & 3 deletions memphis/form/field.py
Expand Up @@ -2,7 +2,8 @@
from collections import OrderedDict

from validator import All
from interfaces import _, null, required, Invalid, FORM_INPUT, FORM_DISPLAY
from interfaces import _, null, required
from interfaces import Invalid, FORM_INPUT, FORM_DISPLAY


fields = {}
Expand Down Expand Up @@ -311,8 +312,7 @@ def updateTerms(self, context):
if self.terms is None:
self.terms = self.vocabulary
if self.terms is None:
self.terms = config.registry.getMultiAdapter(
(context, self), IVocabulary)
raise ValueError("Vocabulary is not specified")

return self.terms

Expand Down
59 changes: 32 additions & 27 deletions memphis/form/fields.py
@@ -1,5 +1,5 @@
""" Basic fields """
import datetime, iso8601
import datetime, iso8601, decimal
from memphis import view
from memphis.view import formatter
from memphis.form import vocabulary
Expand Down Expand Up @@ -90,7 +90,7 @@ class FloatField(Number, TextField):
num = float


class Decimal(Number):
class DecimalField(Number, TextField):
__doc__ = _(u'Decimal input widget')

field('decimal')
Expand Down Expand Up @@ -148,20 +148,31 @@ class LinesField(TextAreaField):
'sequence element.')

field('lines')
klass = u'textlines-widget'

def serialize(self, value):
return u'\n'.join(value)
if value is null or not value:
return null

def extract(self, default = null):
value = self.params.get(self.name, default)
if value is not default:
return value.split(u'\n')
return value
try:
return u'\n'.join(value)
except Exception:
raise Invalid(self,
_('"${val}" is not a list',
mapping={'val': value}),
)

tmpl_input = view.template(
"memphis.form:templates/fields/textlines_input.pt")
tmpl_display = view.template(
"memphis.form:templates/fields/textlines_display.pt")
def deserialize(self, value):
if not value:
return null

try:
return [s.strip() for s in value.split()]
except Exception:
raise Invalid(self,
_('"${val}" is not a list',
mapping={'val': value}),
)


class PasswordField(TextField):
Expand All @@ -177,15 +188,13 @@ class PasswordField(TextField):
"memphis.form:templates/fields/password_display.pt")


class CheckBoxField(SequenceField):
"""Input type checkbox widget implementation."""
class CheckboxsField(SequenceField):
__doc__ = _('HTML Checkboxs input based widget.')

klass = u'checkbox-widget'
items = ()
field('checkboxs')

__fname__ = 'checkbox'
__title__ = _('Checkbox widget')
__description__ = _('HTML Checkbox input based widget.')
klass = u'checkboxs-widget'
items = ()

tmpl_input = view.template(
"memphis.form:templates/fields/checkbox_input.pt")
Expand All @@ -196,8 +205,7 @@ def isChecked(self, term):
return term.token in self.value

def update(self, request):
"""See z3c.form.interfaces.IWidget."""
super(CheckBoxWidget, self).update(request)
super(CheckboxsField, self).update(request)

self.items = []
for count, term in enumerate(self.terms):
Expand All @@ -211,15 +219,12 @@ def update(self, request):
'label':label, 'checked':checked})


class SingleCheckBoxField(CheckBoxField):
"""Single Input type checkbox widget implementation."""
class CheckboxField(CheckboxsField):
__doc__ = _('Single checkbox widget.')

field('checkbox')
klass = u'single-checkbox-widget'

__fname__ = 'singlecheckbox'
__title__ = _('Single checkbox')
__description__ = _('Single checkbox widget.')

def updateTerms(self):
if self.terms is None:
self.terms = vocabulary.Vocabulary()
Expand Down
4 changes: 2 additions & 2 deletions memphis/form/templates/fields/date_input.pt
Expand Up @@ -5,9 +5,9 @@ ${view.include('jquery-ui')}
});
</script>

<input id="" name="" class="" title="" lang="" disabled=""
<input id="" type="text" name="" class="" title="" lang="" disabled=""
readonly="" alt="" tabindex="" accesskey="" size="" maxlength=""
style="" value="" type="text"
value=""
tal:attributes="id context.id;
name context.name;
class context.klass;
Expand Down
4 changes: 2 additions & 2 deletions memphis/form/templates/fields/datetime_input.pt
Expand Up @@ -7,7 +7,7 @@

<input id="" name="" class="" title="" lang="" disabled=""
readonly="" alt="" tabindex="" accesskey="" size="" maxlength=""
style="" value="" type="text"
value="" type="text"
tal:attributes="id '%s-date'%context.id;
name context.date_name;
class 'small %s'%context.klass;
Expand All @@ -24,7 +24,7 @@

<input id="" name="" class="" title="" lang="" disabled=""
readonly="" alt="" tabindex="" accesskey="" size="" maxlength=""
style="" value="" type="text"
value="" type="text"
tal:attributes="id '%s-time'%context.id;
name context.time_name;
class 'mini %s'%context.klass;
Expand Down
13 changes: 7 additions & 6 deletions memphis/form/templates/fields/password_display.pt
@@ -1,7 +1,8 @@
<span id="" class=""
tal:attributes="id context.id;
class context.klass;
title context.title;
lang context.lang;">
<tal:block condition="context.value" content="context.value" />
<span class="uneditable-input">
<span tal:attributes="id context.id;
class context.klass;
title context.title;
lang context.lang;">
*****
</span>
</span>
4 changes: 1 addition & 3 deletions memphis/form/templates/fields/radiohoriz_input.pt
Expand Up @@ -13,9 +13,7 @@
readonly context.readonly;
alt context.alt;
accesskey context.accesskey;
checked python: checked and 'checked' or None" />
checked checked and 'checked' or None" />
${item['label']}
</tal:block>
<input name="field-empty-marker" type="hidden" value="1"
tal:attributes="name context.empty_marker" />
</div>
3 changes: 1 addition & 2 deletions memphis/form/templates/fields/text_display.pt
@@ -1,6 +1,5 @@
<span class="uneditable-input">
<span id="" class=""
tal:attributes="id context.id;
<span tal:attributes="id context.id;
class context.klass;
title context.title;
lang context.lang;">
Expand Down
4 changes: 1 addition & 3 deletions memphis/form/templates/fields/text_input.pt
@@ -1,6 +1,4 @@
<input id="" name="" class="" title="" lang="" disabled=""
readonly="" alt="" tabindex="" accesskey="" size="" maxlength=""
style="" value="" type="text"
<input type="text"
tal:attributes="id context.id;
name context.name;
class context.klass;
Expand Down
5 changes: 1 addition & 4 deletions memphis/form/templates/fields/textarea_input.pt
@@ -1,7 +1,4 @@
<textarea
id="" name="" class="" cols="" rows=""
tabindex="" disabled="" readonly="" accesskey=""
tal:attributes="id context.id;
<textarea tal:attributes="id context.id;
name context.name;
class context.klass;
title context.title;
Expand Down
7 changes: 0 additions & 7 deletions memphis/form/templates/fields/textlines_display.pt

This file was deleted.

15 changes: 0 additions & 15 deletions memphis/form/templates/fields/textlines_input.pt

This file was deleted.

2 changes: 1 addition & 1 deletion memphis/form/templates/widget.pt
Expand Up @@ -5,7 +5,7 @@
${context.title}
<tal:block condition="context.required">*</tal:block>
</label>
<div class="input" tal:on-error="nothing">
<div class="input">
<tal:block tal:content="structure context.render(request)" />
<span class="help-inline"
tal:condition="error"
Expand Down
4 changes: 2 additions & 2 deletions memphis/form/tests/test_field.py
Expand Up @@ -121,7 +121,7 @@ def validator(fs, data):

def _makeOne(self, name, **kw):
class MyField(form.Field):
def serialize(self, value):
def serialize(self, value): # pragma: no cover
return value
def deserialize(self, value):
return value
Expand Down Expand Up @@ -328,7 +328,7 @@ def test_field_update_value(self):
class MyField(form.Field):
def serialize(self, value):
return value
def deserialize(self, value):
def deserialize(self, value): # pragma: no cover
return value

request = object()
Expand Down

0 comments on commit e4fef22

Please sign in to comment.