Skip to content

Commit e07935e

Browse files
authored
Merge pull request #6 from skip-pay/UpstreamSync0617
Upstream sync0617
2 parents f00c440 + bac850b commit e07935e

File tree

6 files changed

+106
-20
lines changed

6 files changed

+106
-20
lines changed

chamber/templatetags/__init__.py

Whitespace-only changes.

chamber/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = (0, 6, 16, 3)
1+
VERSION = (0, 6, 17, 1)
22

33

44
def get_version():

docs/installation.rst

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,23 @@ Installation
66
Python/Django versions
77
----------------------
88

9-
+----------------------+------------+
10-
| Python | Django |
11-
+======================+============+
12-
| 2.7, 3.4, 3.5, 3.6 | 1.7 - 1.10 |
13-
+----------------------+------------+
9+
+----------------------------+------------------+
10+
| Python | Django |
11+
+============================+==================+
12+
| 3.5, 3.6, 3.9, 3.10, 3.11 | >=2.2 <4 |
13+
+----------------------------+------------------+
1414

1515

1616
Requirements
1717
------------
1818

1919
* **django** -- Chamber extends Django, therefore it is a natural dependency
2020
* **pyprind** -- used in CSV importers to show progress bars
21-
* **six** -- to provide Python 2/3 compatibility
22-
* **filemagic**
23-
* **unidecode**
21+
* **filemagic** -- to check type of the files from its content
22+
* **unidecode** -- to convert unicode characters to ascii
2423

2524

26-
Using Pip
25+
Using pip
2726
---------
2827
Django-chamber is not currently inside *PyPI* but in the future you will be able to use:
2928

docs/models.rst

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ The ``django.db.models.FileField`` with ``RestrictedFileFieldMixin`` options.
6868

6969
``chamber.models.fields.PriceField`` with a default ``django.core.validators.MinValueValidator`` set to ``0.00``.
7070

71-
.. class:: chamber.models.fields.SouthMixin
72-
73-
Mixin for automatic South migration of custom model fields.
7471

7572
SmartModel
7673
----------
@@ -149,6 +146,24 @@ SmartModel
149146

150147
Update instance field values with values sent in ``changed_fields`` and finally instance is saved. If you want to update only changed fields in the database you can use parameter ``update_only_changed_fields`` to achieve it
151148

149+
.. method:: full_clean(exclude=None, *args, **kwargs)
150+
151+
The original django full_clean method is improved with calling extra clean_{field} methods on the model (it is similar to django forms clean methods::
152+
153+
class CustomModel(SmartModel):
154+
155+
name = models.CharField(max_length=100)
156+
157+
def clean_name(self):
158+
if len(self.name) >= 10:
159+
raise ValidationError('name must be lower than 10')
160+
161+
The method ``clean_name`` will be automatically called when the ``full_clean`` method is triggered and ValidationError will be added to the field error.
162+
163+
.. method:: get_locked_instance()
164+
165+
The method returns the new instance of the self object which is locked in the database with ``select_for_update``. Method must be used in the django atomic block.
166+
152167

153168
SmartMeta
154169
---------

docs/transactions.rst

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,42 @@ Transaction helpers
22
===================
33

44

5-
``chamber.utils.transaction.atomic``
5+
``chamber.utils.transaction``
66
------------------------------------
77

88
.. function:: smart_atomic(using=None, savepoint=True, ignore_errors=None, reversion=True)
99

10-
Like django ``transaction.smart_atomic()`` decorator chamber atomic can be used for surrounding method, function or block of code with db atomic block. But because we often uses reversion the atomic is surrounded with ``create_revision`` decorator. Reversion can be turned off with ``reversion`` argument
10+
Like django ``transaction.smart_atomic()`` decorator chamber atomic can be used for surrounding method, function or block of code with db atomic block. But because we often uses reversion the atomic is surrounded with ``create_revision`` decorator. Reversion can be turned off with ``reversion`` argument.
1111

1212
.. function:: pre_commit(callable, using=None)
1313

14-
Similar to django ``on_commit`` helper, but callable function is called before the data is saved to the database. Of no atomic bloc is activated callable is called imediatelly
14+
Similar to django ``on_commit`` helper, but callable function is called just before the data is committed to the database. If no atomic block is activated callable is called immediately.
15+
16+
.. function:: in_atomic_block(callable, using=None)
17+
18+
The function checks if your code is in the atomic block.
1519

1620

1721
``chamber.utils.transaction.UniquePreCommitCallable``
1822
-----------------------------------------------------
1923

2024
One time callable is registered and called only once. But all input parameters are stored inside list of kwargs.
2125

22-
.. class:: chamber.utils.transaction.OneTimePreCommitHandler
26+
.. class:: chamber.utils.transaction.UniquePreCommitCallable
2327

2428
.. method:: handle()
2529

26-
There should be implemented code that will be invoked after success pass though the code. Difference from ``PreCommitHandler.handle`` is that kwargs is stored inside list in the order how handlers was created
30+
There should be implemented code that will be invoked after success pass though the code.
2731

2832
.. method:: _get_unique_id()
2933

3034
The uniqueness of the handler must be somehow defined. You must implement this method to define unique identifier of the handler. By default it is identified with has of the class
3135

3236

33-
``chamber.utils.transaction.InstanceOneTimePreCommitHandler``
37+
``chamber.models.handlers.InstanceOneTimePreCommitHandler``
3438
-------------------------------------------------------------
3539

36-
Special type of unique handler that is identified with iteslf and model instance of the input model object.
40+
Special type of unique handler that is identified with itself and model instance of the input model object.
3741

3842
.. class:: chamber.utils.transaction.InstanceOneTimePreCommitHandler
3943

docs/utils.rst

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,71 @@ is equivalent to
184184
def absolute_amount(self):
185185
return abs(self.amount)
186186
absolute_amount.short_description = 'amount'
187+
188+
Tqdm
189+
----
190+
191+
.. class:: chamber.utils.tqdm.tqdm
192+
193+
The class extends ``tqdm`` library (https://tqdm.github.io/). Now the ``tqdm`` context processor can be used with th django commands. Django command stdout writes newline after every write to the stdout which breaks the progress bar::
194+
195+
# a custom command
196+
from django.core.management.base import BaseCommand
197+
from chamber.utils.tqdm import tqdm
198+
199+
class Command(BaseCommand):
200+
201+
def handle(self, *args, **options):
202+
for i in tqdm(range(10), file=self.stdout):
203+
custom_operation(i)
204+
205+
206+
Logging
207+
-------
208+
209+
.. class:: chamber.logging.AppendExtraJSONHandler
210+
211+
Log handler which writes every extra argument in the log to the output message in a json format::
212+
213+
# logged message with handler
214+
logger.log('message', extra={'extra': 'data'})
215+
216+
# logger output
217+
message --- {"extra": "data"}
218+
219+
220+
Storages
221+
--------
222+
223+
.. class:: chamber.storages.BaseS3Storage
224+
225+
Class fixes bugs in the boto3 library storage. For example you can write only bytes with the standard boto3 S3Boto3Storage. Strings will raise exception. The chamber BaseS3Storage adds possibility to saves strings to the storage.
226+
227+
.. class:: chamber.storages.BasePrivateS3Storage
228+
229+
Improves boto3 storage with url method. With this method you can generate temporary URL address to the private s3 storage. The URL will expire after ``CHAMBER_PRIVATE_S3_STORAGE_URL_EXPIRATION`` (default value is one day).
230+
231+
Commands
232+
--------
233+
234+
makemessages
235+
^^^^^^^^^^^^
236+
237+
Django makemessages commands is expanded with another keywords which represents transaction strings. This keyword you can use instead of long django functions:
238+
239+
* ``_l`` - instead of ``gettext_lazy``
240+
* ``_n`` - instead of ``ngettext``
241+
* ``_nl`` - instead of ``ngettext_lazy``
242+
* ``_p`` - instead of ``pgettext``
243+
* ``_np`` - instead of ``npgettext``
244+
* ``_pl`` - instead of ``pgettext_lazy``
245+
* ``_npl`` - instead of ``npgettext_lazy``
246+
247+
Second improvement is parameter ``no-creation-date`` which remove ``POT-Creation-Date`` from the result file.
248+
249+
initdata
250+
^^^^^^^^
251+
252+
Init data is command similar to django ``loaddata``. The command automatically loads the file from the path defined in setting ``CHAMBER_INITAL_DATA_PATH``.
253+
254+

0 commit comments

Comments
 (0)