Skip to content

Commit

Permalink
Merge pull request #35 from bobslee/component-dir-files
Browse files Browse the repository at this point in the history
Put component classes as files under (new) components dir.
  • Loading branch information
bobslee authored Sep 21, 2023
2 parents b2dfa24 + af979b0 commit b1bead0
Show file tree
Hide file tree
Showing 66 changed files with 1,421 additions and 1,285 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Changelog

## 1.1.0

Put component classes as files in the new `components` directory.\
Change the instantiation of a component in the `get_component_object` method of the `Builder` class.

**Warning**:

This changes the `import` declaration (path) of how components should be imported.

**Old style import:**:

```python
from formiodata.components import textfieldComponent
```

**New style import:**

```python
from formiodata.components.textfield import textfieldComponent
```

Also some additional minor improvements, e.g. remove unused imports and newlines.

## 1.0.5

Add Component properties:
Expand Down
8 changes: 5 additions & 3 deletions formiodata/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from collections import OrderedDict
from copy import deepcopy

from formiodata import components
from formiodata.components.component import Component

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -80,7 +80,9 @@ def get_component_object(self, component):
if component_type:
try:
cls_name = '%sComponent' % component_type
cls = getattr(components, cls_name)
import_path = 'formiodata.components.%s' % component_type
module = __import__(import_path, fromlist=[cls_name])
cls = getattr(module, cls_name)
component_obj = cls(component, self, language=self.language, i18n=self.i18n, resources=self.resources)
return component_obj
except AttributeError as e:
Expand All @@ -89,7 +91,7 @@ def get_component_object(self, component):
logging.error(e)
# TODO: implement property (by kwargs) whether to return
# (raw) Component object or throw exception,
return components.Component(component, self)
return Component(component, self)
else:
msg = "Can't instantiate a (raw) component without a type.\n\n" \
"Component raw data\n" \
Expand Down
Loading

0 comments on commit b1bead0

Please sign in to comment.