| Conditions | 5 |
| Total Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 5 |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | 1 | from django.db import models |
|
| 12 | 1 | def __init__(self, *args, **kwargs): |
|
| 13 | """Initializes a new instance of :see:LocalizedModel. |
||
| 14 | |||
| 15 | Here we set all the fields that are of :see:LocalizedField |
||
| 16 | to an instance of :see:LocalizedValue in case they are none |
||
| 17 | so that the user doesn't explicitely have to do so.""" |
||
| 18 | |||
| 19 | 1 | super(LocalizedModel, self).__init__(*args, **kwargs) |
|
| 20 | |||
| 21 | 1 | for field in self._meta.get_fields(): |
|
| 22 | 1 | if not isinstance(field, LocalizedField): |
|
| 23 | 1 | continue |
|
| 24 | |||
| 25 | 1 | value = getattr(self, field.name, None) |
|
| 26 | |||
| 27 | 1 | if not isinstance(value, LocalizedValue): |
|
| 28 | 1 | if isinstance(value, dict): |
|
| 29 | 1 | value = LocalizedValue(value) |
|
| 30 | else: |
||
| 31 | 1 | value = LocalizedValue() |
|
| 32 | |||
| 33 | setattr(self, field.name, value) |
||
| 34 |