Skip to content

Commit 01f9c65

Browse files
authored
docs: update docs about customization (#79)
1 parent a4c91f6 commit 01f9c65

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+84
-3122
lines changed
+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"label": "Customization",
3-
"position": 4
4-
}
5-
2+
"label": "Customization",
3+
"position": 4
4+
}
+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
sidebar_position: 2
3+
---
4+
5+
# Text And Icons
6+
7+
To customize the image uploader widget or inline you can set some variables (this feature is based on the issue [#77](https://github.com/inventare/django-image-uploader-widget/issues/77)). In this page we talk about how to, easy, change the texts and icons on that lib.
8+
9+
10+
## Widget
11+
12+
For the widget, to customize the icon and the text we need to set some variables in the `ImageUploaderWidget` constructor, like it:
13+
14+
```python
15+
# ...
16+
class TestCustomForm(forms.ModelForm):
17+
class Meta:
18+
model = CustomWidget
19+
widgets = {
20+
'image': ImageUploaderWidget(
21+
drop_icon="<svg ...></svg>",
22+
drop_text="Custom Drop Text",
23+
empty_icon="<svg ...></svg>",
24+
empty_text="Custom Empty Marker Text",
25+
),
26+
}
27+
fields = '__all__'
28+
```
29+
30+
In this example, we set all four properties (`drop_icon`, `drop_text`, `empty_icon` and `empty_text`) for the widget. In the icons is possible to use the `django.shortcuts.render` ([REF](https://docs.djangoproject.com/en/4.1/topics/http/shortcuts/#render)) to renderize the icon from an HTML template.
31+
32+
Another way for customize it is create an new widget class based on that and use it for your forms:
33+
34+
```python
35+
class MyCustomWidget(ImageUploaderWidget):
36+
drop_text = ""
37+
empty_text = ""
38+
39+
def get_empty_icon(self):
40+
return render(...)
41+
42+
def get_drop_icon(self):
43+
return render(...)
44+
45+
class TestCustomForm(forms.ModelForm):
46+
class Meta:
47+
model = CustomWidget
48+
widgets = {
49+
'image': MyCustomWidget()
50+
}
51+
fields = '__all__'
52+
```
53+
54+
## Inline Editor
55+
56+
To customize the text and the icons of the inline editor is a little bit faster too. We can set some variables on the `InlineAdmin` of your model, like this:
57+
58+
```python
59+
class CustomInlineEditor(ImageUploaderInline):
60+
model = models.CustomInlineItem
61+
add_image_text = "add_image_text"
62+
drop_text = "drop_text"
63+
empty_text = "empty_text"
64+
65+
def get_empty_icon(self):
66+
return render(...)
67+
68+
def get_add_icon(self):
69+
return render(...)
70+
71+
def get_drop_icon(self):
72+
return render(...)
73+
74+
@admin.register(models.CustomInline)
75+
class CustomInlineAdmin(admin.ModelAdmin):
76+
inlines = [CustomInlineEditor]
77+
```

docs/docs/development/tests.md

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ To maintain the integrity of the features of this project we have written some i
1010
In the decision to write the tests we opted for writing only integration tests using the selenium. And the reason for it is: our project uses much more JavaScript for web browser than Python code for back-end and runs in high coupling with the django-admin. In this context, unit tests are expendable.
1111
:::
1212

13+
:::note Some unit tests
14+
In the note block above i talked about not using unit test cases, and in the decisions of the issue [#77](https://github.com/inventare/django-image-uploader-widget/issues/77) we decided to add one unit test for the translation of the widget ([tests/widget_customized.py](https://github.com/inventare/django-image-uploader-widget/blob/main/image_uploader_widget_demo/tests/widget_customized.py#L5)).
15+
:::
16+
1317
## Some Tests Decisions and Workarounds
1418

1519
When testing with selenium is not possible to hack the file picker to choose some file. And in this project, in some moments we use an *temporary file input* for choosing files without compromise the current choosed file. Based on those context, to test correctly fires to onClick event of the *temporary file input*, we added an JavaScript to add an onClick event showing an alert and test for this alert into the screen.

docs/docusaurus.config.js

-5
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ const config = {
5050
},
5151
items: [
5252
{ type: 'doc', docId: 'intro', position: 'left', label: 'Documentation', },
53-
{
54-
type: 'docsVersionDropdown',
55-
position: 'right',
56-
dropdownActiveClassDisabled: true,
57-
},
5853
{ href: 'https://github.com/inventare/django-image-uploader-widget', label: 'GitHub', position: 'right', },
5954
],
6055
},

docs/versioned_docs/version-0.0.6/intro.md

-138
This file was deleted.
-1.96 MB
Binary file not shown.
-502 KB
Binary file not shown.

docs/versioned_docs/version-0.1.3/customization/_category_.json

-5
This file was deleted.

docs/versioned_docs/version-0.1.3/customization/comming.md

-5
This file was deleted.

docs/versioned_docs/version-0.1.3/inline_admin/_category_.json

-5
This file was deleted.

docs/versioned_docs/version-0.1.3/inline_admin/comming.md

-5
This file was deleted.

docs/versioned_docs/version-0.1.3/intro.md

-68
This file was deleted.

docs/versioned_docs/version-0.1.3/widget/_category_.json

-5
This file was deleted.

docs/versioned_docs/version-0.1.3/widget/comming.md

-5
This file was deleted.

docs/versioned_docs/version-0.1.4/customization/_category_.json

-5
This file was deleted.

docs/versioned_docs/version-0.1.4/customization/comming.md

-5
This file was deleted.

docs/versioned_docs/version-0.1.4/inline_admin/_category_.json

-5
This file was deleted.

docs/versioned_docs/version-0.1.4/inline_admin/comming.md

-5
This file was deleted.

0 commit comments

Comments
 (0)