Skip to content

Commit 537461d

Browse files
committed
Consistency in README.md
1 parent 6b9db22 commit 537461d

File tree

1 file changed

+52
-46
lines changed

1 file changed

+52
-46
lines changed

README.md

Lines changed: 52 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ To upgrade to `webstack-django-sorting` v1.0.0+, you must remove the old middlew
3131

3232
The provide is available on PyPI:
3333

34-
pip install webstack_django_sorting
34+
```shell
35+
pip install webstack_django_sorting
36+
```
3537

3638
The project provides examples of integration with Django and Jinja2 templates.
3739

@@ -40,59 +42,63 @@ The project provides examples of integration with Django and Jinja2 templates.
4042
1. Add the application to the `INSTALLED_APPS` list:
4143

4244
```python
43-
INSTALLED_APPS = [
44-
# ...
45-
'webstack_django_sorting',
46-
]
45+
INSTALLED_APPS = [
46+
# ...
47+
'webstack_django_sorting',
48+
]
4749
```
4850

4951
2. Check the request context processor is loaded in `TEMPLATES` options:
5052

5153
```python
52-
TEMPLATES = [
53-
{
54-
'BACKEND': 'django.template.backends.django.DjangoTemplates',
55-
'DIRS': [],
56-
'APP_DIRS': True,
57-
'OPTIONS': {
58-
'context_processors': [
59-
# ...
60-
'django.template.context_processors.request',
61-
# ...
62-
],
63-
},
64-
},
65-
]
54+
TEMPLATES = [
55+
{
56+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
57+
'DIRS': [],
58+
'APP_DIRS': True,
59+
'OPTIONS': {
60+
'context_processors': [
61+
# ...
62+
'django.template.context_processors.request',
63+
# ...
64+
],
65+
},
66+
},
67+
]
6668
```
6769

6870
3. Add this line at the top of your template to load the sorting tags:
6971

70-
{% load sorting_tags %}
72+
```html
73+
{% load sorting_tags %}
74+
```
7175

7276
4. Decide on a variable that you would like to sort, and use the
7377
autosort tag on that variable before iterating over it:
7478

75-
{% autosort object_list %}
79+
```html
80+
{% autosort object_list %}
81+
```
7682

7783
5. Now, you want to display different headers with links to sort
7884
your objects_list:
7985

8086
```html
81-
<tr>
82-
<th>{% anchor first_name _("Name") %}</th>
83-
<th>{% anchor creation_date _("Creation") %}</th>
84-
</tr>
87+
<tr>
88+
<th>{% anchor first_name _("Name") %}</th>
89+
<th>{% anchor creation_date _("Creation") %}</th>
90+
</tr>
8591
```
8692

8793
The first argument is a field or an attribute of the objects list, and the
8894
second one (optional) is a title that would be displayed. The previous
8995
snippet will be rendered like this in French:
9096

9197
```html
92-
<tr>
93-
<th><a href="/path/to/your/view/?sort=first_name" title="Nom">Nom</a></th>
94-
<th><a href="/path/to/your/view/?sort=creation_date" title="Création">Création</a></th>
95-
</tr>
98+
<tr>
99+
<th><a href="/path/to/your/view/?sort=first_name" title="Nom">Nom</a></th>
100+
<th><a href="/path/to/your/view/?sort=creation_date" title="Création">Création</a></th>
101+
</tr>
96102
```
97103

98104
If your application doesn't support internationalization, you can use a
@@ -103,16 +109,16 @@ The project provides examples of integration with Django and Jinja2 templates.
103109
1. Define the environment in the `TEMPLATES` options:
104110

105111
```python
106-
TEMPLATES = {
107-
{
108-
"BACKEND": "django.template.backends.jinja2.Jinja2",
109-
"DIRS": [],
110-
"APP_DIRS": True,
111-
"OPTIONS": {
112-
"environment": "testproj.testapp.jinja2.env.JinjaEnvironment",
113-
},
112+
TEMPLATES = {
113+
{
114+
"BACKEND": "django.template.backends.jinja2.Jinja2",
115+
"DIRS": [],
116+
"APP_DIRS": True,
117+
"OPTIONS": {
118+
"environment": "testproj.testapp.jinja2.env.JinjaEnvironment",
114119
},
115-
]
120+
},
121+
]
116122
````
117123

118124
2. Your environment file should add `sorting_anchor` and `sort_queryset` to globals:
@@ -128,21 +134,21 @@ The project provides examples of integration with Django and Jinja2 templates.
128134
self.globals["sort_queryset"] = sort_queryset
129135
```
130136

131-
3. Now, you can generate header links to sort your queryset:
137+
3. Now, you can generate header links to sort your queryset.
132138

133139
```html
134-
<tr>
135-
<th>{{ sorting_anchor(request, "created_on", "Date") }}</th>
136-
<!--...-->
137-
<tr>
140+
<tr>
141+
<th>{{ sorting_anchor(request, "created_on", "Date") }}</th>
142+
<!--...-->
143+
<tr>
138144
```
139145

140146
4. The queryset should be wrapped with `sort_queryset` to use the GET request arguments for sorting:
141147

142148
```html
143-
{% for secret_file in sort_queryset(request, secret_files) %}
144-
<!--...-->
145-
{% endfor %}
149+
{% for secret_file in sort_queryset(request, secret_files) %}
150+
<!--...-->
151+
{% endfor %}
146152
```
147153

148154

0 commit comments

Comments
 (0)