Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
Merge branch 'waskiqdev/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
toirl committed Nov 18, 2016
2 parents 4228c09 + aa21b8c commit 0a4545d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 25 deletions.
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
# built documents.
#
# The short X.Y version.
version = '0.21.1'
version = '0.22.0'
# The full version, including alpha/beta/rc tags.
release = '0.21.1'
release = '0.22.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
63 changes: 43 additions & 20 deletions formbar/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@
log = logging.getLogger(__name__)


def get_sa_property(item, fieldname):
if not item:
return None

# Recursive handling of "dot.separated.field.names"
elif fieldname.find(".") > -1:
nameparts = fieldname.split(".")
return get_sa_property(getattr(item, ".".join(nameparts[0:-1])),
nameparts[-1])
else:
mapper = sa.orm.object_mapper(item)
for prop in mapper.iterate_properties:
if prop.key == fieldname:
return prop


def remove_ws(data):
"""Helper function which removes trailing and leading whitespaces
for all values in the given dictionary. The dictionary usually
Expand Down Expand Up @@ -281,19 +297,12 @@ def deserialize(self, data):
# Load relations of the item. Those are needed to deserialize
# the relations.
relation_names = {}
try:
mapper = sa.orm.object_mapper(self._item)
relation_properties = filter(
lambda p: isinstance(p,
sa.orm.properties.RelationshipProperty),
mapper.iterate_properties)
for prop in relation_properties:
relation_names[prop.key] = prop
except sa.orm.exc.UnmappedInstanceError:
if not self._item:
pass # The form is not mapped to an item.
else:
raise

if self._item:
for fieldname in data.keys():
prop = get_sa_property(self._item, fieldname)
if isinstance(prop, sa.orm.properties.RelationshipProperty):
relation_names[fieldname] = prop

for fieldname, value in self._filter_values(data).iteritems():
field = self.fields.get(fieldname)
Expand Down Expand Up @@ -682,17 +691,31 @@ def __getattr__(self, name):
return getattr(self._config, name)

def _get_sa_mapped_class(self):
# TODO: Raise Exception if this field is not a relation. (None)
# <2013-07-25 07:44>
return self.sa_property.mapper.class_
if self.name.find(".") > -1:
# Special handling for prefixed relations in case of
# included entities.
# Those included entities usually has a prefix which defines
# the path to the attribute.
#
# Example:
# If the fieldname ist "foo.bar" this means that the current
# item has a relation named "foo". And within this foo
# relation a value should be set in "bar".
#
# Unfortunately this special notation breaks the default
# procedure how to get the mapped class of this attribute.
path = self.name.split(".")
rel = getattr(self._form._item, ".".join(path[:-1]))
field = path[-1]
sa_property = get_sa_property(rel, field)
return sa_property.mapper.class_
else:
return self.sa_property.mapper.class_

def _get_sa_property(self):
if not self._form._item:
return None
mapper = sa.orm.object_mapper(self._form._item)
for prop in mapper.iterate_properties:
if prop.key == self.name:
return prop
return get_sa_property(self._form._item, self.name)

def get_type(self):
"""Returns the datatype of the field."""
Expand Down
10 changes: 8 additions & 2 deletions formbar/static/js/formbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -700,8 +700,14 @@ var form = function (inputFilter, ruleEngine) {
var setListener = function () {
var timeOutID;
var changeEvent = function(e){
if (formFields[e.target.name].state==='inactive'){
clearFieldValue(e.target.name);
var div = $(e.target);
var fieldName = e.target.name;
if (formFields[fieldName].state==='inactive'){
if (div.attr("reset-value") == "true") {
clearFieldValue(fieldName);
} else {
resetFieldValue(fieldName, formFields);
}
} else {
inputChanged(e);
}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import multiprocessing
import sys, os

version = '0.21.1'
version = '0.22.0'

setup(name='formbar',
version=version,
Expand Down

0 comments on commit 0a4545d

Please sign in to comment.